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 import java.util.Locale;
21 import org.joda.time.DateTimeField;
22 import org.joda.time.DateTimeFieldType;
23 import org.joda.time.DurationField;
24 import org.joda.time.ReadablePartial;
25
26
27
28
29
30
31
32
33
34 public final class UnsupportedDateTimeField extends DateTimeField implements Serializable {
35
36
37 private static final long serialVersionUID = -1934618396111902255L;
38
39
40 private static HashMap<DateTimeFieldType, UnsupportedDateTimeField> cCache;
41
42
43
44
45
46
47
48
49
50
51 public static synchronized UnsupportedDateTimeField getInstance(
52 DateTimeFieldType type, DurationField durationField) {
53
54 UnsupportedDateTimeField field;
55 if (cCache == null) {
56 cCache = new HashMap<DateTimeFieldType, UnsupportedDateTimeField>(7);
57 field = null;
58 } else {
59 field = cCache.get(type);
60 if (field != null && field.getDurationField() != durationField) {
61 field = null;
62 }
63 }
64 if (field == null) {
65 field = new UnsupportedDateTimeField(type, durationField);
66 cCache.put(type, field);
67 }
68 return field;
69 }
70
71
72 private final DateTimeFieldType iType;
73
74 private final DurationField iDurationField;
75
76
77
78
79
80
81
82 private UnsupportedDateTimeField(DateTimeFieldType type, DurationField durationField) {
83 if (type == null || durationField == null) {
84 throw new IllegalArgumentException();
85 }
86 iType = type;
87 iDurationField = durationField;
88 }
89
90
91
92
93
94 public DateTimeFieldType getType() {
95 return iType;
96 }
97
98 public String getName() {
99 return iType.getName();
100 }
101
102
103
104
105
106
107 public boolean isSupported() {
108 return false;
109 }
110
111
112
113
114
115
116 public boolean isLenient() {
117 return false;
118 }
119
120
121
122
123
124
125 public int get(long instant) {
126 throw unsupported();
127 }
128
129
130
131
132
133
134 public String getAsText(long instant, Locale locale) {
135 throw unsupported();
136 }
137
138
139
140
141
142
143 public String getAsText(long instant) {
144 throw unsupported();
145 }
146
147
148
149
150
151
152 public String getAsText(ReadablePartial partial, int fieldValue, Locale locale) {
153 throw unsupported();
154 }
155
156
157
158
159
160
161 public String getAsText(ReadablePartial partial, Locale locale) {
162 throw unsupported();
163 }
164
165
166
167
168
169
170 public String getAsText(int fieldValue, Locale locale) {
171 throw unsupported();
172 }
173
174
175
176
177
178
179 public String getAsShortText(long instant, Locale locale) {
180 throw unsupported();
181 }
182
183
184
185
186
187
188 public String getAsShortText(long instant) {
189 throw unsupported();
190 }
191
192
193
194
195
196
197 public String getAsShortText(ReadablePartial partial, int fieldValue, Locale locale) {
198 throw unsupported();
199 }
200
201
202
203
204
205
206 public String getAsShortText(ReadablePartial partial, Locale locale) {
207 throw unsupported();
208 }
209
210
211
212
213
214
215 public String getAsShortText(int fieldValue, Locale locale) {
216 throw unsupported();
217 }
218
219
220
221
222
223
224 public long add(long instant, int value) {
225 return getDurationField().add(instant, value);
226 }
227
228
229
230
231
232
233 public long add(long instant, long value) {
234 return getDurationField().add(instant, value);
235 }
236
237
238
239
240
241
242 public int[] add(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
243 throw unsupported();
244 }
245
246
247
248
249
250
251 public int[] addWrapPartial(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
252 throw unsupported();
253 }
254
255
256
257
258
259
260 public long addWrapField(long instant, int value) {
261 throw unsupported();
262 }
263
264
265
266
267
268
269 public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
270 throw unsupported();
271 }
272
273
274
275
276
277
278 public int getDifference(long minuendInstant, long subtrahendInstant) {
279 return getDurationField().getDifference(minuendInstant, subtrahendInstant);
280 }
281
282
283
284
285
286
287 public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
288 return getDurationField().getDifferenceAsLong(minuendInstant, subtrahendInstant);
289 }
290
291
292
293
294
295
296 public long set(long instant, int value) {
297 throw unsupported();
298 }
299
300
301
302
303
304
305 public int[] set(ReadablePartial instant, int fieldIndex, int[] values, int newValue) {
306 throw unsupported();
307 }
308
309
310
311
312
313
314 public long set(long instant, String text, Locale locale) {
315 throw unsupported();
316 }
317
318
319
320
321
322
323 public long set(long instant, String text) {
324 throw unsupported();
325 }
326
327
328
329
330
331
332 public int[] set(ReadablePartial instant, int fieldIndex, int[] values, String text, Locale locale) {
333 throw unsupported();
334 }
335
336
337
338
339
340
341
342 public DurationField getDurationField() {
343 return iDurationField;
344 }
345
346
347
348
349
350
351 public DurationField getRangeDurationField() {
352 return null;
353 }
354
355
356
357
358
359
360 public boolean isLeap(long instant) {
361 throw unsupported();
362 }
363
364
365
366
367
368
369 public int getLeapAmount(long instant) {
370 throw unsupported();
371 }
372
373
374
375
376
377
378 public DurationField getLeapDurationField() {
379 return null;
380 }
381
382
383
384
385
386
387 public int getMinimumValue() {
388 throw unsupported();
389 }
390
391
392
393
394
395
396 public int getMinimumValue(long instant) {
397 throw unsupported();
398 }
399
400
401
402
403
404
405 public int getMinimumValue(ReadablePartial instant) {
406 throw unsupported();
407 }
408
409
410
411
412
413
414 public int getMinimumValue(ReadablePartial instant, int[] values) {
415 throw unsupported();
416 }
417
418
419
420
421
422
423 public int getMaximumValue() {
424 throw unsupported();
425 }
426
427
428
429
430
431
432 public int getMaximumValue(long instant) {
433 throw unsupported();
434 }
435
436
437
438
439
440
441 public int getMaximumValue(ReadablePartial instant) {
442 throw unsupported();
443 }
444
445
446
447
448
449
450 public int getMaximumValue(ReadablePartial instant, int[] values) {
451 throw unsupported();
452 }
453
454
455
456
457
458
459 public int getMaximumTextLength(Locale locale) {
460 throw unsupported();
461 }
462
463
464
465
466
467
468 public int getMaximumShortTextLength(Locale locale) {
469 throw unsupported();
470 }
471
472
473
474
475
476
477 public long roundFloor(long instant) {
478 throw unsupported();
479 }
480
481
482
483
484
485
486 public long roundCeiling(long instant) {
487 throw unsupported();
488 }
489
490
491
492
493
494
495 public long roundHalfFloor(long instant) {
496 throw unsupported();
497 }
498
499
500
501
502
503
504 public long roundHalfCeiling(long instant) {
505 throw unsupported();
506 }
507
508
509
510
511
512
513 public long roundHalfEven(long instant) {
514 throw unsupported();
515 }
516
517
518
519
520
521
522 public long remainder(long instant) {
523 throw unsupported();
524 }
525
526
527
528
529
530
531
532 public String toString() {
533 return "UnsupportedDateTimeField";
534 }
535
536
537
538
539 private Object readResolve() {
540 return getInstance(iType, iDurationField);
541 }
542
543 private UnsupportedOperationException unsupported() {
544 return new UnsupportedOperationException(iType + " field is unsupported");
545 }
546
547 }