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 021 package org.apache.directory.server.ntp.messages; 022 023 024 import java.util.Arrays; 025 import java.util.Collections; 026 import java.util.List; 027 028 029 /** 030 * Mode: This is a three-bit integer indicating the mode, with values 031 * defined as follows: 032 * 033 * Mode Meaning 034 * ------------------------------------ 035 * 0 reserved 036 * 1 symmetric active 037 * 2 symmetric passive 038 * 3 client 039 * 4 server 040 * 5 broadcast 041 * 6 reserved for NTP control message 042 * 7 reserved for private use 043 * 044 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 045 * @version $Rev: 586763 $, $Date: 2007-10-20 19:26:29 +0200 (Sat, 20 Oct 2007) $ 046 */ 047 public final class ModeType implements Comparable<ModeType> 048 { 049 /** 050 * Constant for the "Reserved mode" mode type. 051 */ 052 public static final ModeType RESERVED = new ModeType( 0, "Reserved mode." ); 053 054 /** 055 * Constant for the "Symmetric active mode" mode type. 056 */ 057 public static final ModeType SYMMETRIC_ACTIVE = new ModeType( 1, "Symmetric active mode." ); 058 059 /** 060 * Constant for the "Symmetric passive mode" mode type. 061 */ 062 public static final ModeType RESERVED_PASSIVE = new ModeType( 2, "Symmetric passive mode." ); 063 064 /** 065 * Constant for the "Client mode" mode type. 066 */ 067 public static final ModeType CLIENT = new ModeType( 3, "Client mode." ); 068 069 /** 070 * Constant for the "Server mode" mode type. 071 */ 072 public static final ModeType SERVER = new ModeType( 4, "Server mode." ); 073 074 /** 075 * Constant for the "Broadcast mode" mode type. 076 */ 077 public static final ModeType BROADCAST = new ModeType( 5, "Broadcast mode." ); 078 079 /** 080 * Constant for the "Reserved for NTP control message" mode type. 081 */ 082 public static final ModeType RESERVED_FOR_NTP_CONTROL = new ModeType( 6, "Reserved for NTP control message." ); 083 084 /** 085 * Constant for the "Reserved for private use" mode type. 086 */ 087 public static final ModeType RESERVED_FOR_PRIVATE_USE = new ModeType( 7, "Reserved for private use." ); 088 089 /** 090 * Array for building a List of VALUES. 091 */ 092 private static final ModeType[] values = 093 { RESERVED, SYMMETRIC_ACTIVE, RESERVED_PASSIVE, CLIENT, SERVER, BROADCAST, RESERVED_FOR_NTP_CONTROL, 094 RESERVED_FOR_PRIVATE_USE }; 095 096 /** 097 * A list of all the mode type constants. 098 */ 099 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 }