Add new revision for pcep types model
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / TerminationReason.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep;
9
10 import static com.google.common.base.Verify.verify;
11
12 import java.util.Arrays;
13
14 public enum TerminationReason {
15     UNKNOWN(1),
16     EXP_DEADTIMER(2),
17     MALFORMED_MSG(3),
18     TOO_MANY_UNKNWN_REQS(4),
19     TOO_MANY_UNKNOWN_MSGS(5);
20
21     private static final TerminationReason[] REASONS;
22
23     static {
24         // We are not making many assumptions here
25         final TerminationReason[] reasons = TerminationReason.values();
26         verify(reasons.length > 0);
27
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;
32         }
33
34         REASONS = init;
35     }
36
37     private short value;
38
39     TerminationReason(final int value) {
40         this.value = (short) value;
41     }
42
43     /**
44      * Gets value of termination reason.
45      *
46      * @return short value
47      */
48     public short getShortValue() {
49         return value;
50     }
51
52     /**
53      * Gets termination reason for specific short value.
54      *
55      * @param valueArg corresponding to Termination reason
56      * @return corresponding TerminationReason item
57      */
58     public static TerminationReason forValue(final short valueArg) {
59         return valueArg < 0 || valueArg >= REASONS.length ? null : REASONS[valueArg];
60     }
61 }