1 10 11 package com.triactive.jdo.test; 12 13 import com.triactive.jdo.DatabaseProperties; 14 import java.math.BigDecimal ; 15 import java.math.BigInteger ; 16 17 18 public class DecimalWidget extends Widget 19 { 20 private BigInteger bigIntegerField; 21 private BigDecimal bigDecimalField; 22 23 24 public DecimalWidget() 25 { 26 super(); 27 } 28 29 30 public BigInteger getBigIntegerField() 31 { 32 return bigIntegerField; 33 } 34 35 36 public BigDecimal getBigDecimalField() 37 { 38 return bigDecimalField; 39 } 40 41 42 47 48 public void fillRandom() 49 { 50 super.fillRandom(); 51 52 58 int numRandBits = 59; 59 60 64 if (DatabaseProperties.dbURL.startsWith("jdbc:mysql")) 65 numRandBits = 52; 66 67 bigIntegerField = nextNull() ? null : new BigInteger (numRandBits, r); 68 bigDecimalField = nextNull() ? null : new BigDecimal (new BigInteger (numRandBits, r), 2); 69 } 70 71 72 83 84 public boolean compareTo(Object obj) 85 { 86 if (obj == this) 87 return true; 88 89 if (!(obj instanceof DecimalWidget) || !super.compareTo(obj)) 90 return false; 91 92 DecimalWidget w = (DecimalWidget)obj; 93 94 if (bigIntegerField == null) { if (w.bigIntegerField != null) return false; } 95 else if (!bigIntegerField.equals(w.bigIntegerField)) return false; 96 97 if (bigDecimalField == null) { if (w.bigDecimalField != null) return false; } 98 else if (bigDecimalField.compareTo(w.bigDecimalField) != 0) return false; 99 100 return true; 101 } 102 103 104 110 111 public String toString() 112 { 113 StringBuffer s = new StringBuffer (super.toString()); 114 115 s.append(" bigIntegerField = ").append(bigIntegerField); 116 s.append('\n'); 117 s.append(" bigDecimalField = ").append(bigDecimalField); 118 s.append('\n'); 119 120 return s.toString(); 121 } 122 } 123 | Popular Tags |