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