1 package org.prevayler.demos.scalability; 2 3 import java.io.Serializable ; 4 import java.util.*; 5 import java.math.BigDecimal ; 6 7 public class Record implements Serializable { 8 9 private static final String largeString = generateLargeString(); 10 11 private final long id; 12 private final String name; 13 private final String string1; 14 private final BigDecimal bigDecimal1; 15 private final BigDecimal 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 (random.nextInt()), 33 new BigDecimal (random.nextInt()), 34 new Date(random.nextInt(10000000)), 35 new Date(random.nextInt(10000000)) 36 ); 37 } 38 39 public Record(long id, String name, String string1, BigDecimal bigDecimal1, BigDecimal 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 getName() { 54 return name; 55 } 56 57 public String getString1() { 58 return string1; 59 } 60 61 public BigDecimal getBigDecimal1() { 62 return bigDecimal1; 63 } 64 65 public BigDecimal 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 generateLargeString() { 90 char[] chars = new char[980]; 91 Arrays.fill(chars, 'A'); 92 return new String (chars); 93 } 94 95 } 96 | Popular Tags |