View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2007, 2014 Massimiliano Ziccardi
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *******************************************************************************/
16  package it.jnrpe.net;
17  
18  /**
19   * Enumeration of all the supported packet versions.
20   *
21   * @author Massimiliano Ziccardi
22   */
23  public enum PacketVersion {
24      /**
25       * Packet version 1: no longer supported.
26       */
27      VERSION_1(1),
28      /**
29       * Packet version 2.
30       */
31      VERSION_2(2);
32  
33      /**
34       * The enumeration int value.
35       */
36      private final int intValue;
37  
38      /**
39       * Builds an enumeration with the given int value.
40       *
41       * @param value
42       *            The value
43       */
44      PacketVersion(final int value) {
45          intValue = value;
46      }
47  
48      /**
49       * Returns the int value of the enum.
50       *
51       * @return The int value
52       */
53      public int intValue() {
54          return intValue;
55      }
56  
57      /**
58       * Returns the enum corresponding with the given int value.
59       *
60       * @param value
61       *            The int value to be converted
62       * @return A {@link PacketVersion} enum. Null if not found
63       */
64      public static PacketVersion fromIntValue(final int value) {
65          switch (value) {
66          case 1:
67              return VERSION_1;
68          case 2:
69              return VERSION_2;
70          default:
71              return null;
72          }
73      }
74  }