]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/impl/duration/TimeUnit.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / impl / duration / TimeUnit.java
1 /*
2 ******************************************************************************
3 * Copyright (C) 2007, International Business Machines Corporation and   *
4 * others. All Rights Reserved.                                               *
5 ******************************************************************************
6 */
7
8 package com.ibm.icu.impl.duration;
9
10 /**
11  * 'Enum' for individual time units.  Not an actual enum so that it can be 
12  * used by Java 1.4.
13  */
14 public final class TimeUnit {
15   /** The name of this unit, a key, not for localization. */
16   final String name;
17
18   /** The ordinal of the unit, in order from largest to smallest. */
19   final byte ordinal;
20
21   /** Private constructor */
22   private TimeUnit(String name, int ordinal) {
23     this.name = name;
24     this.ordinal = (byte) ordinal;
25   }
26
27   public String toString() {
28     return name;
29   }
30   
31   /** Represents a year. */ 
32   public static final TimeUnit YEAR = new TimeUnit("year", 0);
33
34   /** Represents a month. */  
35   public static final TimeUnit MONTH = new TimeUnit("month", 1);
36
37   /** Represents a week. */ 
38   public static final TimeUnit WEEK = new TimeUnit("week", 2);
39
40   /** Represents a day. */ 
41   public static final TimeUnit DAY = new TimeUnit("day", 3);
42
43   /** Represents an hour. */ 
44   public static final TimeUnit HOUR = new TimeUnit("hour", 4);
45
46   /** Represents a minute. */ 
47   public static final TimeUnit MINUTE = new TimeUnit("minute", 5);
48
49   /** Represents a second. */ 
50   public static final TimeUnit SECOND = new TimeUnit("second", 6);
51
52   /** Represents a millisecond. */ 
53   public static final TimeUnit MILLISECOND = new TimeUnit("millisecond", 7);
54
55   /** Returns the next larger time unit, or null if this is the largest. */
56   public TimeUnit larger() {
57     return ordinal == 0 ? null : units[ordinal - 1];
58   }
59
60   /** Returns the next smaller time unit, or null if this is the smallest. */
61   public TimeUnit smaller() {
62     return ordinal == units.length - 1 ? null : units[ordinal + 1];
63   }
64
65   /** The list of units, in order from largest to smallest. */
66   static final TimeUnit[] units = {
67     YEAR, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, MILLISECOND
68   };
69
70     /** Returns the ordinal value of this time unit, largest is 0. **/
71   public int ordinal() {
72     return ordinal;
73   }
74
75   /** Approximate, durations for the units independent of the time at which
76       they are measured */
77
78   // hack, initialization long array using expressions with 'L' at end doesn't
79   // compute entire expression using 'long'.  differs from initializtion of
80   // a single constant
81   static final long[] approxDurations = {
82     36525L*24*60*60*10, 3045*24*60*60*10L, 7*24*60*60*1000L, 24*60*60*1000L, 
83     60*60*1000L, 60*1000L, 1000L, 1L
84   };
85 }