directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r1037657 - in /directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages: LeapIndicatorType.java ModeType.java StratumType.java
Date Mon, 22 Nov 2010 10:14:26 GMT
Author: felixk
Date: Mon Nov 22 10:14:25 2010
New Revision: 1037657

URL: http://svn.apache.org/viewvc?rev=1037657&view=rev
Log:
Transform to enum

Modified:
    directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/LeapIndicatorType.java
    directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/ModeType.java
    directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/StratumType.java

Modified: directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/LeapIndicatorType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/LeapIndicatorType.java?rev=1037657&r1=1037656&r2=1037657&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/LeapIndicatorType.java
(original)
+++ directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/LeapIndicatorType.java
Mon Nov 22 10:14:25 2010
@@ -21,11 +21,6 @@
 package org.apache.directory.server.ntp.messages;
 
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-
 /**
  * Leap Indicator (LI): This is a two-bit code warning of an impending
  * leap second to be inserted/deleted in the last minute of the current
@@ -40,51 +35,37 @@ import java.util.List;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public final class LeapIndicatorType implements Comparable<LeapIndicatorType>
+public enum LeapIndicatorType
 {
     /**
      * Constant for the "No leap second warning" leap indicator type.
      */
-    public static final LeapIndicatorType NO_WARNING = new LeapIndicatorType( 0, "No leap
second warning." );
+    NO_WARNING(0, "No leap second warning."),
 
     /**
      * Constant for the "Last minute has 61 seconds" leap indicator type.
      */
-    public static final LeapIndicatorType POSITIVE_LEAP_SECOND = new LeapIndicatorType( 1,
-        "Last minute has 61 seconds." );
+    POSITIVE_LEAP_SECOND(1, "Last minute has 61 seconds."),
 
     /**
      * Constant for the "Last minute has 59 seconds" leap indicator type.
      */
-    public static final LeapIndicatorType NEGATIVE_LEAP_SECOND = new LeapIndicatorType( 2,
-        "Last minute has 59 seconds." );
+    NEGATIVE_LEAP_SECOND(2, "Last minute has 59 seconds."),
 
     /**
      * Constant for the "Alarm condition (clock not synchronized)" leap indicator type.
      */
-    public static final LeapIndicatorType ALARM_CONDITION = new LeapIndicatorType( 3,
-        "Alarm condition (clock not synchronized)." );
-
-    /**
-     * Array for building a List of VALUES.
-     */
-    private static final LeapIndicatorType[] values =
-        { NO_WARNING, POSITIVE_LEAP_SECOND, NEGATIVE_LEAP_SECOND, ALARM_CONDITION };
-
-    /**
-     * A list of all the leap indicator type constants.
-     */
-    public static final List<LeapIndicatorType> VALUES = Collections.unmodifiableList(
Arrays.asList( values ) );
+    ALARM_CONDITION(3, "Alarm condition (clock not synchronized).");
 
     /**
      * The name of the leap indicator type.
      */
-    private final String name;
+    private String name;
 
     /**
      * The value/code for the leap indicator type.
      */
-    private final int ordinal;
+    private int ordinal;
 
 
     /**
@@ -105,11 +86,11 @@ public final class LeapIndicatorType imp
      */
     public static LeapIndicatorType getTypeByOrdinal( int type )
     {
-        for ( int ii = 0; ii < values.length; ii++ )
+        for ( LeapIndicatorType lit : LeapIndicatorType.values() )
         {
-            if ( values[ii].ordinal == type )
+            if ( type == lit.getOrdinal() )
             {
-                return values[ii];
+                return lit;
             }
         }
 
@@ -128,12 +109,6 @@ public final class LeapIndicatorType imp
     }
 
 
-    public int compareTo( LeapIndicatorType that )
-    {
-        return ordinal - that.ordinal;
-    }
-
-
     public String toString()
     {
         return name;

Modified: directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/ModeType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/ModeType.java?rev=1037657&r1=1037656&r2=1037657&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/ModeType.java
(original)
+++ directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/ModeType.java
Mon Nov 22 10:14:25 2010
@@ -21,11 +21,6 @@
 package org.apache.directory.server.ntp.messages;
 
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-
 /**
  * Mode: This is a three-bit integer indicating the mode, with values
  * defined as follows:
@@ -43,69 +38,57 @@ import java.util.List;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public final class ModeType implements Comparable<ModeType>
+public enum ModeType
 {
     /**
      * Constant for the "Reserved mode" mode type.
      */
-    public static final ModeType RESERVED = new ModeType( 0, "Reserved mode." );
+    RESERVED(0, "Reserved mode."),
 
     /**
      * Constant for the "Symmetric active mode" mode type.
      */
-    public static final ModeType SYMMETRIC_ACTIVE = new ModeType( 1, "Symmetric active mode."
);
+    SYMMETRIC_ACTIVE(1, "Symmetric active mode."),
 
     /**
      * Constant for the "Symmetric passive mode" mode type.
      */
-    public static final ModeType RESERVED_PASSIVE = new ModeType( 2, "Symmetric passive mode."
);
+    RESERVED_PASSIVE(2, "Symmetric passive mode."),
 
     /**
      * Constant for the "Client mode" mode type.
      */
-    public static final ModeType CLIENT = new ModeType( 3, "Client mode." );
+    CLIENT(3, "Client mode."),
 
     /**
      * Constant for the "Server mode" mode type.
      */
-    public static final ModeType SERVER = new ModeType( 4, "Server mode." );
+    SERVER(4, "Server mode."),
 
     /**
      * Constant for the "Broadcast mode" mode type.
      */
-    public static final ModeType BROADCAST = new ModeType( 5, "Broadcast mode." );
+    BROADCAST(5, "Broadcast mode."),
 
     /**
      * Constant for the "Reserved for NTP control message" mode type.
      */
-    public static final ModeType RESERVED_FOR_NTP_CONTROL = new ModeType( 6, "Reserved for
NTP control message." );
+    RESERVED_FOR_NTP_CONTROL(6, "Reserved for NTP control message."),
 
     /**
      * Constant for the "Reserved for private use" mode type.
      */
-    public static final ModeType RESERVED_FOR_PRIVATE_USE = new ModeType( 7, "Reserved for
private use." );
-
-    /**
-     * Array for building a List of VALUES.
-     */
-    private static final ModeType[] values =
-        { RESERVED, SYMMETRIC_ACTIVE, RESERVED_PASSIVE, CLIENT, SERVER, BROADCAST, RESERVED_FOR_NTP_CONTROL,
-            RESERVED_FOR_PRIVATE_USE };
-
-    /**
-     * A list of all the mode type constants.
-     */
-    public static final List<ModeType> VALUES = Collections.unmodifiableList( Arrays.asList(
values ) );
+    RESERVED_FOR_PRIVATE_USE(7, "Reserved for private use.");
 
     /**
      * The name of the mode type.
      */
-    private final String name;
+    private String name;
 
     /**
      * The value/code for the mode type.
      */
-    private final int ordinal;
+    private int ordinal;
 
 
     /**
@@ -126,13 +109,14 @@ public final class ModeType implements C
      */
     public static ModeType getTypeByOrdinal( int type )
     {
-        for ( int ii = 0; ii < values.length; ii++ )
+        for ( ModeType mt : ModeType.values() )
         {
-            if ( values[ii].ordinal == type )
+            if ( type == mt.getOrdinal() )
             {
-                return values[ii];
+                return mt;
             }
         }
+
         return SERVER;
     }
 
@@ -148,12 +132,6 @@ public final class ModeType implements C
     }
 
 
-    public int compareTo( ModeType that )
-    {
-        return ordinal - that.ordinal;
-    }
-
-
     public String toString()
     {
         return name;

Modified: directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/StratumType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/StratumType.java?rev=1037657&r1=1037656&r2=1037657&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/StratumType.java
(original)
+++ directory/apacheds/trunk/protocol-ntp/src/main/java/org/apache/directory/server/ntp/messages/StratumType.java
Mon Nov 22 10:14:25 2010
@@ -21,11 +21,6 @@
 package org.apache.directory.server.ntp.messages;
 
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-
 /**
  * Stratum: This is a eight-bit unsigned integer indicating the stratum
  * level of the local clock, with values defined as follows:
@@ -39,43 +34,32 @@ import java.util.List;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public final class StratumType implements Comparable<StratumType>
+public enum StratumType
 {
     /**
      * Constant for the "Unspecified or unavailable" stratum type.
      */
-    public static final StratumType UNSPECIFIED = new StratumType( 0, "Unspecified or unavailable."
);
+    UNSPECIFIED(0, "Unspecified or unavailable."),
 
     /**
      * Constant for the "Primary reference" stratum type.
      */
-    public static final StratumType PRIMARY_REFERENCE = new StratumType( 1, "Primary reference."
);
+    PRIMARY_REFERENCE(1, "Primary reference."),
 
     /**
      * Constant for the "Secondary reference" stratum type.
      */
-    public static final StratumType SECONDARY_REFERENCE = new StratumType( 2, "Secondary
reference." );
-
-    /**
-     * Array for building a List of VALUES.
-     */
-    private static final StratumType[] values =
-        { UNSPECIFIED, PRIMARY_REFERENCE, SECONDARY_REFERENCE };
-
-    /**
-     * A list of all the stratum type constants.
-     */
-    public static final List<StratumType> VALUES = Collections.unmodifiableList( Arrays.asList(
values ) );
+    SECONDARY_REFERENCE(2, "Secondary reference.");
 
     /**
      * The name of the stratum type.
      */
-    private final String name;
+    private String name;
 
     /**
      * The value/code for the stratum type.
      */
-    private final int ordinal;
+    private int ordinal;
 
 
     /**
@@ -96,11 +80,11 @@ public final class StratumType implement
      */
     public static StratumType getTypeByOrdinal( int type )
     {
-        for ( int ii = 0; ii < values.length; ii++ )
+        for ( StratumType st : StratumType.values() )
         {
-            if ( values[ii].ordinal == type )
+            if ( type == st.getOrdinal() )
             {
-                return values[ii];
+                return st;
             }
         }
 
@@ -119,12 +103,6 @@ public final class StratumType implement
     }
 
 
-    public int compareTo( StratumType that )
-    {
-        return ordinal - that.ordinal;
-    }
-
-
     public String toString()
     {
         return name;



Mime
View raw message