commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1086037 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/imap/IMAP.java main/java/org/apache/commons/net/imap/IMAPCommand.java
Date Sun, 27 Mar 2011 20:58:48 GMT
Author: sebb
Date: Sun Mar 27 20:58:48 2011
New Revision: 1086037

URL: http://svn.apache.org/viewvc?rev=1086037&view=rev
Log:
NET-392 Use enum for IMAPCommand

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1086037&r1=1086036&r2=1086037&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Sun Mar 27 20:58:48 2011
@@ -57,6 +57,9 @@ The <action> type attribute can be add,u
 
     <body>
         <release version="3.0" date="TBA" description="TBA">
+            <action issue="NET-392" dev="sebb" type="update">
+            Use enum for IMAPCommand.
+            </action>
             <action issue="NET-333" dev="sebb" type="add" due-to="Bogdan Drozdowski" due-to-email="bogdandr
# op . pl">
             would you provide a class used for imap protocol?
             </action>

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java?rev=1086037&r1=1086036&r2=1086037&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java Sun Mar 27
20:58:48 2011
@@ -273,7 +273,7 @@ public class IMAP extends SocketClient
      * @param args     The command arguments.
      * @return  The server reply code (see IMAPReply).
      */
-    public int sendCommandWithID(String commandID, int command, String args) throws IOException
+    public int sendCommandWithID(String commandID, IMAPCommand command, String args) throws
IOException
     {
         return sendCommandWithID(commandID, IMAPCommand.getCommand(command), args);
     }
@@ -287,7 +287,7 @@ public class IMAP extends SocketClient
      *                  (one of the IMAPCommand constants).
      * @return  The server reply code (see IMAPReply).
     **/
-    public int sendCommandWithID(String commandID, int command) throws IOException
+    public int sendCommandWithID(String commandID, IMAPCommand command) throws IOException
     {
         return sendCommandWithID(commandID, command, null);
     }
@@ -324,7 +324,7 @@ public class IMAP extends SocketClient
      * @param args     The command arguments.
      * @return  The server reply code (see IMAPReply).
      */
-    public int sendCommand(int command, String args) throws IOException
+    public int sendCommand(IMAPCommand command, String args) throws IOException
     {
         return sendCommandWithID(generateCommandID(), IMAPCommand.getCommand(command), args);
     }
@@ -337,7 +337,7 @@ public class IMAP extends SocketClient
      * @param args     The command arguments.
      * @return  {@code true} if the command was successful
      */
-    public boolean doCommand(int command, String args) throws IOException
+    public boolean doCommand(IMAPCommand command, String args) throws IOException
     {
         return IMAPReply.isSuccess(sendCommand(command, args));
     }
@@ -350,7 +350,7 @@ public class IMAP extends SocketClient
      *                  (one of the IMAPCommand constants).
      * @return  The server reply code (see IMAPReply).
     **/
-    public int sendCommand(int command) throws IOException
+    public int sendCommand(IMAPCommand command) throws IOException
     {
         return sendCommand(command, null);
     }
@@ -362,7 +362,7 @@ public class IMAP extends SocketClient
      *                  (one of the IMAPCommand constants).
      * @return  {@code true} if the command was successful
      */
-    public boolean doCommand(int command) throws IOException
+    public boolean doCommand(IMAPCommand command) throws IOException
     {
         return IMAPReply.isSuccess(sendCommand(command));
     }
@@ -399,7 +399,7 @@ public class IMAP extends SocketClient
      * @param args     The command arguments.
      * @return  The server reply code (see IMAPReply).
      */
-    public int sendUntaggedCommand(int command, String args) throws IOException
+    public int sendUntaggedCommand(IMAPCommand command, String args) throws IOException
     {
         return sendCommandWithID(null, IMAPCommand.getCommand(command), args);
     }
@@ -412,7 +412,7 @@ public class IMAP extends SocketClient
      *                  (one of the IMAPCommand constants).
      * @return  The server reply code (see IMAPReply).
     **/
