KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > demos > scalability > Record


1 package org.prevayler.demos.scalability;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.*;
5 import java.math.BigDecimal JavaDoc;
6
7 public class Record implements Serializable JavaDoc {
8
9     private static final String JavaDoc largeString = generateLargeString();
10
11     private final long id;
12     private final String JavaDoc name;
13     private final String JavaDoc string1;
14     private final BigDecimal JavaDoc bigDecimal1;
15     private final BigDecimal JavaDoc bigDecimal2;
16     private final long date1;
17     private final long date2;
18
19     private static final Random RANDOM = new Random();
20
21
22     public Record(long id) {
23         this(id, RANDOM);
24     }
25
26     
27     public Record(long id, Random random) {
28         this(
29                 id,
30                 "NAME" + (id % 10000),
31                 (id % 10000) == 0 ? largeString + id : null,
32                 new BigDecimal JavaDoc(random.nextInt()),
33                 new BigDecimal JavaDoc(random.nextInt()),
34                 new Date(random.nextInt(10000000)),
35                 new Date(random.nextInt(10000000))
36             );
37     }
38
39     public Record(long id, String JavaDoc name, String JavaDoc string1, BigDecimal JavaDoc bigDecimal1, BigDecimal JavaDoc bigDecimal2, Date date1, Date date2) {
40         this.id = id;
41         this.name = name;
42         this.string1 = string1;
43         this.bigDecimal1 = bigDecimal1;
44         this.bigDecimal2 = bigDecimal2;
45         this.date1 = date1.getTime();
46         this.date2 = date2.getTime();
47     }
48
49     public long getId() {
50         return id;
51     }
52
53     public String JavaDoc getName() {
54         return name;
55     }
56
57     public String JavaDoc getString1() {
58         return string1;
59     }
60
61     public BigDecimal JavaDoc getBigDecimal1() {
62         return bigDecimal1;
63     }
64
65     public BigDecimal JavaDoc getBigDecimal2() {
66         return bigDecimal2;
67     }
68
69     public Date getDate1() {
70         return new Date(date1);
71     }
72
73     public Date getDate2() {
74         return new Date(date2);
75     }
76
77     public int hashCode() {
78         return (int)(id
79             + name.hashCode()
80             + ("" + string1).hashCode()
81             + bigDecimal1.hashCode()
82             + bigDecimal2.hashCode()
83             + date1
84             + date2
85         );
86     }
87
88
89     static private String JavaDoc generateLargeString() {
90         char[] chars = new char[980];
91         Arrays.fill(chars, 'A');
92         return new String JavaDoc(chars);
93     }
94
95 }
96
Popular Tags