1 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 34 public final class UnsupportedDateTimeField extends DateTimeField implements Serializable { 35 36 37 private static final long serialVersionUID = -1934618396111902255L; 38 39 40 private static HashMap cCache; 41 42 51 public static synchronized UnsupportedDateTimeField getInstance( 52 DateTimeFieldType type, DurationField durationField) { 53 54 UnsupportedDateTimeField field; 55 if (cCache == null) { 56 cCache = new HashMap (7); 57 field = null; 58 } else { 59 field = (UnsupportedDateTimeField)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 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 94 public DateTimeFieldType getType() { 95 return iType; 96 } 97 98 public String getName() { 99 return iType.getName(); 100 } 101 102 107 public boolean isSupported() { 108 return false; 109 } 110 111 116 public boolean isLenient() { 117 return false; 118 } 119 120 125 public int get(long instant) { 126 throw unsupported(); 127 } 128 129 134 public String getAsText(long instant, Locale locale) { 135 throw unsupported(); 136 } 137 138 143 public String getAsText(long instant) { 144 throw unsupported(); 145 } 146 147 152 public String getAsText(ReadablePartial partial, int fieldValue, Locale locale) { 153 throw unsupported(); 154 } 155 156 161 public String getAsText(ReadablePartial partial, Locale locale) { 162 throw unsupported(); 163 } 164 165 170 public String getAsText(int fieldValue, Locale locale) { 171 throw unsupported(); 172 } 173 174 179 public String getAsShortText(long instant, Locale locale) { 180 throw unsupported(); 181 } 182 183 188 public String getAsShortText(long instant) { 189 throw unsupported(); 190 } 191 192 197 public String getAsShortText(ReadablePartial partial, int fieldValue, Locale locale) { 198 throw unsupported(); 199 } 200 201 206 public String getAsShortText(ReadablePartial partial, Locale locale) { 207 throw unsupported(); 208 } 209 210 215 public String getAsShortText(int fieldValue, Locale locale) { 216 throw unsupported(); 217 } 218 219 224 public long add(long instant, int value) { 225 return getDurationField().add(instant, value); 226 } 227 228 233 public long add(long instant, long value) { 234 return getDurationField().add(instant, value); 235 } 236 237 242 public int[] add(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { 243 throw unsupported(); 244 } 245 246 251 public int[] addWrapPartial(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { 252 throw unsupported(); 253 } 254 255 260 public long addWrapField(long instant, int value) { 261 throw unsupported(); 262 } 263 264 269 public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) { 270 throw unsupported(); 271 } 272 273 278 public int getDifference(long minuendInstant, long subtrahendInstant) { 279 return getDurationField().getDifference(minuendInstant, subtrahendInstant); 280 } 281 282 287 public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { 288 return getDurationField().getDifferenceAsLong(minuendInstant, subtrahendInstant); 289 } 290 291 296 public long set(long instant, int value) { 297 throw unsupported(); 298 } 299 300 305 public int[] set(ReadablePartial instant, int fieldIndex, int[] values, int newValue) { 306 throw unsupported(); 307 } 308 309 314 public long set(long instant, String text, Locale locale) { 315 throw unsupported(); 316 } 317 318 323 public long set(long instant, String text) { 324 throw unsupported(); 325 } 326 327 332 public int[] set(ReadablePartial instant, int fieldIndex, int[] values, String text, Locale locale) { 333 throw unsupported(); 334 } 335 336 342 public DurationField getDurationField() { 343 return iDurationField; 344 } 345 346 351 public DurationField getRangeDurationField() { 352 return null; 353 } 354 355 360 public boolean isLeap(long instant) { 361 throw unsupported(); 362 } 363 364 369 public int getLeapAmount(long instant) { 370 throw unsupported(); 371 } 372 373 378 public DurationField getLeapDurationField() { 379 return null; 380 } 381 382 387 public int getMinimumValue() { 388 throw unsupported(); 389 } 390 391 396 public int getMinimumValue(long instant) { 397 throw unsupported(); 398 } 399 400 405 public int getMinimumValue(ReadablePartial instant) { 406 throw unsupported(); 407 } 408 409 414 public int getMinimumValue(ReadablePartial instant, int[] values) { 415 throw unsupported(); 416 } 417 418 423 public int getMaximumValue() { 424 throw unsupported(); 425 } 426 427 432 public int getMaximumValue(long instant) { 433 throw unsupported(); 434 } 435 436 441 public int getMaximumValue(ReadablePartial instant) { 442 throw unsupported(); 443 } 444 445 450 public int getMaximumValue(ReadablePartial instant, int[] values) { 451 throw unsupported(); 452 } 453 454 459 public int getMaximumTextLength(Locale locale) { 460 throw unsupported(); 461 } 462 463 468 public int getMaximumShortTextLength(Locale locale) { 469 throw unsupported(); 470 } 471 472 477 public long roundFloor(long instant) { 478 throw unsupported(); 479 } 480 481 486 public long roundCeiling(long instant) { 487 throw unsupported(); 488 } 489 490 495 public long roundHalfFloor(long instant) { 496 throw unsupported(); 497 } 498 499 504 public long roundHalfCeiling(long instant) { 505 throw unsupported(); 506 } 507 508 513 public long roundHalfEven(long instant) { 514 throw unsupported(); 515 } 516 517 522 public long remainder(long instant) { 523 throw unsupported(); 524 } 525 526 532 public String toString() { 533 return "UnsupportedDateTimeField"; 534 } 535 536 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 } 548 | Popular Tags |