001: /*
002: * Copyright 2001-2005 Stephen Colebourne
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.joda.time.chrono;
017:
018: import java.util.Locale;
019:
020: import org.joda.time.DateTimeConstants;
021: import org.joda.time.DateTimeFieldType;
022: import org.joda.time.DurationField;
023: import org.joda.time.DurationFieldType;
024: import org.joda.time.IllegalFieldValueException;
025: import org.joda.time.field.BaseDateTimeField;
026: import org.joda.time.field.FieldUtils;
027: import org.joda.time.field.UnsupportedDurationField;
028:
029: /**
030: * Provides time calculations for the coptic era component of time.
031: *
032: * @author Brian S O'Neill
033: * @author Stephen Colebourne
034: * @since 1.2, refactored from CopticEraDateTimeField
035: */
036: final class BasicSingleEraDateTimeField extends BaseDateTimeField {
037:
038: /**
039: * Value of the era, which will be the same as DateTimeConstants.CE.
040: */
041: private static final int ERA_VALUE = DateTimeConstants.CE;
042: /**
043: * Text value of the era.
044: */
045: private final String iEraText;
046:
047: /**
048: * Restricted constructor.
049: */
050: BasicSingleEraDateTimeField(String text) {
051: super (DateTimeFieldType.era());
052: iEraText = text;
053: }
054:
055: /** @inheritDoc */
056: public boolean isLenient() {
057: return false;
058: }
059:
060: /** @inheritDoc */
061: public int get(long instant) {
062: return ERA_VALUE;
063: }
064:
065: /** @inheritDoc */
066: public long set(long instant, int era) {
067: FieldUtils.verifyValueBounds(this , era, ERA_VALUE, ERA_VALUE);
068: return instant;
069: }
070:
071: /** @inheritDoc */
072: public long set(long instant, String text, Locale locale) {
073: if (iEraText.equals(text) == false && "1".equals(text) == false) {
074: throw new IllegalFieldValueException(DateTimeFieldType
075: .era(), text);
076: }
077: return instant;
078: }
079:
080: /** @inheritDoc */
081: public long roundFloor(long instant) {
082: return Long.MIN_VALUE;
083: }
084:
085: /** @inheritDoc */
086: public long roundCeiling(long instant) {
087: return Long.MAX_VALUE;
088: }
089:
090: /** @inheritDoc */
091: public long roundHalfFloor(long instant) {
092: return Long.MIN_VALUE;
093: }
094:
095: /** @inheritDoc */
096: public long roundHalfCeiling(long instant) {
097: return Long.MIN_VALUE;
098: }
099:
100: /** @inheritDoc */
101: public long roundHalfEven(long instant) {
102: return Long.MIN_VALUE;
103: }
104:
105: /** @inheritDoc */
106: public DurationField getDurationField() {
107: return UnsupportedDurationField.getInstance(DurationFieldType
108: .eras());
109: }
110:
111: /** @inheritDoc */
112: public DurationField getRangeDurationField() {
113: return null;
114: }
115:
116: /** @inheritDoc */
117: public int getMinimumValue() {
118: return ERA_VALUE;
119: }
120:
121: /** @inheritDoc */
122: public int getMaximumValue() {
123: return ERA_VALUE;
124: }
125:
126: /** @inheritDoc */
127: public String getAsText(int fieldValue, Locale locale) {
128: return iEraText;
129: }
130:
131: /** @inheritDoc */
132: public int getMaximumTextLength(Locale locale) {
133: return iEraText.length();
134: }
135:
136: }
|