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;
17  
18  /**
19   * Enums all the known packet types.
20   *
21   * @author Massimiliano Ziccardi
22   */
23  public enum PacketType {
24      /**
25       * Id code for a packet containing a query.
26       */
27      QUERY(1),
28      /**
29       * Id code for a packet containing a response.
30       */
31      RESPONSE(2);
32  
33      /**
34       * The int value of the enumeration constant.
35       */
36      private final int intValue;
37  
38      /**
39       * Creates an enumeration constant with the given value.
40       *
41       * @param value
42       *            the constant value
43       */
44      PacketType(final int value) {
45          intValue = value;
46      }
47  
48      /**
49       * Return the integer value of the constant.
50       *
51       * @return The integer value
52       */
53      public int intValue() {
54          return intValue;
55      }
56  
57      /**
58       * Convert from the passed in integer value to the corresponding enumeration
59       * constant.
60       *
61       * @param value
62       *            The value to be converted
63       * @return The corresponding enumeration constant
64       */
65      public static PacketType fromIntValue(final int value) {
66          switch (value) {
67          case 1:
68              return QUERY;
69          case 2:
70              return RESPONSE;
71          default:
72              return null;
73          }
74      }
75  }