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 * Stratum: This is a eight-bit unsigned integer indicating the stratum
026 * level of the local clock, with values defined as follows:
027 *
028 *    Stratum  Meaning
029 *    ----------------------------------------------
030 *    0        unspecified or unavailable
031 *    1        primary reference (e.g., radio clock)
032 *    2-15     secondary reference (via NTP or SNTP)
033 *    16-255   reserved
034 * 
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 */
037public enum StratumType
038{
039    /**
040     * Constant for the "Unspecified or unavailable" stratum type.
041     */
042    UNSPECIFIED(0, "Unspecified or unavailable."),
043
044    /**
045     * Constant for the "Primary reference" stratum type.
046     */
047    PRIMARY_REFERENCE(1, "Primary reference."),
048
049    /**
050     * Constant for the "Secondary reference" stratum type.
051     */
052    SECONDARY_REFERENCE(2, "Secondary reference.");
053
054    /**
055     * The name of the stratum type.
056     */
057    private String name;
058
059    /**
060     * The value/code for the stratum type.
061     */
062    private int ordinal;
063
064
065    /**
066     * Private constructor prevents construction outside of this class.
067     */
068    StratumType( int ordinal, String name )
069    {
070        this.ordinal = ordinal;
071        this.name = name;
072    }
073
074
075    /**
076     * Returns the stratum type when specified by its ordinal.
077     *
078     * @param type
079     * @return The stratum type.
080     */
081    public static StratumType getTypeByOrdinal( int type )
082    {
083        for ( StratumType st : StratumType.values() )
084        {
085            if ( type == st.getOrdinal() )
086            {
087                return st;
088            }
089        }
090
091        return UNSPECIFIED;
092    }
093
094
095    /**
096     * Returns the number associated with this stratum type.
097     *
098     * @return The stratum type ordinal.
099     */
100    public int getOrdinal()
101    {
102        return ordinal;
103    }
104
105
106    /**
107     * {@inheritDoc}
108     */
109    @Override
110    public String toString()
111    {
112        return name;
113    }
114}