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

index 667b64ce18839386f0c9ce44375bd7f88649588a,74d8e93102f3171d089a69703c994d961232635b..26523395a32f0cf2e1f06fdb46d99a5e01b71494
@@@ -73,14 -73,15 +73,14 @@@ public class TransactionProxy extends A
          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);
              }
          }
      }
                  LOG.debug("Tx {} Creating NoOpTransaction because of error", getIdentifier(), failure);
  
                  localTransactionContext = new NoOpTransactionContext(failure, getIdentifier(), operationLimiter);
-             } else if (response.getClass().equals(CreateTransactionReply.SERIALIZABLE_CLASS)) {
+             } else if (CreateTransactionReply.SERIALIZABLE_CLASS.equals(response.getClass())) {
                  localTransactionContext = createValidTransactionContext(
                          CreateTransactionReply.fromSerializable(response));
              } else {