Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.xml.crypto.Data;
- import java.io.*;
- import java.nio.charset.Charset;
- import java.util.ArrayList;
- import java.util.GregorianCalendar;
- import java.util.Random;
- /**
- * Created by Anna on 09.01.2016.
- */
- public class Generator {
- final static int maxParticipants = 806;
- final static int maxIndividual = 200;
- final static int maxCompanyParticipants = maxParticipants - maxIndividual;
- final static int phoneLength = 9;
- final static int maxCity = 70;
- final static int maxPostcode = 6;
- final static int maxCompany = 500;
- final static int datamin=2013;
- final static int datamax=2015;
- final static int maxPayID=500;
- final static int maxReservations=800;
- /* public static String AddReservationPayments (Integer IDPay,String PayDate,Integer IDRes){
- return "EXECUTE AddReservationPayments '"+IDPay+"', '"+PayDate+"', '"+IDRes+"'";
- }
- public static String AddAllParticipant(Integer IDParticipant, String Firstname, String Lastname, String StudentID) {
- return "EXECUTE AddParticipant '" + IDParticipant + "', '" + Firstname + "', '" + Lastname + "', '" + StudentID + "'";
- }
- public static String AddIndividualParticipant(Integer IDPArticipant, Integer IDCity, String street, String postcode, String phone, String email) {
- return "EXECUTE AddIndividualParticipant '" + IDPArticipant + "', '" + IDCity + "', '" + street + "', '" + postcode + "', '" + phone + "', '" + email + "'";
- }
- public static String AddCompanyParticipant(Integer IDPArticipant,Integer IDCompany){
- return "EXECUTE AddCompanyParticipant '"+IDPArticipant+"', '"+IDCompany+"'";
- }*/
- public static String AddReservation(Integer IDReservation,Integer IDParticipant){
- return "Execute AddReservation '"+IDReservation+"', '"+IDParticipant+"'";
- }
- /*
- public static String randomdata(){
- GregorianCalendar gc = new GregorianCalendar();
- int year = randBetween(datamin, datamax);
- gc.set(gc.YEAR, year);
- int dayOfYear = randBetween(1, gc.getActualMaximum(gc.DAY_OF_YEAR));
- gc.set(gc.DAY_OF_YEAR, dayOfYear);
- return gc.get(gc.YEAR) + "-" + (gc.get(gc.MONTH) + 1) + "-" + gc.get(gc.DAY_OF_MONTH);
- }
- public static int randBetween(int start, int end) {
- return start + (int)Math.round(Math.random() * (end - start));
- }
- public static int countLines(String filename) throws IOException {
- InputStream is = new BufferedInputStream(new FileInputStream(filename));
- try {
- byte[] c = new byte[1024];
- int count = 0;
- int readChars = 0;
- boolean empty = true;
- while ((readChars = is.read(c)) != -1) {
- empty = false;
- for (int i = 0; i < readChars; ++i) {
- if (c[i] == '\n') {
- ++count;
- }
- }
- }
- return (count == 0 && !empty) ? 1 : count + 1;
- } finally {
- is.close();
- }
- }
- public static String randomLine(String filename) {
- Random rand = new Random();
- int randomNum = 0;
- try {
- //randomNum = rand.nextInt((countLines(filename)));
- randomNum = rand.nextInt((countLines(filename))) + 1;
- } catch (IOException e) {
- }
- FileInputStream fs = null;
- try {
- fs = new FileInputStream(filename);
- } catch (FileNotFoundException e) {
- }
- BufferedReader br = new BufferedReader(new InputStreamReader(fs));
- for (int i = 0; i < randomNum; ++i) {
- try {
- br.readLine();
- } catch (IOException e) {
- }
- }
- String line = null;
- try {
- line = br.readLine();
- } catch (IOException e) {
- }
- return line;
- }
- public static String getRandomString(Random rng, String characters, int length) {
- char[] text = new char[length];
- for (int i = 0; i < length; i++) {
- text[i] = characters.charAt(rng.nextInt(characters.length()));
- }
- return new String(text);
- }
- public static String randomStringDistinct(int length, ArrayList tab, String characters) {
- String random = getRandomString(new Random(), characters, length);
- long i = 0;
- while (tab.contains(random) && i < 947) {
- random = getRandomString(new Random(), characters, length);
- i++;
- }
- tab.add(random);
- return random;
- }
- public static void AddFileToArray(ArrayList ar, String filename) {
- String line;
- try {
- try (
- InputStream fis = new FileInputStream(filename);
- InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
- BufferedReader br = new BufferedReader(isr);
- ) {
- while ((line = br.readLine()) != null) {
- ar.add(line);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static String randomMail(ArrayList list) {
- String all = "1234567890qwertyuiopasdfghjklzxcvbnm.";
- String nonum = "qwertyuiopasdfghjklzxcvbnm";
- Random random = new Random();
- 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);
- while (list.contains(mail)) {
- 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);
- }
- list.add(mail);
- return mail;
- }
- public static String randomPhone(ArrayList list) {
- String numbers = "1234567890";
- Random random = new Random();
- String phone = getRandomString(new Random(), numbers, phoneLength);
- while (list.contains(phone)) {
- phone = getRandomString(new Random(), numbers, phoneLength);
- }
- return phone;
- }
- public static Integer RandomIntDistinct(ArrayList ar, int max, int min) {
- Random random = new Random();
- int results = 0;
- results = random.nextInt(max) + min;
- while (ar.contains(results)) {
- results = random.nextInt(max) + min;
- }
- ar.add(results);
- return results;
- }*/
- public static void main(String[] args) {
- PrintWriter generator = null;
- try {
- generator = new PrintWriter("generator.sql");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- Random random = new Random();
- String name = "name.txt";
- String surname = "surname.txt";
- String mailCompany = "mailCompany.txt";
- String phoneFirm = "phoneFirm.txt";
- String street = "streets.txt";
- ArrayList studentIDlist = new ArrayList();
- ArrayList maillist = new ArrayList();
- ArrayList phonelist = new ArrayList();
- ArrayList indiwidulaID = new ArrayList();
- ArrayList companyParticipantID=new ArrayList();
- int i=1;
- //AddFileToArray(maillist, mailCompany);
- //AddFileToArray(phonelist, phoneFirm);
- /////////////////
- ////////////////
- /////AllParticipants
- /*for(int i=1;i<maxParticipants;i++){
- if(i%5!=0) {
- generator.println(AddAllParticipant(i, randomLine(name), randomLine(surname), randomStringDistinct(6, studentIDlist, "1234567890")));
- }else{
- generator.println(AddAllParticipant(i, randomLine(name), randomLine(surname), null));
- }
- }*/
- /////////////////
- ////////////////
- /////Individual
- /* String rmail=randomMail(maillist);
- int i=1;
- while(i<=maxIndividual){
- generator.println(AddIndividualParticipant(RandomIntDistinct(indiwidulaID,maxParticipants,1), random.nextInt(maxCity) + 1, randomLine(street), getRandomString(new Random(), "1234567890qwertyuiopasdfghjklzxcvbnm", maxPostcode), randomPhone(phonelist), randomMail(maillist)));
- i++;
- }*/
- /////////////////
- ////////////////
- /////CompanyParticipant
- /*while(i<maxCompanyParticipants){
- generator.println(AddCompanyParticipant(RandomIntDistinct(companyParticipantID,maxCompanyParticipants,1),random.nextInt(maxCompany)+1));
- }
- /////////////
- /////////////
- /////////ResPayments
- i=1;
- while(i<maxPayID){
- generator.println(AddReservationPayments(i,randomdata(),random.nextInt(maxReservations)+1));
- i++;
- }*/
- /////////////
- /////////////
- /////////Reservations
- i=448;
- while(i<maxReservations){
- generator.println(AddReservation(i,random.nextInt(maxParticipants)+1));
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement