EMMA Coverage Report (generated Tue Oct 28 00:01:11 GMT 2008)
[all classes][org.joda.time.chrono]

COVERAGE SUMMARY FOR SOURCE FILE [GJEraDateTimeField.java]

nameclass, %method, %block, %line, %
GJEraDateTimeField.java100% (1/1)71%  (12/17)75%  (83/111)77%  (23/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class GJEraDateTimeField100% (1/1)71%  (12/17)75%  (83/111)77%  (23/30)
readResolve (): Object 0%   (0/1)0%   (0/4)0%   (0/1)
roundCeiling (long): long 0%   (0/1)0%   (0/12)0%   (0/3)
roundHalfCeiling (long): long 0%   (0/1)0%   (0/4)0%   (0/1)
roundHalfEven (long): long 0%   (0/1)0%   (0/4)0%   (0/1)
roundHalfFloor (long): long 0%   (0/1)0%   (0/4)0%   (0/1)
GJEraDateTimeField (BasicChronology): void 100% (1/1)100% (7/7)100% (3/3)
get (long): int 100% (1/1)100% (9/9)100% (3/3)
getAsText (int, Locale): String 100% (1/1)100% (5/5)100% (1/1)
getDurationField (): DurationField 100% (1/1)100% (3/3)100% (1/1)
getMaximumTextLength (Locale): int 100% (1/1)100% (4/4)100% (1/1)
getMaximumValue (): int 100% (1/1)100% (2/2)100% (1/1)
getMinimumValue (): int 100% (1/1)100% (2/2)100% (1/1)
getRangeDurationField (): DurationField 100% (1/1)100% (2/2)100% (1/1)
isLenient (): boolean 100% (1/1)100% (2/2)100% (1/1)
roundFloor (long): long 100% (1/1)100% (13/13)100% (3/3)
set (long, String, Locale): long 100% (1/1)100% (8/8)100% (1/1)
set (long, int): long 100% (1/1)100% (26/26)100% (6/6)

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 */
16package org.joda.time.chrono;
17 
18import java.util.Locale;
19 
20import org.joda.time.DateTimeConstants;
21import org.joda.time.DateTimeFieldType;
22import org.joda.time.DurationField;
23import org.joda.time.DurationFieldType;
24import org.joda.time.field.BaseDateTimeField;
25import org.joda.time.field.FieldUtils;
26import org.joda.time.field.UnsupportedDurationField;
27 
28/**
29 * Provides time calculations for the era component of time.
30 *
31 * @author Stephen Colebourne
32 * @author Brian S O'Neill
33 * @since 1.0
34 */
35final class GJEraDateTimeField extends BaseDateTimeField {
36    
37    /** Serialization version */
38    private static final long serialVersionUID = 4240986525305515528L;
39 
40    private final BasicChronology iChronology;
41 
42    /**
43     * Restricted constructor
44     */
45    GJEraDateTimeField(BasicChronology chronology) {
46        super(DateTimeFieldType.era());
47        iChronology = chronology;
48    }
49 
50    public boolean isLenient() {
51        return false;
52    }
53 
54    /**
55     * Get the Era component of the specified time instant.
56     * 
57     * @param instant  the time instant in millis to query.
58     */
59    public int get(long instant) {
60        if (iChronology.getYear(instant) <= 0) {
61            return DateTimeConstants.BCE;
62        } else {
63            return DateTimeConstants.CE;
64        }
65    }
66 
67    public String getAsText(int fieldValue, Locale locale) {
68        return GJLocaleSymbols.forLocale(locale).eraValueToText(fieldValue);
69    }
70 
71    /**
72     * Set the Era component of the specified time instant.
73     * 
74     * @param instant  the time instant in millis to update.
75     * @param era  the era to update the time to.
76     * @return the updated time instant.
77     * @throws IllegalArgumentException  if era is invalid.
78     */
79    public long set(long instant, int era) {
80        FieldUtils.verifyValueBounds(this, era, DateTimeConstants.BCE, DateTimeConstants.CE);
81            
82        int oldEra = get(instant);
83        if (oldEra != era) {
84            int year = iChronology.getYear(instant);
85            return iChronology.setYear(instant, -year);
86        } else {
87            return instant;
88        }
89    }
90 
91    public long set(long instant, String text, Locale locale) {
92        return set(instant, GJLocaleSymbols.forLocale(locale).eraTextToValue(text));
93    }
94 
95    public long roundFloor(long instant) {
96        if (get(instant) == DateTimeConstants.CE) {
97            return iChronology.setYear(0, 1);
98        } else {
99            return Long.MIN_VALUE;
100        }
101    }
102 
103    public long roundCeiling(long instant) {
104        if (get(instant) == DateTimeConstants.BCE) {
105            return iChronology.setYear(0, 1);
106        } else {
107            return Long.MAX_VALUE;
108        }
109    }
110 
111    public long roundHalfFloor(long instant) {
112        // In reality, the era is infinite, so there is no halfway point.
113        return roundFloor(instant);
114    }
115 
116    public long roundHalfCeiling(long instant) {
117        // In reality, the era is infinite, so there is no halfway point.
118        return roundFloor(instant);
119    }
120 
121    public long roundHalfEven(long instant) {
122        // In reality, the era is infinite, so there is no halfway point.
123        return roundFloor(instant);
124    }
125 
126    public DurationField getDurationField() {
127        return UnsupportedDurationField.getInstance(DurationFieldType.eras());
128    }
129 
130    public DurationField getRangeDurationField() {
131        return null;
132    }
133 
134    public int getMinimumValue() {
135        return DateTimeConstants.BCE;
136    }
137 
138    public int getMaximumValue() {
139        return DateTimeConstants.CE;
140    }
141 
142    public int getMaximumTextLength(Locale locale) {
143        return GJLocaleSymbols.forLocale(locale).getEraMaxTextLength();
144    }
145 
146    /**
147     * Serialization singleton
148     */
149    private Object readResolve() {
150        return iChronology.era();
151    }
152}

[all classes][org.joda.time.chrono]
EMMA 2.0.5312 (C) Vladimir Roubtsov