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 024import java.util.Arrays; 025import java.util.Collections; 026import java.util.List; 027 028 029/** 030 * Reference Identifier: This is a 32-bit bitstring identifying the 031 * particular reference source. In the case of NTP Version 3 or Version 032 * 4 stratum-0 (unspecified) or stratum-1 (primary) servers, this is a 033 * four-character ASCII string, left justified and zero padded to 32 034 * bits. In NTP Version 3 secondary servers, this is the 32-bit IPv4 035 * address of the reference source. In NTP Version 4 secondary servers, 036 * this is the low order 32 bits of the latest transmit timestamp of the 037 * reference source. NTP primary (stratum 1) servers should set this 038 * field to a code identifying the external reference source according 039 * to the following list. If the external reference is one of those 040 * listed, the associated code should be used. Codes for sources not 041 * listed can be contrived as appropriate. 042 * 043 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 044 */ 045public final class ReferenceIdentifier implements Comparable<ReferenceIdentifier> 046{ 047 /** 048 * Constant for the "INIT" reference identifier type. 049 */ 050 public static final ReferenceIdentifier INIT = new ReferenceIdentifier( 0, "INIT", "initializing" ); 051 052 /** 053 * Constant for the "LOCL" reference identifier type. 054 */ 055 public static final ReferenceIdentifier LOCL = new ReferenceIdentifier( 1, "LOCL", "uncalibrated local clock" ); 056 057 /** 058 * Constant for the "PPL" reference identifier type. 059 */ 060 public static final ReferenceIdentifier PPS = new ReferenceIdentifier( 2, "PPL", "pulse-per-second source" ); 061 062 /** 063 * Constant for the "ACTS" reference identifier type. 064 */ 065 public static final ReferenceIdentifier ACTS = new ReferenceIdentifier( 3, "ACTS", "NIST dialup modem service" ); 066 067 /** 068 * Constant for the "USNO" reference identifier type. 069 */ 070 public static final ReferenceIdentifier USNO = new ReferenceIdentifier( 4, "USNO", "USNO modem service" ); 071 072 /** 073 * Constant for the "PTB" reference identifier type. 074 */ 075 public static final ReferenceIdentifier PTB = new ReferenceIdentifier( 5, "PTB", "PTB (Germany) modem service" ); 076 077 /** 078 * Constant for the "TDF" reference identifier type. 079 */ 080 public static final ReferenceIdentifier TDF = new ReferenceIdentifier( 6, "TDF", "Allouis (France) Radio 164 kHz" ); 081 082 /** 083 * Constant for the "DCF" reference identifier type. 084 */ 085 public static final ReferenceIdentifier DCF = new ReferenceIdentifier( 7, "DCF", 086 "Mainflingen (Germany) Radio 77.5 kHz" ); 087 088 /** 089 * Constant for the "MSF" reference identifier type. 090 */ 091 public static final ReferenceIdentifier MSF = new ReferenceIdentifier( 8, "MSF", "Rugby (UK) Radio 60 kHz" ); 092 093 /** 094 * Constant for the "WWV" reference identifier type. 095 */ 096 public static final ReferenceIdentifier WWV = new ReferenceIdentifier( 9, "WWV", 097 "Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz" ); 098 099 /** 100 * Constant for the "WWVB" reference identifier type. 101 */ 102 public static final ReferenceIdentifier WWVB = new ReferenceIdentifier( 10, "WWVB", "Boulder (US) Radio 60 kHz" ); 103 104 /** 105 * Constant for the "WWVH" reference identifier type. 106 */ 107 public static final ReferenceIdentifier WWVH = new ReferenceIdentifier( 11, "WWVH", 108 "Kaui Hawaii (US) Radio 2.5, 5, 10, 15 MHz" ); 109 110 /** 111 * Constant for the "CHU" reference identifier type. 112 */ 113 public static final ReferenceIdentifier CHU = new ReferenceIdentifier( 12, "CHU", 114 "Ottawa (Canada) Radio 3330, 7335, 14670 kHz" ); 115 116 /** 117 * Constant for the "LORC" reference identifier type. 118 */ 119 public static final ReferenceIdentifier LORC = new ReferenceIdentifier( 13, "LORC", 120 "LORAN-C radionavigation system" ); 121 122 /** 123 * Constant for the "OMEG" reference identifier type. 124 */ 125 public static final ReferenceIdentifier OMEG = new ReferenceIdentifier( 14, "OMEG", "OMEGA radionavigation system" ); 126 127 /** 128 * Constant for the "GPS" reference identifier type. 129 */ 130 public static final ReferenceIdentifier GPS = new ReferenceIdentifier( 15, "GPS", "Global Positioning Service" ); 131 132 /** 133 * Constant for the "GOES" reference identifier type. 134 */ 135 public static final ReferenceIdentifier GOES = new ReferenceIdentifier( 16, "GOES", 136 "Geostationary Orbit Environment Satellite" ); 137 138 /** 139 * Constant for the "CDMA" reference identifier type. 140 */ 141 public static final ReferenceIdentifier CDMA = new ReferenceIdentifier( 17, "CDMA", 142 "CDMA mobile cellular/PCS telephone system" ); 143 144 /** 145 * Array for building a List of VALUES. 146 */ 147 private static final ReferenceIdentifier[] VALUES_ARRAY = 148 { INIT, LOCL, PPS, ACTS, USNO, PTB, TDF, DCF, MSF, WWV, WWVB, WWVH, CHU, LORC, OMEG, GPS, GOES, CDMA }; 149 150 /** 151 * A list of all the reference identifier type constants. 152 */ 153 public static final List<ReferenceIdentifier> VALUES = Collections.unmodifiableList( Arrays.asList( VALUES_ARRAY ) ); 154 155 /** 156 * The value/code for the reference identifier type. 157 */ 158 private final int ordinal; 159 160 /** 161 * The name of the reference identifier type. 162 */ 163 private final String name; 164 165 /** 166 * The code of the reference identifier type. 167 */ 168 private final String code; 169 170 171 /** 172 * Private constructor prevents construction outside of this class. 173 */ 174 private ReferenceIdentifier( int ordinal, String code, String name ) 175 { 176 this.ordinal = ordinal; 177 this.code = code; 178 this.name = name; 179 } 180 181 182 /** 183 * Returns the reference identifier type when specified by its ordinal. 184 * 185 * @param type 186 * @return The reference identifier type. 187 */ 188 public static ReferenceIdentifier getTypeByOrdinal( int type ) 189 { 190 for ( int ii = 0; ii < VALUES_ARRAY.length; ii++ ) 191 { 192 if ( VALUES_ARRAY[ii].ordinal == type ) 193 { 194 return VALUES_ARRAY[ii]; 195 } 196 } 197 198 return LOCL; 199 } 200 201 202 /** 203 * Returns the reference identifier type when specified by its name. 204 * 205 * @param type 206 * @return The reference identifier type. 207 */ 208 public static ReferenceIdentifier getTypeByName( String type ) 209 { 210 for ( int ii = 0; ii < VALUES_ARRAY.length; ii++ ) 211 { 212 if ( VALUES_ARRAY[ii].code.equalsIgnoreCase( type ) ) 213 { 214 return VALUES_ARRAY[ii]; 215 } 216 } 217 218 return LOCL; 219 } 220 221 222 /** 223 * Returns the code associated with this reference identifier type. 224 * 225 * @return The reference identifier type code. 226 */ 227 public String getCode() 228 { 229 return code; 230 } 231 232 233 /** 234 * Returns the number associated with this reference identifier type. 235 * 236 * @return The reference identifier type ordinal. 237 */ 238 public int getOrdinal() 239 { 240 return ordinal; 241 } 242 243 244 /** 245 * {@inheritDoc} 246 */ 247 public int compareTo( ReferenceIdentifier that ) 248 { 249 return ordinal - that.ordinal; 250 } 251 252 253 /** 254 * {@inheritDoc} 255 */ 256 public int hashCode() 257 { 258 return ordinal; 259 } 260 261 262 /** 263 * {@inheritDoc} 264 */ 265 public boolean equals( Object that ) 266 { 267 if ( that == this ) 268 { 269 return true; 270 } 271 272 if ( !( that instanceof ReferenceIdentifier ) ) 273 { 274 return false; 275 } 276 277 ReferenceIdentifier thatRef = ( ReferenceIdentifier ) that; 278 279 return ordinal == thatRef.ordinal; 280 } 281 282 283 public String toString() 284 { 285 return name; 286 } 287}