Merge "Speed up enumeration lookups"
authorTom Pantelis <tpanteli@brocade.com>
Thu, 2 Apr 2015 11:30:14 +0000 (11:30 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 2 Apr 2015 11:30:15 +0000 (11:30 +0000)
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java

index a7effbcf3792346b6521fec14b599dc1bfa0194b..667b64ce18839386f0c9ce44375bd7f88649588a 100644 (file)
@@ -73,15 +73,14 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         WRITE_ONLY,
         READ_WRITE;
 
-        public static TransactionType fromInt(int type) {
-            if(type == WRITE_ONLY.ordinal()) {
-                return WRITE_ONLY;
-            } else if(type == READ_WRITE.ordinal()) {
-                return READ_WRITE;
-            } else if(type == READ_ONLY.ordinal()) {
-                return READ_ONLY;
-            } else {
-                throw new IllegalArgumentException("In TransactionType enum value" + type);
+        // Cache all values
+        private static final TransactionType[] VALUES = values();
+
+        public static TransactionType fromInt(final int type) {
+            try {
+                return VALUES[type];
+            } catch (IndexOutOfBoundsException e) {
+                throw new IllegalArgumentException("In TransactionType enum value " + type, e);
             }
         }
     }