Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.22 KB | None | 0 0
  1. import javax.xml.crypto.Data;
  2. import java.io.*;
  3. import java.nio.charset.Charset;
  4. import java.util.ArrayList;
  5. import java.util.GregorianCalendar;
  6. import java.util.Random;
  7.  
  8. /**
  9. * Created by Anna on 09.01.2016.
  10. */
  11. public class Generator {
  12. final static int maxParticipants = 806;
  13. final static int maxIndividual = 200;
  14. final static int maxCompanyParticipants = maxParticipants - maxIndividual;
  15. final static int phoneLength = 9;
  16. final static int maxCity = 70;
  17. final static int maxPostcode = 6;
  18. final static int maxCompany = 500;
  19. final static int datamin=2013;
  20. final static int datamax=2015;
  21. final static int maxPayID=500;
  22. final static int maxReservations=800;
  23.  
  24.  
  25. /* public static String AddReservationPayments (Integer IDPay,String PayDate,Integer IDRes){
  26. return "EXECUTE AddReservationPayments '"+IDPay+"', '"+PayDate+"', '"+IDRes+"'";
  27. }
  28.  
  29. public static String AddAllParticipant(Integer IDParticipant, String Firstname, String Lastname, String StudentID) {
  30. return "EXECUTE AddParticipant '" + IDParticipant + "', '" + Firstname + "', '" + Lastname + "', '" + StudentID + "'";
  31. }
  32.  
  33. public static String AddIndividualParticipant(Integer IDPArticipant, Integer IDCity, String street, String postcode, String phone, String email) {
  34. return "EXECUTE AddIndividualParticipant '" + IDPArticipant + "', '" + IDCity + "', '" + street + "', '" + postcode + "', '" + phone + "', '" + email + "'";
  35. }
  36.  
  37. public static String AddCompanyParticipant(Integer IDPArticipant,Integer IDCompany){
  38. return "EXECUTE AddCompanyParticipant '"+IDPArticipant+"', '"+IDCompany+"'";
  39. }*/
  40.  
  41. public static String AddReservation(Integer IDReservation,Integer IDParticipant){
  42. return "Execute AddReservation '"+IDReservation+"', '"+IDParticipant+"'";
  43. }
  44.  
  45.  
  46. /*
  47. public static String randomdata(){
  48. GregorianCalendar gc = new GregorianCalendar();
  49.  
  50. int year = randBetween(datamin, datamax);
  51.  
  52. gc.set(gc.YEAR, year);
  53.  
  54. int dayOfYear = randBetween(1, gc.getActualMaximum(gc.DAY_OF_YEAR));
  55.  
  56. gc.set(gc.DAY_OF_YEAR, dayOfYear);
  57.  
  58. return gc.get(gc.YEAR) + "-" + (gc.get(gc.MONTH) + 1) + "-" + gc.get(gc.DAY_OF_MONTH);
  59.  
  60. }
  61.  
  62. public static int randBetween(int start, int end) {
  63. return start + (int)Math.round(Math.random() * (end - start));
  64. }
  65.  
  66. public static int countLines(String filename) throws IOException {
  67. InputStream is = new BufferedInputStream(new FileInputStream(filename));
  68. try {
  69. byte[] c = new byte[1024];
  70. int count = 0;
  71. int readChars = 0;
  72. boolean empty = true;
  73. while ((readChars = is.read(c)) != -1) {
  74. empty = false;
  75. for (int i = 0; i < readChars; ++i) {
  76. if (c[i] == '\n') {
  77. ++count;
  78. }
  79. }
  80. }
  81. return (count == 0 && !empty) ? 1 : count + 1;
  82. } finally {
  83. is.close();
  84. }
  85. }
  86.  
  87. public static String randomLine(String filename) {
  88. Random rand = new Random();
  89. int randomNum = 0;
  90. try {
  91. //randomNum = rand.nextInt((countLines(filename)));
  92. randomNum = rand.nextInt((countLines(filename))) + 1;
  93. } catch (IOException e) {
  94. }
  95. FileInputStream fs = null;
  96. try {
  97. fs = new FileInputStream(filename);
  98. } catch (FileNotFoundException e) {
  99. }
  100. BufferedReader br = new BufferedReader(new InputStreamReader(fs));
  101. for (int i = 0; i < randomNum; ++i) {
  102. try {
  103. br.readLine();
  104. } catch (IOException e) {
  105. }
  106. }
  107. String line = null;
  108. try {
  109. line = br.readLine();
  110. } catch (IOException e) {
  111. }
  112. return line;
  113. }
  114.  
  115.  
  116. public static String getRandomString(Random rng, String characters, int length) {
  117. char[] text = new char[length];
  118. for (int i = 0; i < length; i++) {
  119. text[i] = characters.charAt(rng.nextInt(characters.length()));
  120. }
  121. return new String(text);
  122. }
  123.  
  124.  
  125. public static String randomStringDistinct(int length, ArrayList tab, String characters) {
  126. String random = getRandomString(new Random(), characters, length);
  127. long i = 0;
  128. while (tab.contains(random) && i < 947) {
  129. random = getRandomString(new Random(), characters, length);
  130. i++;
  131. }
  132.  
  133. tab.add(random);
  134. return random;
  135. }
  136.  
  137. public static void AddFileToArray(ArrayList ar, String filename) {
  138. String line;
  139. try {
  140. try (
  141. InputStream fis = new FileInputStream(filename);
  142. InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
  143. BufferedReader br = new BufferedReader(isr);
  144. ) {
  145. while ((line = br.readLine()) != null) {
  146. ar.add(line);
  147. }
  148. }
  149. } catch (IOException e) {
  150. e.printStackTrace();
  151. }
  152. }
  153.  
  154.  
  155. public static String randomMail(ArrayList list) {
  156. String all = "1234567890qwertyuiopasdfghjklzxcvbnm.";
  157. String nonum = "qwertyuiopasdfghjklzxcvbnm";
  158. Random random = new Random();
  159. String mail = getRandomString(new Random(), all, random.nextInt(10) + 1) + "@" + getRandomString(new Random(), nonum, random.nextInt(3) + 1) + "." + getRandomString(new Random(), nonum, random.nextInt(3) + 1);
  160. while (list.contains(mail)) {
  161. mail = getRandomString(new Random(), all, random.nextInt(10) + 1) + "@" + getRandomString(new Random(), nonum, random.nextInt(3) + 1) + "." + getRandomString(new Random(), nonum, random.nextInt(3) + 1);
  162. }
  163. list.add(mail);
  164. return mail;
  165. }
  166.  
  167. public static String randomPhone(ArrayList list) {
  168. String numbers = "1234567890";
  169. Random random = new Random();
  170. String phone = getRandomString(new Random(), numbers, phoneLength);
  171. while (list.contains(phone)) {
  172. phone = getRandomString(new Random(), numbers, phoneLength);
  173. }
  174. return phone;
  175. }
  176.  
  177. public static Integer RandomIntDistinct(ArrayList ar, int max, int min) {
  178. Random random = new Random();
  179. int results = 0;
  180. results = random.nextInt(max) + min;
  181. while (ar.contains(results)) {
  182. results = random.nextInt(max) + min;
  183. }
  184. ar.add(results);
  185. return results;
  186. }*/
  187.  
  188. public static void main(String[] args) {
  189. PrintWriter generator = null;
  190. try {
  191. generator = new PrintWriter("generator.sql");
  192. } catch (FileNotFoundException e) {
  193. e.printStackTrace();
  194. }
  195.  
  196. Random random = new Random();
  197. String name = "name.txt";
  198. String surname = "surname.txt";
  199. String mailCompany = "mailCompany.txt";
  200. String phoneFirm = "phoneFirm.txt";
  201. String street = "streets.txt";
  202. ArrayList studentIDlist = new ArrayList();
  203. ArrayList maillist = new ArrayList();
  204. ArrayList phonelist = new ArrayList();
  205. ArrayList indiwidulaID = new ArrayList();
  206. ArrayList companyParticipantID=new ArrayList();
  207. int i=1;
  208. //AddFileToArray(maillist, mailCompany);
  209. //AddFileToArray(phonelist, phoneFirm);
  210.  
  211. /////////////////
  212. ////////////////
  213. /////AllParticipants
  214. /*for(int i=1;i<maxParticipants;i++){
  215. if(i%5!=0) {
  216. generator.println(AddAllParticipant(i, randomLine(name), randomLine(surname), randomStringDistinct(6, studentIDlist, "1234567890")));
  217. }else{
  218. generator.println(AddAllParticipant(i, randomLine(name), randomLine(surname), null));
  219. }
  220. }*/
  221.  
  222. /////////////////
  223. ////////////////
  224. /////Individual
  225.  
  226. /* String rmail=randomMail(maillist);
  227. int i=1;
  228. while(i<=maxIndividual){
  229. generator.println(AddIndividualParticipant(RandomIntDistinct(indiwidulaID,maxParticipants,1), random.nextInt(maxCity) + 1, randomLine(street), getRandomString(new Random(), "1234567890qwertyuiopasdfghjklzxcvbnm", maxPostcode), randomPhone(phonelist), randomMail(maillist)));
  230. i++;
  231. }*/
  232.  
  233. /////////////////
  234. ////////////////
  235. /////CompanyParticipant
  236.  
  237.  
  238. /*while(i<maxCompanyParticipants){
  239. generator.println(AddCompanyParticipant(RandomIntDistinct(companyParticipantID,maxCompanyParticipants,1),random.nextInt(maxCompany)+1));
  240. }
  241.  
  242. /////////////
  243. /////////////
  244. /////////ResPayments
  245. i=1;
  246. while(i<maxPayID){
  247. generator.println(AddReservationPayments(i,randomdata(),random.nextInt(maxReservations)+1));
  248. i++;
  249. }*/
  250. /////////////
  251. /////////////
  252. /////////Reservations
  253. i=448;
  254. while(i<maxReservations){
  255. generator.println(AddReservation(i,random.nextInt(maxParticipants)+1));
  256. i++;
  257. }
  258.  
  259.  
  260. }
  261.  
  262.  
  263.  
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement