1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.joda.time.field;
17
18 import java.io.Serializable;
19 import java.util.HashMap;
20
21 import org.joda.time.DurationField;
22 import org.joda.time.DurationFieldType;
23
24
25
26
27
28
29
30
31
32 public final class UnsupportedDurationField extends DurationField implements Serializable {
33
34
35 private static final long serialVersionUID = -6390301302770925357L;
36
37
38 private static HashMap<DurationFieldType, UnsupportedDurationField> cCache;
39
40
41
42
43
44
45
46
47 public static synchronized UnsupportedDurationField getInstance(DurationFieldType type) {
48 UnsupportedDurationField field;
49 if (cCache == null) {
50 cCache = new HashMap<DurationFieldType, UnsupportedDurationField>(7);
51 field = null;
52 } else {
53 field = cCache.get(type);
54 }
55 if (field == null) {
56 field = new UnsupportedDurationField(type);
57 cCache.put(type, field);
58 }
59 return field;
60 }
61
62
63 private final DurationFieldType iType;
64
65
66
67
68
69
70 private UnsupportedDurationField(DurationFieldType type) {
71 iType = type;
72 }
73
74
75
76
77
78 public final DurationFieldType getType() {
79 return iType;
80 }
81
82 public String getName() {
83 return iType.getName();
84 }
85
86
87
88
89
90
91 public boolean isSupported() {
92 return false;
93 }
94
95
96
97
98
99
100 public boolean isPrecise() {
101 return true;
102 }
103
104
105
106
107
108
109 public int getValue(long duration) {
110 throw unsupported();
111 }
112
113
114
115
116
117
118 public long getValueAsLong(long duration) {
119 throw unsupported();
120 }
121
122
123
124
125
126
127 public int getValue(long duration, long instant) {
128 throw unsupported();
129 }
130
131
132
133
134
135
136 public long getValueAsLong(long duration, long instant) {
137 throw unsupported();
138 }
139
140
141
142
143
144
145 public long getMillis(int value) {
146 throw unsupported();
147 }
148
149
150
151
152
153
154 public long getMillis(long value) {
155 throw unsupported();
156 }
157
158
159
160
161
162
163 public long getMillis(int value, long instant) {
164 throw unsupported();
165 }
166
167
168
169
170
171
172 public long getMillis(long value, long instant) {
173 throw unsupported();
174 }
175
176
177
178
179
180
181 public long add(long instant, int value) {
182 throw unsupported();
183 }
184
185
186
187
188
189
190 public long add(long instant, long value) {
191 throw unsupported();
192 }
193
194
195
196
197
198
199 public int getDifference(long minuendInstant, long subtrahendInstant) {
200 throw unsupported();
201 }
202
203
204
205
206
207
208 public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
209 throw unsupported();
210 }
211
212
213
214
215
216
217 public long getUnitMillis() {
218 return 0;
219 }
220
221
222
223
224
225
226 public int compareTo(DurationField durationField) {
227 return 0;
228 }
229
230
231
232
233
234
235
236
237 public boolean equals(Object obj) {
238 if (this == obj) {
239 return true;
240 } else if (obj instanceof UnsupportedDurationField) {
241 UnsupportedDurationField other = (UnsupportedDurationField) obj;
242 if (other.getName() == null) {
243 return (getName() == null);
244 }
245 return (other.getName().equals(getName()));
246 }
247 return false;
248 }
249
250
251
252
253
254
255 public int hashCode() {
256 return getName().hashCode();
257 }
258
259
260
261
262
263
264 public String toString() {
265 return "UnsupportedDurationField[" + getName() + ']';
266 }
267
268
269
270
271 private Object readResolve() {
272 return getInstance(iType);
273 }
274
275 private UnsupportedOperationException unsupported() {
276 return new UnsupportedOperationException(iType + " field is unsupported");
277 }
278
279 }