2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep;
10 import static com.google.common.base.Verify.verify;
12 import java.util.Arrays;
14 public enum TerminationReason {
18 TOO_MANY_UNKNWN_REQS(4),
19 TOO_MANY_UNKNOWN_MSGS(5);
21 private static final TerminationReason[] REASONS;
24 // We are not making many assumptions here
25 final TerminationReason[] reasons = TerminationReason.values();
26 verify(reasons.length > 0);
28 final short highest = Arrays.stream(reasons).map(TerminationReason::getShortValue).max(Short::compareTo).get();
29 final TerminationReason[] init = new TerminationReason[highest + 1];
30 for (TerminationReason reason : reasons) {
31 init[reason.getShortValue()] = reason;
39 TerminationReason(final int value) {
40 this.value = (short) value;
44 * Gets value of termination reason.
48 public short getShortValue() {
53 * Gets termination reason for specific short value.
55 * @param valueArg corresponding to Termination reason
56 * @return corresponding TerminationReason item
58 public static TerminationReason forValue(final short valueArg) {
59 return valueArg < 0 || valueArg >= REASONS.length ? null : REASONS[valueArg];