KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > testdata > Job


1 package jimm.datavision.testdata;
2 import java.util.Random JavaDoc;
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Date JavaDoc;
6 import java.util.Calendar JavaDoc;
7
8 /**
9  * Generates test data for the jobs table. Used by the <code>CreateData</code>
10  * classes found in the database subdirectories.
11  *
12  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
13  */

14 public class Job {
15
16 // public static final int NUM_JOBS = 73;
17
public static final int NUM_JOBS = 2000;
18 protected static final long MILLISECS_PER_DAY = 24L * 60L * 60L * 1000L;
19 protected static final String JavaDoc[] CITIES = {
20     "New York", "Chicago", "London", "Tokyo", "Paris"
21 };
22
23 public int id, fk_office_id;
24 public Integer JavaDoc hourly_rate;
25 public String JavaDoc title, company, location, description;
26 public Calendar JavaDoc post_date;
27 public boolean visible;
28
29 public static Iterator JavaDoc jobs() {
30     Random JavaDoc rand = new Random JavaDoc();
31     ArrayList JavaDoc jobs = new ArrayList JavaDoc();
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 JavaDoc 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 JavaDoc(i * 100);
48     visible = true;
49
50     long randomDaysInMillisecs = rand.nextInt(20) * MILLISECS_PER_DAY;
51     Date JavaDoc t = new Date JavaDoc(System.currentTimeMillis() - randomDaysInMillisecs);
52     post_date = Calendar.getInstance();
53     post_date.setTime(t);
54 }
55
56 public String JavaDoc hourlyRateAsString() {
57     return hourly_rate == null ? "NULL" : hourly_rate.toString();
58 }
59
60 }
61
Popular Tags