1 16 package org.joda.time.field; 17 18 import org.joda.time.Chronology; 19 import org.joda.time.DateTimeField; 20 import org.joda.time.DateTimeFieldType; 21 import org.joda.time.IllegalFieldValueException; 22 23 35 public final class SkipDateTimeField extends DelegatedDateTimeField { 36 37 38 private static final long serialVersionUID = -8869148464118507846L; 39 40 41 private final Chronology iChronology; 42 43 private final int iSkip; 44 45 private transient int iMinValue; 46 47 53 public SkipDateTimeField(Chronology chronology, DateTimeField field) { 54 this(chronology, field, 0); 55 } 56 57 64 public SkipDateTimeField(Chronology chronology, DateTimeField field, int skip) { 65 super(field); 66 iChronology = chronology; 67 int min = super.getMinimumValue(); 68 if (min < skip) { 69 iMinValue = min - 1; 70 } else if (min == skip) { 71 iMinValue = skip + 1; 72 } else { 73 iMinValue = min; 74 } 75 iSkip = skip; 76 } 77 78 public int get(long millis) { 80 int value = super.get(millis); 81 if (value <= iSkip) { 82 value--; 83 } 84 return value; 85 } 86 87 public long set(long millis, int value) { 88 FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue()); 89 if (value <= iSkip) { 90 if (value == iSkip) { 91 throw new IllegalFieldValueException 92 (DateTimeFieldType.year(), new Integer (value), null, null); 93 } 94 value++; 95 } 96 return super.set(millis, value); 97 } 98 99 public int getMinimumValue() { 100 return iMinValue; 101 } 102 103 private Object readResolve() { 104 return getType().getField(iChronology); 105 } 106 107 } 108 | Popular Tags |