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 org.joda.time.DateTimeField;
019: import org.joda.time.DateTimeFieldType;
020: import org.joda.time.ReadablePartial;
021: import org.joda.time.field.DecoratedDateTimeField;
022: import org.joda.time.field.FieldUtils;
023:
024: /**
025: * This field is not publicy exposed by ISOChronology, but rather it is used to
026: * build the yearOfCentury and centuryOfEra fields. It merely drops the sign of
027: * the year.
028: *
029: * @author Brian S O'Neill
030: * @see GJYearOfEraDateTimeField
031: * @since 1.0
032: */
033: class ISOYearOfEraDateTimeField extends DecoratedDateTimeField {
034:
035: private static final long serialVersionUID = 7037524068969447317L;
036:
037: /**
038: * Singleton instance
039: */
040: static final DateTimeField INSTANCE = new ISOYearOfEraDateTimeField();
041:
042: /**
043: * Restricted constructor.
044: */
045: private ISOYearOfEraDateTimeField() {
046: super (GregorianChronology.getInstanceUTC().year(),
047: DateTimeFieldType.yearOfEra());
048: }
049:
050: public int get(long instant) {
051: int year = getWrappedField().get(instant);
052: return year < 0 ? -year : year;
053: }
054:
055: public long add(long instant, int years) {
056: return getWrappedField().add(instant, years);
057: }
058:
059: public long add(long instant, long years) {
060: return getWrappedField().add(instant, years);
061: }
062:
063: public long addWrapField(long instant, int years) {
064: return getWrappedField().addWrapField(instant, years);
065: }
066:
067: public int[] addWrapField(ReadablePartial instant, int fieldIndex,
068: int[] values, int years) {
069: return getWrappedField().addWrapField(instant, fieldIndex,
070: values, years);
071: }
072:
073: public int getDifference(long minuendInstant, long subtrahendInstant) {
074: return getWrappedField().getDifference(minuendInstant,
075: subtrahendInstant);
076: }
077:
078: public long getDifferenceAsLong(long minuendInstant,
079: long subtrahendInstant) {
080: return getWrappedField().getDifferenceAsLong(minuendInstant,
081: subtrahendInstant);
082: }
083:
084: public long set(long instant, int year) {
085: FieldUtils.verifyValueBounds(this , year, 0, getMaximumValue());
086: if (getWrappedField().get(instant) < 0) {
087: year = -year;
088: }
089: return super .set(instant, year);
090: }
091:
092: public int getMinimumValue() {
093: return 0;
094: }
095:
096: public int getMaximumValue() {
097: return getWrappedField().getMaximumValue();
098: }
099:
100: public long roundFloor(long instant) {
101: return getWrappedField().roundFloor(instant);
102: }
103:
104: public long roundCeiling(long instant) {
105: return getWrappedField().roundCeiling(instant);
106: }
107:
108: public long remainder(long instant) {
109: return getWrappedField().remainder(instant);
110: }
111:
112: /**
113: * Serialization singleton
114: */
115: private Object readResolve() {
116: return INSTANCE;
117: }
118: }
|