Add method to parse a priority from a string.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 18 Mar 2012 01:13:12 +0000 (02:13 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 18 Mar 2012 01:13:12 +0000 (02:13 +0100)
src/de/todesbaum/util/freenet/fcp2/PriorityClass.java

index d9af597..729acc1 100644 (file)
@@ -89,4 +89,25 @@ public final class PriorityClass {
                return value;
        }
 
+       //
+       // STATIC METHODS
+       //
+
+       /**
+        * Returns the priority class with the given name, matched case-insensitive.
+        *
+        * @param value
+        *            The name of the priority
+        * @return The priority with the given name, or {@code null} if no priority
+        *         matches the given name
+        */
+       public static PriorityClass valueOf(String value) {
+               for (PriorityClass priorityClass : new PriorityClass[] { MINIMUM, PREFETCH, BULK, UPDATABLE, SEMI_INTERACTIVE, INTERACTIVE, MAXIMUM }) {
+                       if (priorityClass.getName().equalsIgnoreCase(value)) {
+                               return priorityClass;
+                       }
+               }
+               return null;
+       }
+
 }