1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package junitx.ddtunit.data;
39
40
41
42
43
44
45
46 public class TypedObject implements Cloneable {
47 public final static String UNKNOWN_TYPE = "UnknownType";
48
49 private String id;
50
51 private String type;
52
53 private Object value;
54
55 public TypedObject(String id) {
56 this(id, UNKNOWN_TYPE);
57 }
58
59 public TypedObject(String id, String type) {
60 if (id == null || "".equals(id)) {
61
62
63 throw new IllegalArgumentException(
64 "id and type must be specified on TypedObject");
65 }
66 this.id = id;
67 if (type == null || "".equals(type)) {
68 this.type = UNKNOWN_TYPE;
69 } else {
70 this.type = type;
71 }
72 }
73
74 public Object getValue() {
75 return value;
76 }
77
78 public void setValue(Object value) {
79 this.value = value;
80 }
81
82 public String getType() {
83 return type;
84 }
85
86 public String getId() {
87 return id;
88 }
89
90
91
92
93
94
95 public int hashCode() {
96 int hashCode = 1;
97 hashCode = 31 * hashCode + (id == null ? 0 : id.hashCode());
98 hashCode = 31 * hashCode + (type == null ? 0 : type.hashCode());
99 hashCode = 31 * hashCode + (value == null ? 0 : value.hashCode());
100 return hashCode;
101 }
102
103
104
105
106
107
108
109
110 public boolean equals(Object obj) {
111 if (this == obj) {
112 return true;
113 }
114 if (obj == null) {
115 return false;
116 }
117 if (obj.getClass() != getClass()) {
118 return false;
119 }
120 TypedObject castedObj = (TypedObject) obj;
121 return ((this.id == null ? castedObj.id == null : this.id
122 .equals(castedObj.id))
123 && (this.type == null ? castedObj.type == null : this.type
124 .equals(castedObj.type)) && (this.value == null ? castedObj.value == null
125 : this.value.equals(castedObj.value)));
126 }
127
128 public void setId(String id) {
129 this.id = id;
130 }
131
132 public void setType(String type) {
133 if (type == null) {
134 throw new NullPointerException(
135 "TypedObject.type is not allowed to be null!");
136 }
137 this.type = type;
138 }
139
140 public String toString() {
141 StringBuffer buffer = new StringBuffer();
142 buffer.append("[TypedObject:");
143 buffer.append(" id: ");
144 buffer.append(id);
145 buffer.append(" type: ");
146 buffer.append(type);
147 buffer.append("]");
148 return buffer.toString();
149 }
150
151 public Object clone() {
152 TypedObject newObj = new TypedObject(this.id, this.type);
153 newObj.setValue(this.value);
154 return newObj;
155 }
156 }