1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20
21 package org.apache.directory.server.ntp.messages;
22
23
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.List;
27
28
29 /**
30 * Leap Indicator (LI): This is a two-bit code warning of an impending
31 * leap second to be inserted/deleted in the last minute of the current
32 * day, with bit 0 and bit 1, respectively, coded as follows:
33 *
34 * LI Value Meaning
35 * -------------------------------------------------------
36 * 00 0 no warning
37 * 01 1 last minute has 61 seconds
38 * 10 2 last minute has 59 seconds)
39 * 11 3 alarm condition (clock not synchronized)
40 *
41 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42 * @version $Rev: 586763 $, $Date: 2007-10-20 19:26:29 +0200 (Sa, 20 Okt 2007) $
43 */
44 public final class LeapIndicatorType implements Comparable<LeapIndicatorType>
45 {
46 /**
47 * Constant for the "No leap second warning" leap indicator type.
48 */
49 public static final LeapIndicatorType NO_WARNING = new LeapIndicatorType( 0, "No leap second warning." );
50
51 /**
52 * Constant for the "Last minute has 61 seconds" leap indicator type.
53 */
54 public static final LeapIndicatorType POSITIVE_LEAP_SECOND = new LeapIndicatorType( 1,
55 "Last minute has 61 seconds." );
56
57 /**
58 * Constant for the "Last minute has 59 seconds" leap indicator type.
59 */
60 public static final LeapIndicatorType NEGATIVE_LEAP_SECOND = new LeapIndicatorType( 2,
61 "Last minute has 59 seconds." );
62
63 /**
64 * Constant for the "Alarm condition (clock not synchronized)" leap indicator type.
65 */
66 public static final LeapIndicatorType ALARM_CONDITION = new LeapIndicatorType( 3,
67 "Alarm condition (clock not synchronized)." );
68
69 /**
70 * Array for building a List of VALUES.
71 */
72 private static final LeapIndicatorType[] values =
73 { NO_WARNING, POSITIVE_LEAP_SECOND, NEGATIVE_LEAP_SECOND, ALARM_CONDITION };
74
75 /**
76 * A list of all the leap indicator type constants.
77 */
78 public static final List<LeapIndicatorType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
79
80 /**
81 * The name of the leap indicator type.
82 */
83 private final String name;
84
85 /**
86 * The value/code for the leap indicator type.
87 */
88 private final int ordinal;
89
90
91 /**
92 * Private constructor prevents construction outside of this class.
93 */
94 private LeapIndicatorType( int ordinal, String name )
95 {
96 this.ordinal = ordinal;
97 this.name = name;
98 }
99
100
101 /**
102 * Returns the leap indicator type when specified by its ordinal.
103 *
104 * @param type
105 * @return The leap indicator type.
106 */
107 public static LeapIndicatorType getTypeByOrdinal( int type )
108 {
109 for ( int ii = 0; ii < values.length; ii++ )
110 {
111 if ( values[ii].ordinal == type )
112 {
113 return values[ii];
114 }
115 }
116
117 return NO_WARNING;
118 }
119
120
121 /**
122 * Returns the number associated with this leap indicator type.
123 *
124 * @return The leap indicator type ordinal.
125 */
126 public int getOrdinal()
127 {
128 return ordinal;
129 }
130
131
132 public int compareTo( LeapIndicatorType that )
133 {
134 return ordinal - that.ordinal;
135 }
136
137
138 public String toString()
139 {
140 return name;
141 }
142 }