1 16 package org.joda.time.chrono; 17 18 import java.util.Locale ; 19 20 import org.joda.time.DateTimeConstants; 21 import org.joda.time.DateTimeFieldType; 22 import org.joda.time.DurationField; 23 import org.joda.time.DurationFieldType; 24 import org.joda.time.IllegalFieldValueException; 25 import org.joda.time.field.BaseDateTimeField; 26 import org.joda.time.field.FieldUtils; 27 import org.joda.time.field.UnsupportedDurationField; 28 29 36 final class BasicSingleEraDateTimeField extends BaseDateTimeField { 37 38 41 private static final int ERA_VALUE = DateTimeConstants.CE; 42 45 private final String iEraText; 46 47 50 BasicSingleEraDateTimeField(String text) { 51 super(DateTimeFieldType.era()); 52 iEraText = text; 53 } 54 55 56 public boolean isLenient() { 57 return false; 58 } 59 60 61 public int get(long instant) { 62 return ERA_VALUE; 63 } 64 65 66 public long set(long instant, int era) { 67 FieldUtils.verifyValueBounds(this, era, ERA_VALUE, ERA_VALUE); 68 return instant; 69 } 70 71 72 public long set(long instant, String text, Locale locale) { 73 if (iEraText.equals(text) == false && "1".equals(text) == false) { 74 throw new IllegalFieldValueException(DateTimeFieldType.era(), text); 75 } 76 return instant; 77 } 78 79 80 public long roundFloor(long instant) { 81 return Long.MIN_VALUE; 82 } 83 84 85 public long roundCeiling(long instant) { 86 return Long.MAX_VALUE; 87 } 88 89 90 public long roundHalfFloor(long instant) { 91 return Long.MIN_VALUE; 92 } 93 94 95 public long roundHalfCeiling(long instant) { 96 return Long.MIN_VALUE; 97 } 98 99 100 public long roundHalfEven(long instant) { 101 return Long.MIN_VALUE; 102 } 103 104 105 public DurationField getDurationField() { 106 return UnsupportedDurationField.getInstance(DurationFieldType.eras()); 107 } 108 109 110 public DurationField getRangeDurationField() { 111 return null; 112 } 113 114 115 public int getMinimumValue() { 116 return ERA_VALUE; 117 } 118 119 120 public int getMaximumValue() { 121 return ERA_VALUE; 122 } 123 124 125 public String getAsText(int fieldValue, Locale locale) { 126 return iEraText; 127 } 128 129 130 public int getMaximumTextLength(Locale locale) { 131 return iEraText.length(); 132 } 133 134 } 135 | Popular Tags |