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.field;
017:
018: import java.io.Serializable;
019: import java.util.Locale;
020: import org.joda.time.DateTimeField;
021: import org.joda.time.DateTimeFieldType;
022: import org.joda.time.DurationField;
023: import org.joda.time.ReadablePartial;
024:
025: /**
026: * <code>DelegatedDateTimeField</code> delegates each method call to the
027: * date time field it wraps.
028: * <p>
029: * DelegatedDateTimeField is thread-safe and immutable, and its subclasses must
030: * be as well.
031: *
032: * @author Brian S O'Neill
033: * @since 1.0
034: * @see DecoratedDateTimeField
035: */
036: public class DelegatedDateTimeField extends DateTimeField implements
037: Serializable {
038:
039: /** Serialization version */
040: private static final long serialVersionUID = -4730164440214502503L;
041:
042: /** The DateTimeField being wrapped */
043: private final DateTimeField iField;
044: /** The override field type */
045: private final DateTimeFieldType iType;
046:
047: /**
048: * Constructor.
049: *
050: * @param field the field being decorated
051: */
052: public DelegatedDateTimeField(DateTimeField field) {
053: this (field, null);
054: }
055:
056: /**
057: * Constructor.
058: *
059: * @param field the field being decorated
060: * @param type the field type override
061: */
062: public DelegatedDateTimeField(DateTimeField field,
063: DateTimeFieldType type) {
064: super ();
065: if (field == null) {
066: throw new IllegalArgumentException(
067: "The field must not be null");
068: }
069: iField = field;
070: iType = (type == null ? field.getType() : type);
071: }
072:
073: /**
074: * Gets the wrapped date time field.
075: *
076: * @return the wrapped DateTimeField
077: */
078: public final DateTimeField getWrappedField() {
079: return iField;
080: }
081:
082: public DateTimeFieldType getType() {
083: return iType;
084: }
085:
086: public String getName() {
087: return iType.getName();
088: }
089:
090: public boolean isSupported() {
091: return iField.isSupported();
092: }
093:
094: public boolean isLenient() {
095: return iField.isLenient();
096: }
097:
098: public int get(long instant) {
099: return iField.get(instant);
100: }
101:
102: public String getAsText(long instant, Locale locale) {
103: return iField.getAsText(instant, locale);
104: }
105:
106: public String getAsText(long instant) {
107: return iField.getAsText(instant);
108: }
109:
110: public String getAsText(ReadablePartial partial, int fieldValue,
111: Locale locale) {
112: return iField.getAsText(partial, fieldValue, locale);
113: }
114:
115: public String getAsText(ReadablePartial partial, Locale locale) {
116: return iField.getAsText(partial, locale);
117: }
118:
119: public String getAsText(int fieldValue, Locale locale) {
120: return iField.getAsText(fieldValue, locale);
121: }
122:
123: public String getAsShortText(long instant, Locale locale) {
124: return iField.getAsShortText(instant, locale);
125: }
126:
127: public String getAsShortText(long instant) {
128: return iField.getAsShortText(instant);
129: }
130:
131: public String getAsShortText(ReadablePartial partial,
132: int fieldValue, Locale locale) {
133: return iField.getAsShortText(partial, fieldValue, locale);
134: }
135:
136: public String getAsShortText(ReadablePartial partial, Locale locale) {
137: return iField.getAsShortText(partial, locale);
138: }
139:
140: public String getAsShortText(int fieldValue, Locale locale) {
141: return iField.getAsShortText(fieldValue, locale);
142: }
143:
144: public long add(long instant, int value) {
145: return iField.add(instant, value);
146: }
147:
148: public long add(long instant, long value) {
149: return iField.add(instant, value);
150: }
151:
152: public int[] add(ReadablePartial instant, int fieldIndex,
153: int[] values, int valueToAdd) {
154: return iField.add(instant, fieldIndex, values, valueToAdd);
155: }
156:
157: public int[] addWrapPartial(ReadablePartial instant,
158: int fieldIndex, int[] values, int valueToAdd) {
159: return iField.addWrapPartial(instant, fieldIndex, values,
160: valueToAdd);
161: }
162:
163: public long addWrapField(long instant, int value) {
164: return iField.addWrapField(instant, value);
165: }
166:
167: public int[] addWrapField(ReadablePartial instant, int fieldIndex,
168: int[] values, int valueToAdd) {
169: return iField.addWrapField(instant, fieldIndex, values,
170: valueToAdd);
171: }
172:
173: public int getDifference(long minuendInstant, long subtrahendInstant) {
174: return iField.getDifference(minuendInstant, subtrahendInstant);
175: }
176:
177: public long getDifferenceAsLong(long minuendInstant,
178: long subtrahendInstant) {
179: return iField.getDifferenceAsLong(minuendInstant,
180: subtrahendInstant);
181: }
182:
183: public long set(long instant, int value) {
184: return iField.set(instant, value);
185: }
186:
187: public long set(long instant, String text, Locale locale) {
188: return iField.set(instant, text, locale);
189: }
190:
191: public long set(long instant, String text) {
192: return iField.set(instant, text);
193: }
194:
195: public int[] set(ReadablePartial instant, int fieldIndex,
196: int[] values, int newValue) {
197: return iField.set(instant, fieldIndex, values, newValue);
198: }
199:
200: public int[] set(ReadablePartial instant, int fieldIndex,
201: int[] values, String text, Locale locale) {
202: return iField.set(instant, fieldIndex, values, text, locale);
203: }
204:
205: public DurationField getDurationField() {
206: return iField.getDurationField();
207: }
208:
209: public DurationField getRangeDurationField() {
210: return iField.getRangeDurationField();
211: }
212:
213: public boolean isLeap(long instant) {
214: return iField.isLeap(instant);
215: }
216:
217: public int getLeapAmount(long instant) {
218: return iField.getLeapAmount(instant);
219: }
220:
221: public DurationField getLeapDurationField() {
222: return iField.getLeapDurationField();
223: }
224:
225: public int getMinimumValue() {
226: return iField.getMinimumValue();
227: }
228:
229: public int getMinimumValue(long instant) {
230: return iField.getMinimumValue(instant);
231: }
232:
233: public int getMinimumValue(ReadablePartial instant) {
234: return iField.getMinimumValue(instant);
235: }
236:
237: public int getMinimumValue(ReadablePartial instant, int[] values) {
238: return iField.getMinimumValue(instant, values);
239: }
240:
241: public int getMaximumValue() {
242: return iField.getMaximumValue();
243: }
244:
245: public int getMaximumValue(long instant) {
246: return iField.getMaximumValue(instant);
247: }
248:
249: public int getMaximumValue(ReadablePartial instant) {
250: return iField.getMaximumValue(instant);
251: }
252:
253: public int getMaximumValue(ReadablePartial instant, int[] values) {
254: return iField.getMaximumValue(instant, values);
255: }
256:
257: public int getMaximumTextLength(Locale locale) {
258: return iField.getMaximumTextLength(locale);
259: }
260:
261: public int getMaximumShortTextLength(Locale locale) {
262: return iField.getMaximumShortTextLength(locale);
263: }
264:
265: public long roundFloor(long instant) {
266: return iField.roundFloor(instant);
267: }
268:
269: public long roundCeiling(long instant) {
270: return iField.roundCeiling(instant);
271: }
272:
273: public long roundHalfFloor(long instant) {
274: return iField.roundHalfFloor(instant);
275: }
276:
277: public long roundHalfCeiling(long instant) {
278: return iField.roundHalfCeiling(instant);
279: }
280:
281: public long roundHalfEven(long instant) {
282: return iField.roundHalfEven(instant);
283: }
284:
285: public long remainder(long instant) {
286: return iField.remainder(instant);
287: }
288:
289: public String toString() {
290: return ("DateTimeField[" + getName() + ']');
291: }
292:
293: }
|