-    public int sendUntaggedCommand(int command) throws IOException
+    public int sendUntaggedCommand(IMAPCommand command) throws IOException
     {
         return sendCommandWithID(null, IMAPCommand.getCommand(command), null);
     }

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java?rev=1086037&r1=1086036&r2=1086037&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java Sun
Mar 27 20:58:48 2011
@@ -18,103 +18,57 @@
 package org.apache.commons.net.imap;
 
 /**
- * IMAPCommand stores IMAP command code constants.
+ * IMAPCommand stores IMAP command codes.
  */
-public class IMAPCommand
+public enum IMAPCommand
 {
-    /** The  command. */
-    public static final int CAPABILITY = 0;
-    /** The  command. */
-    public static final int NOOP = 1;
-    /** The  command. */
-    public static final int LOGOUT = 2;
-    /** The  command. */
-    public static final int STARTTLS = 3;
-    /** The  command. */
-    public static final int AUTHENTICATE = 4;
-    /** The  command. */
-    public static final int LOGIN = 5;
-    /** The  command. */
-    public static final int SELECT = 6;
-    /** The  command. */
-    public static final int EXAMINE = 7;
-    /** The  command. */
-    public static final int CREATE = 8;
-    /** The  command. */
-    public static final int DELETE = 9;
-    /** The  command. */
-    public static final int RENAME = 10;
-    /** The  command. */
-    public static final int SUBSCRIBE = 11;
-    /** The  command. */
-    public static final int UNSUBSCRIBE = 12;
-    /** The  command. */
-    public static final int LIST = 13;
-    /** The  command. */
-    public static final int LSUB = 14;
-    /** The  command. */
-    public static final int STATUS = 15;
-    /** The  command. */
-    public static final int APPEND = 16;
-    /** The  command. */
-    public static final int CHECK = 17;
-    /** The  command. */
-    public static final int CLOSE = 18;
-    /** The  command. */
-    public static final int EXPUNGE = 19;
-    /** The  command. */
-    public static final int SEARCH = 20;
-    /** The  command. */
-    public static final int FETCH = 21;
-    /** The  command. */
-    public static final int STORE = 22;
-    /** The  command. */
-    public static final int COPY = 23;
-    /** The  command. */
-    public static final int UID = 24;
-
-
-
-    private static final String[] _commands = {
-                                          "CAPABILITY",
-                                          "NOOP",
-                                          "LOGOUT",
-                                          "STARTTLS",
-                                          "AUTHENTICATE",
-                                          "LOGIN",
-                                          "SELECT",
-                                          "EXAMINE",
-                                          "CREATE",
-                                          "DELETE",
-                                          "RENAME",
-                                          "SUBSCRIBE",
-                                          "UNSUBSCRIBE",
-                                          "LIST",
-                                          "LSUB",
-                                          "STATUS",
-                                          "APPEND",
-                                          "CHECK",
-                                          "CLOSE",
-                                          "EXPUNGE",
-                                          "SEARCH",
-                                          "FETCH",
-                                          "STORE",
-                                          "COPY",
-                                          "UID",
-                                      };
-
-    // Cannot be instantiated.
-    private IMAPCommand()
-    {}
+    // These enums must either use the same name as the IMAP command
+    // or must provide the correct string as the parameter.
+    CAPABILITY,
+    NOOP,
+    LOGOUT,
+    STARTTLS,
+    AUTHENTICATE,
+    LOGIN,
+    SELECT,
+    EXAMINE,
+    CREATE,
+    DELETE,
+    RENAME,
+    SUBSCRIBE,
+    UNSUBSCRIBE,
+    LIST,
+    LSUB,
+    STATUS,
+    APPEND,
+    CHECK,
+    CLOSE,
+    EXPUNGE,
+    SEARCH,
+    FETCH,
+    STORE,
+    COPY,
+    UID,
+    ;
+    
+    private final String imapCommand;
 
+    IMAPCommand(){
+        imapCommand = name();
+    }
+    
+    IMAPCommand(String name){
+        imapCommand = name;
+    }
+    
     /**
      * Get the IMAP protocol string command corresponding to a command code.
-     * <p>
+     *
+     * @param command the IMAPCommand whose command string is required.
      * @return The IMAP protocol string command corresponding to a command code.
      */
-    public static final String getCommand(int command)
-    {
-        return _commands[command];
+    public static final String getCommand(IMAPCommand command) {
+        return command.imapCommand;
     }
 
 }



Mime
View raw message