/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.protocol.pcep;

import com.google.common.collect.Maps;
import java.util.Map;

public enum TerminationReason {
    UNKNOWN((short) 1),
    EXP_DEADTIMER((short) 2),
    MALFORMED_MSG((short) 3),
    TOO_MANY_UNKNWN_REQS((short) 4),
    TOO_MANY_UNKNOWN_MSGS((short) 5);

    private static final Map<Short, TerminationReason> VALUE_MAP;

    static {
        VALUE_MAP = Maps.newHashMap();
        for (final TerminationReason enumItem : TerminationReason.values()) {
            VALUE_MAP.put(enumItem.value, enumItem);
        }
    }

    private short value;

    TerminationReason(final short value) {
        this.value = value;
    }

    /**
     * Gets termination reason for specific short value.
     *
     * @param valueArg corresponding to Termination reason
     * @return corresponding TerminationReason item
     */
    public static TerminationReason forValue(final short valueArg) {
        return VALUE_MAP.get(valueArg);
    }

    /**
     * Gets value of termination reason.
     *
     * @return short value
     */
    public short getShortValue() {
        return this.value;
    }
}

@@ -349,16 +349,23 @@
 %0Aimport 
+static 
 com.goog
@@ -378,21 +378,28 @@
 mon.
-collect.Maps;
+base.Verify.verify;%0A
 %0Aimp
@@ -412,19 +412,22 @@
 va.util.
-Map
+Arrays
 ;%0A%0Apubli
@@ -465,24 +465,16 @@
 UNKNOWN(
-(short) 
 1),%0A    
@@ -487,24 +487,16 @@
 ADTIMER(
-(short) 
 2),%0A    
@@ -509,24 +509,16 @@
 MED_MSG(
-(short) 
 3),%0A    
@@ -538,24 +538,16 @@
 WN_REQS(
-(short) 
 4),%0A    
@@ -572,16 +572,8 @@
 SGS(
-(short) 
 5);%0A
@@ -601,19 +601,8 @@
 inal
- Map%3CShort,
  Ter
@@ -619,19 +619,18 @@
 ason
-%3E VALUE_MAP
+%5B%5D REASONS
 ;%0A%0A 
@@ -653,38 +653,50 @@
     
-VALUE_MAP = Maps.newHashMap();
+// We are not making many assumptions here
 %0A   
@@ -704,13 +704,8 @@
     
-for (
 fina
@@ -727,19 +727,20 @@
 ason
- enumItem :
+%5B%5D reasons =
  Ter
@@ -766,74 +766,380 @@
 es()
-) %7B%0A            VALUE_MAP.put(enumItem.value, enumItem);%0A        %7D
+;%0A        verify(reasons.length %3E 0);%0A%0A        final short highest = Arrays.stream(reasons).map(TerminationReason::getShortValue).max(Short::compareTo).get();%0A        final TerminationReason%5B%5D init = new TerminationReason%5Bhighest + 1%5D;%0A        for (TerminationReason reason : reasons) %7B%0A            init%5Breason.getShortValue()%5D = reason;%0A        %7D%0A%0A        REASONS = init;
 %0A   
@@ -1200,43 +1200,204 @@
 nal 
+int value) %7B%0A        this.value = (
 short
+)
  value
-) %7B%0A        this.value =
+;%0A    %7D%0A%0A    /**%0A     * Gets value of termination reason.%0A     *%0A     * @return short value%0A     */%0A    public short getShortValue() %7B%0A        return
  val
@@ -1686,191 +1686,77 @@
 urn 
-VALUE_MAP.get(valueArg);%0A    %7D%0A%0A    /**%0A     * Gets value of termination reason.%0A     *%0A     * @return short value%0A     */%0A    public short getShortValue() %7B%0A        return this.value
+valueArg %3C 0 %7C%7C valueArg %3E= REASONS.length ? null : REASONS%5BvalueArg%5D
 ;%0A  

Optimize TerminationReason memory usage and performance