01: package jimm.datavision.testdata;
02:
03: import java.util.Random;
04: import java.util.ArrayList;
05: import java.util.Iterator;
06: import java.util.Date;
07: import java.util.Calendar;
08:
09: /**
10: * Generates test data for the jobs table. Used by the <code>CreateData</code>
11: * classes found in the database subdirectories.
12: *
13: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
14: */
15: public class Job {
16:
17: // public static final int NUM_JOBS = 73;
18: public static final int NUM_JOBS = 2000;
19: protected static final long MILLISECS_PER_DAY = 24L * 60L * 60L * 1000L;
20: protected static final String[] CITIES = { "New York", "Chicago",
21: "London", "Tokyo", "Paris" };
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: id = i;
39: title = "This is the short description of job " + i;
40: if (rand.nextInt(20) == 0)
41: 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)
51: * MILLISECS_PER_DAY;
52: Date t = new Date(System.currentTimeMillis()
53: - randomDaysInMillisecs);
54: post_date = Calendar.getInstance();
55: post_date.setTime(t);
56: }
57:
58: public String hourlyRateAsString() {
59: return hourly_rate == null ? "NULL" : hourly_rate.toString();
60: }
61:
62: }
|