1 package jimm.datavision.testdata; 2 import java.util.Random ; 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.Date ; 6 import java.util.Calendar ; 7 8 14 public class Job { 15 16 public static final int NUM_JOBS = 2000; 18 protected static final long MILLISECS_PER_DAY = 24L * 60L * 60L * 1000L; 19 protected static final String [] CITIES = { 20 "New York", "Chicago", "London", "Tokyo", "Paris" 21 }; 22 23 public int id, fk_office_id; 24 public Integer hourly_rate; 25 public String title, company, location, description; 26 public Calendar post_date; 27 public boolean visible; 28 29 public static Iterator jobs() { 30 Random rand = new Random (); 31 ArrayList jobs = new ArrayList (); 32 for (int i = 0; i < NUM_JOBS; ++i) 33 jobs.add(new Job(rand, i)); 34 return jobs.iterator(); 35 } 36 37 public Job(Random rand, int i) 38 { 39 id = i; 40 title = "This is the short description of job " + i; 41 if (rand.nextInt(20) == 0) title += " " + title; 42 fk_office_id = rand.nextInt(3) + 1; 43 company = "Company " + i; 44 location = CITIES[rand.nextInt(CITIES.length)]; 45 description = "This is the description of job " + i 46 + ". It could be much longer."; 47 hourly_rate = i == 0 ? null : new Integer (i * 100); 48 visible = true; 49 50 long randomDaysInMillisecs = rand.nextInt(20) * MILLISECS_PER_DAY; 51 Date t = new Date (System.currentTimeMillis() - randomDaysInMillisecs); 52 post_date = Calendar.getInstance(); 53 post_date.setTime(t); 54 } 55 56 public String hourlyRateAsString() { 57 return hourly_rate == null ? "NULL" : hourly_rate.toString(); 58 } 59 60 } 61 | Popular Tags |