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  import java.util.Arrays;
25  import java.util.Collections;
26  import java.util.List;
27  
28  
29  /**
30   * Reference Identifier: This is a 32-bit bitstring identifying the
31   * particular reference source. In the case of NTP Version 3 or Version
32   * 4 stratum-0 (unspecified) or stratum-1 (primary) servers, this is a
33   * four-character ASCII string, left justified and zero padded to 32
34   * bits. In NTP Version 3 secondary servers, this is the 32-bit IPv4
35   * address of the reference source. In NTP Version 4 secondary servers,
36   * this is the low order 32 bits of the latest transmit timestamp of the
37   * reference source. NTP primary (stratum 1) servers should set this
38   * field to a code identifying the external reference source according
39   * to the following list. If the external reference is one of those
40   * listed, the associated code should be used. Codes for sources not
41   * listed can be contrived as appropriate.
42   * 
43   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
44   */
45  public final class ReferenceIdentifier implements Comparable<ReferenceIdentifier>
46  {
47      /**
48       * Constant for the "INIT" reference identifier type.
49       */
50      public static final ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier INIT = new ReferenceIdentifier( 0, "INIT", "initializing" );
51  
52      /**
53       * Constant for the "LOCL" reference identifier type.
54       */
55      public static final ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier LOCL = new ReferenceIdentifier( 1, "LOCL", "uncalibrated local clock" );
56  
57      /**
58       * Constant for the "PPL" reference identifier type.
59       */
60      public static final ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier PPS = new ReferenceIdentifier( 2, "PPL", "pulse-per-second source" );
61  
62      /**
63       * Constant for the "ACTS" reference identifier type.
64       */
65      public static final ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier ACTS = new ReferenceIdentifier( 3, "ACTS", "NIST dialup modem service" );
66  
67      /**
68       * Constant for the "USNO" reference identifier type.
69       */
70      public static final ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier USNO = new ReferenceIdentifier( 4, "USNO", "USNO modem service" );
71  
72      /**
73       * Constant for the "PTB" reference identifier type.
74       */
75      public static final ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier PTB = new ReferenceIdentifier( 5, "PTB", "PTB (Germany) modem service" );
76  
77      /**
78       * Constant for the "TDF" reference identifier type.
79       */
80      public static final ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier TDF = new ReferenceIdentifier( 6, "TDF", "Allouis (France) Radio 164 kHz" );
81  
82      /**
83       * Constant for the "DCF" reference identifier type.
84       */
85      public static final ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier DCF = new ReferenceIdentifier( 7, "DCF",
86          "Mainflingen (Germany) Radio 77.5 kHz" );
87  
88      /**
89       * Constant for the "MSF" reference identifier type.
90       */
91      public static final ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier MSF = new ReferenceIdentifier( 8, "MSF", "Rugby (UK) Radio 60 kHz" );
92  
93      /**
94       * Constant for the "WWV" reference identifier type.
95       */
96      public static final ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier WWV = new ReferenceIdentifier( 9, "WWV",
97          "Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz" );
98  
99      /**
100      * Constant for the "WWVB" reference identifier type.
101      */
102     public static final ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">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 ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">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 ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">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 ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">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 ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier OMEG = new ReferenceIdentifier( 14, "OMEG", "OMEGA radionavigation system" );
126 
127     /**
128      * Constant for the "GPS" reference identifier type.
129      */
130     public static final ReferenceIdentifiermessages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier GPS = new ReferenceIdentifier( 15, "GPS", "Global Positioning Service" );
131 
132     /**
133      * Constant for the "GOES" reference identifier type.
134      */
135     public static final ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">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 ReferenceIdentifieressages/ReferenceIdentifier.html#ReferenceIdentifier">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../org/apache/directory/server/ntp/messages/ReferenceIdentifier.html#ReferenceIdentifier">ReferenceIdentifier thatRef = ( ReferenceIdentifier ) that;
278 
279         return ordinal == thatRef.ordinal;
280     }
281 
282 
283     public String toString()
284     {
285         return name;
286     }
287 }