1 10 11 package com.triactive.jdo.test; 12 13 import java.util.Arrays ; 14 15 16 public class BinaryWidget extends Widget 17 { 18 private byte[] fixedLengthBinary; 19 private byte[] normalBinary; 20 private byte[] hugeBinary; 21 22 23 public BinaryWidget() 24 { 25 super(); 26 } 27 28 29 public byte[] getFixedLengthBinary() 30 { 31 return fixedLengthBinary; 32 } 33 34 35 public byte[] getNormalBinary() 36 { 37 return normalBinary; 38 } 39 40 41 public byte[] getHugeBinary() 42 { 43 return hugeBinary; 44 } 45 46 47 public void setNormalBinary(byte[] normalBinary) 48 { 49 this.normalBinary = normalBinary; 50 } 51 52 53 58 59 public void fillRandom() 60 { 61 super.fillRandom(); 62 63 fixedLengthBinary = nextNull() ? null : nextBinary(20); 64 normalBinary = nextNull() ? null : nextBinary(r.nextInt(21)); 65 hugeBinary = nextNull() ? null : nextBinary(r.nextInt(101)); 66 } 67 68 69 80 81 public boolean compareTo(Object obj) 82 { 83 if (obj == this) 84 return true; 85 86 if (!(obj instanceof BinaryWidget) || !super.compareTo(obj)) 87 return false; 88 89 BinaryWidget w = (BinaryWidget)obj; 90 91 if (fixedLengthBinary == null) { if (w.fixedLengthBinary != null) return false; } 92 else if (!Arrays.equals(fixedLengthBinary, w.fixedLengthBinary)) return false; 93 94 if (normalBinary == null) { if (w.normalBinary != null) return false; } 95 else if (!Arrays.equals(normalBinary, w.normalBinary)) return false; 96 97 if (hugeBinary == null) { if (w.hugeBinary != null) return false; } 98 else if (!Arrays.equals(hugeBinary, w.hugeBinary)) 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(" fixedLengthBinary = ").append(toHexString(fixedLengthBinary)); 116 s.append('\n'); 117 s.append(" normalBinary = ").append(toHexString(normalBinary)); 118 s.append('\n'); 119 s.append(" hugeBinary = ").append(toHexString(hugeBinary)); 120 s.append('\n'); 121 122 return s.toString(); 123 } 124 125 126 133 134 private static String toHexString(byte[] ba) 135 { 136 if (ba == null) 137 return "null"; 138 139 StringBuffer s = new StringBuffer (); 140 141 for (int i = 0; i < ba.length; ++i) 142 s.append(Integer.toHexString((int)ba[i] & 0xff)); 143 144 return s.toString(); 145 } 146 } 147 | Popular Tags |