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 * Mode: This is a three-bit integer indicating the mode, with values
31 * defined as follows:
32 *
33 * Mode Meaning
34 * ------------------------------------
35 * 0 reserved
36 * 1 symmetric active
37 * 2 symmetric passive
38 * 3 client
39 * 4 server
40 * 5 broadcast
41 * 6 reserved for NTP control message
42 * 7 reserved for private use
43 *
44 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
45 * @version $Rev: 586763 $, $Date: 2007-10-20 19:26:29 +0200 (Sa, 20 Okt 2007) $
46 */
47 public final class ModeType implements Comparable<ModeType>
48 {
49 /**
50 * Constant for the "Reserved mode" mode type.
51 */
52 public static final ModeType RESERVED = new ModeType( 0, "Reserved mode." );
53
54 /**
55 * Constant for the "Symmetric active mode" mode type.
56 */
57 public static final ModeType SYMMETRIC_ACTIVE = new ModeType( 1, "Symmetric active mode." );
58
59 /**
60 * Constant for the "Symmetric passive mode" mode type.
61 */
62 public static final ModeType RESERVED_PASSIVE = new ModeType( 2, "Symmetric passive mode." );
63
64 /**
65 * Constant for the "Client mode" mode type.
66 */
67 public static final ModeType CLIENT = new ModeType( 3, "Client mode." );
68
69 /**
70 * Constant for the "Server mode" mode type.
71 */
72 public static final ModeType SERVER = new ModeType( 4, "Server mode." );
73
74 /**
75 * Constant for the "Broadcast mode" mode type.
76 */
77 public static final ModeType BROADCAST = new ModeType( 5, "Broadcast mode." );
78
79 /**
80 * Constant for the "Reserved for NTP control message" mode type.
81 */
82 public static final ModeType RESERVED_FOR_NTP_CONTROL = new ModeType( 6, "Reserved for NTP control message." );
83
84 /**
85 * Constant for the "Reserved for private use" mode type.
86 */
87 public static final ModeType RESERVED_FOR_PRIVATE_USE = new ModeType( 7, "Reserved for private use." );
88
89 /**
90 * Array for building a List of VALUES.
91 */
92 private static final ModeType[] values =
93 { RESERVED, SYMMETRIC_ACTIVE, RESERVED_PASSIVE, CLIENT, SERVER, BROADCAST, RESERVED_FOR_NTP_CONTROL,
94 RESERVED_FOR_PRIVATE_USE };
95
96 /**
97 * A list of all the mode type constants.
98 */
99 public static final List<ModeType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
100
101 /**
102 * The name of the mode type.
103 */
104 private final String name;
105
106 /**
107 * The value/code for the mode type.
108 */
109 private final int ordinal;
110
111
112 /**
113 * Private constructor prevents construction outside of this class.
114 */
115 private ModeType( int ordinal, String name )
116 {
117 this.ordinal = ordinal;
118 this.name = name;
119 }
120
121
122 /**
123 * Returns the mode type when specified by its ordinal.
124 *
125 * @param type
126 * @return The mode type.
127 */
128 public static ModeType getTypeByOrdinal( int type )
129 {
130 for ( int ii = 0; ii < values.length; ii++ )
131 {
132 if ( values[ii].ordinal == type )
133 {
134 return values[ii];
135 }
136 }
137 return SERVER;
138 }
139
140
141 /**
142 * Returns the number associated with this mode type.
143 *
144 * @return The mode type ordinal.
145 */
146 public int getOrdinal()
147 {
148 return ordinal;
149 }
150
151
152 public int compareTo( ModeType that )
153 {
154 return ordinal - that.ordinal;
155 }
156
157
158 public String toString()
159 {
160 return name;
161 }
162 }