KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > field > DecoratedDateTimeField


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.joda.time.field;
17
18 import org.joda.time.DateTimeField;
19 import org.joda.time.DateTimeFieldType;
20 import org.joda.time.DurationField;
21
22 /**
23  * <code>DecoratedDateTimeField</code> extends {@link BaseDateTimeField},
24  * implementing only the minimum required set of methods. These implemented
25  * methods delegate to a wrapped field.
26  * <p>
27  * This design allows new DateTimeField types to be defined that piggyback on
28  * top of another, inheriting all the safe method implementations from
29  * BaseDateTimeField. Should any method require pure delegation to the
30  * wrapped field, simply override and use the provided getWrappedField method.
31  * <p>
32  * DecoratedDateTimeField is thread-safe and immutable, and its subclasses must
33  * be as well.
34  *
35  * @author Brian S O'Neill
36  * @since 1.0
37  * @see DelegatedDateTimeField
38  */

39 public abstract class DecoratedDateTimeField extends BaseDateTimeField {
40
41     /** Serialization version */
42     private static final long serialVersionUID = 203115783733757597L;
43
44     /** The DateTimeField being wrapped */
45     private final DateTimeField iField;
46
47     /**
48      * Constructor.
49      *
50      * @param field the field being decorated
51      * @param type allow type to be overridden
52      */

53     protected DecoratedDateTimeField(DateTimeField field, DateTimeFieldType type) {
54         super(type);
55         if (field == null) {
56             throw new IllegalArgumentException JavaDoc("The field must not be null");
57         }
58         if (!field.isSupported()) {
59             throw new IllegalArgumentException JavaDoc("The field must be supported");
60         }
61         iField = field;
62     }
63
64     /**
65      * Gets the wrapped date time field.
66      *
67      * @return the wrapped DateTimeField
68      */

69     public final DateTimeField getWrappedField() {
70         return iField;
71     }
72
73     public boolean isLenient() {
74         return iField.isLenient();
75     }
76
77     public int get(long instant) {
78         return iField.get(instant);
79     }
80
81     public long set(long instant, int value) {
82         return iField.set(instant, value);
83     }
84
85     public DurationField getDurationField() {
86         return iField.getDurationField();
87     }
88
89     public DurationField getRangeDurationField() {
90         return iField.getRangeDurationField();
91     }
92
93     public int getMinimumValue() {
94         return iField.getMinimumValue();
95     }
96
97     public int getMaximumValue() {
98         return iField.getMaximumValue();
99     }
100
101     public long roundFloor(long instant) {
102         return iField.roundFloor(instant);
103     }
104
105 }
106
Popular Tags