1 21 22 package org.apache.derbyTesting.unitTests.services; 23 24 35 public class T_Key { 36 37 private Object value; 38 private long waitms; 39 private boolean canFind; 40 private boolean raiseException; 41 42 public static T_Key simpleInt(int value) { 43 return new T_Key(new Integer (value), 0, true, false); 44 } 45 public static T_Key dontFindInt(int value) { 46 return new T_Key(new Integer (value), 0, false, false); 47 } 48 public static T_Key exceptionInt(int value) { 49 return new T_Key(new Integer (value), 0, true, true); 50 } 51 52 56 public static T_Key randomKey() { 57 58 double rand = Math.random(); 59 T_Key tkey = new T_Key(); 60 61 if (rand < 0.48) 62 tkey.value = new Integer ((int) (100.0 * rand)); 63 else if (rand < 0.96) 64 tkey.value = new Integer ((int) (100.0 * rand)); 65 else 66 tkey.value = Boolean.FALSE; 67 68 rand = Math.random(); 69 70 if (rand < 0.90) 71 tkey.canFind = true; 72 else if (rand < 0.95) 73 tkey.canFind = false; 74 else { 75 tkey.canFind = true; 76 tkey.raiseException = false; 77 } 78 79 rand = Math.random(); 80 81 if (rand < 0.30) { 82 tkey.waitms = (long) (rand * 1000.0); } 84 85 return tkey; 86 } 87 88 private T_Key() { 89 } 90 91 92 private T_Key(Object value, long waitms, boolean canFind, boolean raiseException) { 93 94 this.value = value; 95 this.waitms = waitms; 96 this.canFind = canFind; 97 this.raiseException = raiseException; 98 } 99 100 public Object getValue() { 101 return value; 102 } 103 104 public long getWait() { 105 return waitms; 106 } 107 108 public boolean canFind() { 109 return canFind; 110 } 111 112 public boolean raiseException() { 113 return raiseException; 114 } 115 116 public boolean equals(Object other) { 117 if (other instanceof T_Key) { 118 return value.equals(((T_Key) other).value); 119 } 120 return false; 121 } 122 123 public int hashCode() { 124 return value.hashCode(); 125 } 126 127 public String toString() { 128 return value + " " + waitms + " " + canFind + " " + raiseException; 129 } 130 } 131 132 | Popular Tags |