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 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 * Id code for an unknown packet type.
34 */
35 UNKNOWN(99);
36
37 /**
38 * The enumeration int value.
39 */
40 private final int intValue;
41
42 /**
43 * Builds an enumeration with the given int value.
44 *
45 * @param value
46 * The value
47 */
48 PacketType(final int value) {
49 intValue = value;
50 }
51
52 /**
53 * Returns the int value of the enum.
54 *
55 * @return The int value
56 */
57 public int intValue() {
58 return intValue;
59 }
60
61 /**
62 * Converts from the protocol int value representing the state to the
63 * enumeration constant.
64 *
65 * @param value
66 * The int value state
67 * @return The Enumeration
68 */
69 public static PacketType fromIntValue(final int value) {
70 switch (value) {
71 case 1:
72 return QUERY;
73 case 2:
74 return RESPONSE;
75 default:
76 return UNKNOWN;
77 }
78 }
79 }