~ubuntu-branches/ubuntu/precise/libjoda-time-java/precise

« back to all changes in this revision

Viewing changes to src/java/org/joda/time/chrono/BasicSingleEraDateTimeField.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2011-02-09 23:05:14 UTC
  • mfrom: (5.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110209230514-22otglg8nm2y2y2n
Tags: 1.6.2-2
* Upload to unstable.
* Add (temporary) Build-Depends: ant.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.chrono;
17
 
 
18
 
import java.util.Locale;
19
 
 
20
 
import org.joda.time.DateTimeConstants;
21
 
import org.joda.time.DateTimeFieldType;
22
 
import org.joda.time.DurationField;
23
 
import org.joda.time.DurationFieldType;
24
 
import org.joda.time.IllegalFieldValueException;
25
 
import org.joda.time.field.BaseDateTimeField;
26
 
import org.joda.time.field.FieldUtils;
27
 
import org.joda.time.field.UnsupportedDurationField;
28
 
 
29
 
/**
30
 
 * Provides time calculations for the coptic era component of time.
31
 
 *
32
 
 * @author Brian S O'Neill
33
 
 * @author Stephen Colebourne
34
 
 * @since 1.2, refactored from CopticEraDateTimeField
35
 
 */
36
 
final class BasicSingleEraDateTimeField extends BaseDateTimeField {
37
 
 
38
 
    /**
39
 
     * Value of the era, which will be the same as DateTimeConstants.CE.
40
 
     */
41
 
    private static final int ERA_VALUE = DateTimeConstants.CE;
42
 
    /**
43
 
     * Text value of the era.
44
 
     */
45
 
    private final String iEraText;
46
 
 
47
 
    /**
48
 
     * Restricted constructor.
49
 
     */
50
 
    BasicSingleEraDateTimeField(String text) {
51
 
        super(DateTimeFieldType.era());
52
 
        iEraText = text;
53
 
    }
54
 
 
55
 
    /** @inheritDoc */
56
 
    public boolean isLenient() {
57
 
        return false;
58
 
    }
59
 
 
60
 
    /** @inheritDoc */
61
 
    public int get(long instant) {
62
 
        return ERA_VALUE;
63
 
    }
64
 
 
65
 
    /** @inheritDoc */
66
 
    public long set(long instant, int era) {
67
 
        FieldUtils.verifyValueBounds(this, era, ERA_VALUE, ERA_VALUE);
68
 
        return instant;
69
 
    }
70
 
 
71
 
    /** @inheritDoc */
72
 
    public long set(long instant, String text, Locale locale) {
73
 
        if (iEraText.equals(text) == false && "1".equals(text) == false) {
74
 
            throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
75
 
        }
76
 
        return instant;
77
 
    }
78
 
 
79
 
    /** @inheritDoc */
80
 
    public long roundFloor(long instant) {
81
 
        return Long.MIN_VALUE;
82
 
    }
83
 
 
84
 
    /** @inheritDoc */
85
 
    public long roundCeiling(long instant) {
86
 
        return Long.MAX_VALUE;
87
 
    }
88
 
 
89
 
    /** @inheritDoc */
90
 
    public long roundHalfFloor(long instant) {
91
 
        return Long.MIN_VALUE;
92
 
    }
93
 
 
94
 
    /** @inheritDoc */
95
 
    public long roundHalfCeiling(long instant) {
96
 
        return Long.MIN_VALUE;
97
 
    }
98
 
 
99
 
    /** @inheritDoc */
100
 
    public long roundHalfEven(long instant) {
101
 
        return Long.MIN_VALUE;
102
 
    }
103
 
 
104
 
    /** @inheritDoc */
105
 
    public DurationField getDurationField() {
106
 
        return UnsupportedDurationField.getInstance(DurationFieldType.eras());
107
 
    }
108
 
 
109
 
    /** @inheritDoc */
110
 
    public DurationField getRangeDurationField() {
111
 
        return null;
112
 
    }
113
 
 
114
 
    /** @inheritDoc */
115
 
    public int getMinimumValue() {
116
 
        return ERA_VALUE;
117
 
    }
118
 
 
119
 
    /** @inheritDoc */
120
 
    public int getMaximumValue() {
121
 
        return ERA_VALUE;
122
 
    }
123
 
 
124
 
    /** @inheritDoc */
125
 
    public String getAsText(int fieldValue, Locale locale) {
126
 
        return iEraText;
127
 
    }
128
 
 
129
 
    /** @inheritDoc */
130
 
    public int getMaximumTextLength(Locale locale) {
131
 
        return iEraText.length();
132
 
    }
133
 
 
134
 
}