View Javadoc
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  /**
25   * Leap Indicator (LI): This is a two-bit code warning of an impending
26   * leap second to be inserted/deleted in the last minute of the current
27   * day, with bit 0 and bit 1, respectively, coded as follows:
28   *
29   *    LI       Value     Meaning
30   *    -------------------------------------------------------
31   *    00       0         no warning
32   *    01       1         last minute has 61 seconds
33   *    10       2         last minute has 59 seconds)
34   *    11       3         alarm condition (clock not synchronized)
35   * 
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public enum LeapIndicatorType
39  {
40      /**
41       * Constant for the "No leap second warning" leap indicator type.
42       */
43      NO_WARNING(0, "No leap second warning."),
44  
45      /**
46       * Constant for the "Last minute has 61 seconds" leap indicator type.
47       */
48      POSITIVE_LEAP_SECOND(1, "Last minute has 61 seconds."),
49  
50      /**
51       * Constant for the "Last minute has 59 seconds" leap indicator type.
52       */
53      NEGATIVE_LEAP_SECOND(2, "Last minute has 59 seconds."),
54  
55      /**
56       * Constant for the "Alarm condition (clock not synchronized)" leap indicator type.
57       */
58      ALARM_CONDITION(3, "Alarm condition (clock not synchronized).");
59  
60      /**
61       * The name of the leap indicator type.
62       */
63      private String name;
64  
65      /**
66       * The value/code for the leap indicator type.
67       */
68      private int ordinal;
69  
70  
71      /**
72       * Private constructor prevents construction outside of this class.
73       */
74      LeapIndicatorType( int ordinal, String name )
75      {
76          this.ordinal = ordinal;
77          this.name = name;
78      }
79  
80  
81      /**
82       * Returns the leap indicator type when specified by its ordinal.
83       *
84       * @param type
85       * @return The leap indicator type.
86       */
87      public static LeapIndicatorType getTypeByOrdinal( int type )
88      {
89          for ( LeapIndicatorType lit : LeapIndicatorType.values() )
90          {
91              if ( type == lit.getOrdinal() )
92              {
93                  return lit;
94              }
95          }
96  
97          return NO_WARNING;
98      }
99  
100 
101     /**
102      * Returns the number associated with this leap indicator type.
103      *
104      * @return The leap indicator type ordinal.
105      */
106     public int getOrdinal()
107     {
108         return ordinal;
109     }
110 
111 
112     /**
113      * {@inheritDoc}
114      */
115     @Override
116     public String toString()
117     {
118         return name;
119     }
120 }