001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020
021package org.apache.directory.server.ntp.messages;
022
023
024/**
025 * Leap Indicator (LI): This is a two-bit code warning of an impending
026 * leap second to be inserted/deleted in the last minute of the current
027 * day, with bit 0 and bit 1, respectively, coded as follows:
028 *
029 *    LI       Value     Meaning
030 *    -------------------------------------------------------
031 *    00       0         no warning
032 *    01       1         last minute has 61 seconds
033 *    10       2         last minute has 59 seconds)
034 *    11       3         alarm condition (clock not synchronized)
035 * 
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 */
038public enum LeapIndicatorType
039{
040    /**
041     * Constant for the "No leap second warning" leap indicator type.
042     */
043    NO_WARNING(0, "No leap second warning."),
044
045    /**
046     * Constant for the "Last minute has 61 seconds" leap indicator type.
047     */
048    POSITIVE_LEAP_SECOND(1, "Last minute has 61 seconds."),
049
050    /**
051     * Constant for the "Last minute has 59 seconds" leap indicator type.
052     */
053    NEGATIVE_LEAP_SECOND(2, "Last minute has 59 seconds."),
054
055    /**
056     * Constant for the "Alarm condition (clock not synchronized)" leap indicator type.
057     */
058    ALARM_CONDITION(3, "Alarm condition (clock not synchronized).");
059
060    /**
061     * The name of the leap indicator type.
062     */
063    private String name;
064
065    /**
066     * The value/code for the leap indicator type.
067     */
068    private int ordinal;
069
070
071    /**
072     * Private constructor prevents construction outside of this class.
073     */
074    LeapIndicatorType( int ordinal, String name )
075    {
076        this.ordinal = ordinal;
077        this.name = name;
078    }
079
080
081    /**
082     * Returns the leap indicator type when specified by its ordinal.
083     *
084     * @param type
085     * @return The leap indicator type.
086     */
087    public static LeapIndicatorType getTypeByOrdinal( int type )
088    {
089        for ( LeapIndicatorType lit : LeapIndicatorType.values() )
090        {
091            if ( type == lit.getOrdinal() )
092            {
093                return lit;
094            }
095        }
096
097        return NO_WARNING;
098    }
099
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}