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 * Stratum: This is a eight-bit unsigned integer indicating the stratum 31 * level of the local clock, with values defined as follows: 32 * 33 * Stratum Meaning 34 * ---------------------------------------------- 35 * 0 unspecified or unavailable 36 * 1 primary reference (e.g., radio clock) 37 * 2-15 secondary reference (via NTP or SNTP) 38 * 16-255 reserved 39 * 40 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 41 * @version $Rev: 586763 $, $Date: 2007-10-20 19:26:29 +0200 (Sa, 20 Okt 2007) $ 42 */ 43 public final class StratumType implements Comparable<StratumType> 44 { 45 /** 46 * Constant for the "Unspecified or unavailable" stratum type. 47 */ 48 public static final StratumType UNSPECIFIED = new StratumType( 0, "Unspecified or unavailable." ); 49 50 /** 51 * Constant for the "Primary reference" stratum type. 52 */ 53 public static final StratumType PRIMARY_REFERENCE = new StratumType( 1, "Primary reference." ); 54 55 /** 56 * Constant for the "Secondary reference" stratum type. 57 */ 58 public static final StratumType SECONDARY_REFERENCE = new StratumType( 2, "Secondary reference." ); 59 60 /** 61 * Array for building a List of VALUES. 62 */ 63 private static final StratumType[] values = 64 { UNSPECIFIED, PRIMARY_REFERENCE, SECONDARY_REFERENCE }; 65 66 /** 67 * A list of all the stratum type constants. 68 */ 69 public static final List<StratumType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) ); 70 71 /** 72 * The name of the stratum type. 73 */ 74 private final String name; 75 76 /** 77 * The value/code for the stratum type. 78 */ 79 private final int ordinal; 80 81 82 /** 83 * Private constructor prevents construction outside of this class. 84 */ 85 private StratumType( int ordinal, String name ) 86 { 87 this.ordinal = ordinal; 88 this.name = name; 89 } 90 91 92 /** 93 * Returns the stratum type when specified by its ordinal. 94 * 95 * @param type 96 * @return The stratum type. 97 */ 98 public static StratumType getTypeByOrdinal( int type ) 99 { 100 for ( int ii = 0; ii < values.length; ii++ ) 101 { 102 if ( values[ii].ordinal == type ) 103 { 104 return values[ii]; 105 } 106 } 107 108 return UNSPECIFIED; 109 } 110 111 112 /** 113 * Returns the number associated with this stratum type. 114 * 115 * @return The stratum type ordinal. 116 */ 117 public int getOrdinal() 118 { 119 return ordinal; 120 } 121 122 123 public int compareTo( StratumType that ) 124 { 125 return ordinal - that.ordinal; 126 } 127 128 129 public String toString() 130 { 131 return name; 132 } 133 }