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

COVERAGE SUMMARY FOR SOURCE FILE [BasicYearDateTimeField.java]

nameclass, %method, %block, %line, %
BasicYearDateTimeField.java100% (1/1)94%  (17/18)98%  (162/166)97%  (36/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BasicYearDateTimeField100% (1/1)94%  (17/18)98%  (162/166)97%  (36/37)
readResolve (): Object 0%   (0/1)0%   (0/4)0%   (0/1)
BasicYearDateTimeField (BasicChronology): void 100% (1/1)100% (9/9)100% (3/3)
add (long, int): long 100% (1/1)100% (17/17)100% (5/5)
add (long, long): long 100% (1/1)100% (6/6)100% (1/1)
addWrapField (long, int): long 100% (1/1)100% (24/24)100% (5/5)
get (long): int 100% (1/1)100% (5/5)100% (1/1)
getDifferenceAsLong (long, long): long 100% (1/1)100% (17/17)100% (3/3)
getLeapAmount (long): int 100% (1/1)100% (11/11)100% (3/3)
getLeapDurationField (): DurationField 100% (1/1)100% (4/4)100% (1/1)
getMaximumValue (): int 100% (1/1)100% (4/4)100% (1/1)
getMinimumValue (): int 100% (1/1)100% (4/4)100% (1/1)
getRangeDurationField (): DurationField 100% (1/1)100% (2/2)100% (1/1)
isLeap (long): boolean 100% (1/1)100% (7/7)100% (1/1)
isLenient (): boolean 100% (1/1)100% (2/2)100% (1/1)
remainder (long): long 100% (1/1)100% (6/6)100% (1/1)
roundCeiling (long): long 100% (1/1)100% (22/22)100% (5/5)
roundFloor (long): long 100% (1/1)100% (7/7)100% (1/1)
set (long, int): long 100% (1/1)100% (15/15)100% (2/2)

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 org.joda.time.DateTimeFieldType;
19import org.joda.time.DurationField;
20import org.joda.time.field.FieldUtils;
21import org.joda.time.field.ImpreciseDateTimeField;
22 
23/**
24 * A year field suitable for many calendars.
25 *
26 * @author Guy Allard
27 * @author Stephen Colebourne
28 * @author Brian S O'Neill
29 * @since 1.1, refactored from GJYearDateTimeField
30 */
31class BasicYearDateTimeField extends ImpreciseDateTimeField {
32 
33    /** Serialization version. */
34    private static final long serialVersionUID = -98628754872287L;
35 
36    /** The underlying basic chronology. */
37    protected final BasicChronology iChronology;
38 
39    /**
40     * Restricted constructor.
41     * 
42     * @param chronology  the chronology this field belogs to
43     */
44    BasicYearDateTimeField(BasicChronology chronology) {
45        super(DateTimeFieldType.year(), chronology.getAverageMillisPerYear());
46        iChronology = chronology;
47    }
48 
49    public boolean isLenient() {
50        return false;
51    }
52 
53    public int get(long instant) {
54        return iChronology.getYear(instant);
55    }
56 
57    public long add(long instant, int years) {
58        if (years == 0) {
59            return instant;
60        }
61        int thisYear = get(instant);
62        int newYear = FieldUtils.safeAdd(thisYear, years);
63        return set(instant, newYear);
64    }
65 
66    public long add(long instant, long years) {
67        return add(instant, FieldUtils.safeToInt(years));
68    }
69 
70    public long addWrapField(long instant, int years) {
71        if (years == 0) {
72            return instant;
73        }
74        // Return newly calculated millis value
75        int thisYear = iChronology.getYear(instant);
76        int wrappedYear = FieldUtils.getWrappedValue
77            (thisYear, years, iChronology.getMinYear(), iChronology.getMaxYear());
78        return set(instant, wrappedYear);
79    }
80 
81    public long set(long instant, int year) {
82        FieldUtils.verifyValueBounds
83            (this, year, iChronology.getMinYear(), iChronology.getMaxYear());
84        return iChronology.setYear(instant, year);
85    }
86 
87    public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
88        if (minuendInstant < subtrahendInstant) {
89            return -iChronology.getYearDifference(subtrahendInstant, minuendInstant);
90        }
91        return iChronology.getYearDifference(minuendInstant, subtrahendInstant);
92    }
93 
94    public DurationField getRangeDurationField() {
95        return null;
96    }
97 
98    public boolean isLeap(long instant) {
99        return iChronology.isLeapYear(get(instant));
100    }
101 
102    public int getLeapAmount(long instant) {
103        if (iChronology.isLeapYear(get(instant))) {
104            return 1;
105        } else {
106            return 0;
107        }
108    }
109 
110    public DurationField getLeapDurationField() {
111        return iChronology.days();
112    }
113 
114    public int getMinimumValue() {
115        return iChronology.getMinYear();
116    }
117 
118    public int getMaximumValue() {
119        return iChronology.getMaxYear();
120    }
121 
122    public long roundFloor(long instant) {
123        return iChronology.getYearMillis(get(instant));
124    }
125 
126    public long roundCeiling(long instant) {
127        int year = get(instant);
128        long yearStartMillis = iChronology.getYearMillis(year);
129        if (instant != yearStartMillis) {
130            // Bump up to start of next year.
131            instant = iChronology.getYearMillis(year + 1);
132        }
133        return instant;
134    }
135 
136    public long remainder(long instant) {
137        return instant - roundFloor(instant);
138    }
139 
140    /**
141     * Serialization singleton
142     */
143    private Object readResolve() {
144        return iChronology.year();
145    }
146}

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