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

COVERAGE SUMMARY FOR SOURCE FILE [ReadableDurationConverter.java]

nameclass, %method, %block, %line, %
ReadableDurationConverter.java100% (1/1)100% (5/5)100% (50/50)100% (12/12)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ReadableDurationConverter100% (1/1)100% (5/5)100% (50/50)100% (12/12)
<static initializer> 100% (1/1)100% (5/5)100% (1/1)
ReadableDurationConverter (): void 100% (1/1)100% (3/3)100% (2/2)
getDurationMillis (Object): long 100% (1/1)100% (4/4)100% (1/1)
getSupportedType (): Class 100% (1/1)100% (9/9)100% (1/1)
setInto (ReadWritablePeriod, Object, Chronology): void 100% (1/1)100% (29/29)100% (7/7)

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.convert;
17 
18import org.joda.time.Chronology;
19import org.joda.time.DateTimeUtils;
20import org.joda.time.ReadWritablePeriod;
21import org.joda.time.ReadableDuration;
22 
23/**
24 * ReadableDurationConverter extracts milliseconds and chronology from a ReadableDuration.
25 *
26 * @author Stephen Colebourne
27 * @author Brian S O'Neill
28 * @since 1.0
29 */
30class ReadableDurationConverter extends AbstractConverter
31        implements DurationConverter, PeriodConverter {
32 
33    /**
34     * Singleton instance.
35     */
36    static final ReadableDurationConverter INSTANCE = new ReadableDurationConverter();
37 
38    /**
39     * Restricted constructor.
40     */
41    protected ReadableDurationConverter() {
42        super();
43    }
44 
45    //-----------------------------------------------------------------------
46    /**
47     * Extracts the millis from an object of this convertor's type.
48     * 
49     * @param object  the object to convert, must not be null
50     * @return the millisecond value
51     * @throws NullPointerException if the object is null
52     * @throws ClassCastException if the object is an invalid type
53     * @throws IllegalArgumentException if the object is invalid
54     */
55    public long getDurationMillis(Object object) {
56        return ((ReadableDuration) object).getMillis();
57    }
58 
59    //-----------------------------------------------------------------------
60    /**
61     * Extracts duration values from an object of this converter's type, and
62     * sets them into the given ReadWritableDuration.
63     *
64     * @param writablePeriod  period to get modified
65     * @param object  the object to convert, must not be null
66     * @param chrono  the chronology to use, must not be null
67     * @throws NullPointerException if the duration or object is null
68     * @throws ClassCastException if the object is an invalid type
69     * @throws IllegalArgumentException if the object is invalid
70     */
71    public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) {
72        ReadableDuration dur = (ReadableDuration) object;
73        chrono = DateTimeUtils.getChronology(chrono);
74        long duration = dur.getMillis();
75        int[] values = chrono.get(writablePeriod, duration);
76        for (int i = 0; i < values.length; i++) {
77            writablePeriod.setValue(i, values[i]);
78        }
79    }
80 
81    //-----------------------------------------------------------------------
82    /**
83     * Returns ReadableDuration.class.
84     * 
85     * @return ReadableDuration.class
86     */
87    public Class getSupportedType() {
88        return ReadableDuration.class;
89    }
90 
91}

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