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.convert; |
17 | |
18 | import org.joda.time.Chronology; |
19 | |
20 | /** |
21 | * LongConverter converts a Long to an instant, partial or duration. |
22 | * The Long value represents milliseconds in the ISO chronology. |
23 | * |
24 | * @author Stephen Colebourne |
25 | * @author Brian S O'Neill |
26 | * @since 1.0 |
27 | */ |
28 | class LongConverter extends AbstractConverter |
29 | implements InstantConverter, PartialConverter, DurationConverter { |
30 | |
31 | /** |
32 | * Singleton instance. |
33 | */ |
34 | static final LongConverter INSTANCE = new LongConverter(); |
35 | |
36 | /** |
37 | * Restricted constructor. |
38 | */ |
39 | protected LongConverter() { |
40 | super(); |
41 | } |
42 | |
43 | //----------------------------------------------------------------------- |
44 | /** |
45 | * Gets the millisecond instant, which is the Long value. |
46 | * |
47 | * @param object the Long to convert, must not be null |
48 | * @param chrono the chronology to use, which is always non-null |
49 | * @return the millisecond value |
50 | * @throws NullPointerException if the object is null |
51 | * @throws ClassCastException if the object is an invalid type |
52 | */ |
53 | public long getInstantMillis(Object object, Chronology chrono) { |
54 | return ((Long) object).longValue(); |
55 | } |
56 | |
57 | //----------------------------------------------------------------------- |
58 | /** |
59 | * Gets the millisecond duration, which is the Long value. |
60 | * |
61 | * @param object the Long to convert, must not be null |
62 | * @return the millisecond duration |
63 | * @throws NullPointerException if the object is null |
64 | * @throws ClassCastException if the object is an invalid type |
65 | */ |
66 | public long getDurationMillis(Object object) { |
67 | return ((Long) object).longValue(); |
68 | } |
69 | |
70 | //----------------------------------------------------------------------- |
71 | /** |
72 | * Returns Long.class. |
73 | * |
74 | * @return Long.class |
75 | */ |
76 | public Class getSupportedType() { |
77 | return Long.class; |
78 | } |
79 | |
80 | } |