1 package org.sim0mq.message;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.djutils.immutablecollections.Immutable;
7 import org.djutils.immutablecollections.ImmutableHashMap;
8
9 /**
10 * Message status names and corresponding values when serialized.
11 * <p>
12 * Copyright (c) 2016-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13 * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
14 * </p>
15 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
16 * initial version Mar 3, 2017 <br>
17 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18 */
19 public enum MessageStatus
20 {
21 /** message status NEW. */
22 NEW(1),
23
24 /** message status CHANGE. */
25 CHANGE(2),
26
27 /** message status DELETE. */
28 DELETE(3);
29
30 /** the status code, 1, 2, or 3. */
31 private final byte status;
32
33 /** the types for retrieval. */
34 private static ImmutableHashMap<Integer, MessageStatus> types = null;
35
36 /**
37 * @param status the status code, 1, 2, or 3.
38 */
39 MessageStatus(final int status)
40 {
41 this.status = (byte) status;
42 }
43
44 /**
45 * @return status code
46 */
47 public final byte getStatus()
48 {
49 return this.status;
50 }
51
52 /**
53 * make the types after initialization.
54 * @return the map of message status codes
55 */
56 public static ImmutableHashMap<Integer, MessageStatus> getTypes()
57 {
58 Map<Integer, MessageStatus> t = new HashMap<>();
59 if (types == null)
60 {
61 for (int i = 0; i < values().length; i++)
62 {
63 MessageStatus ms = values()[i];
64 t.put((int) ms.getStatus(), ms);
65 }
66 types = new ImmutableHashMap<>(t, Immutable.WRAP);
67 }
68 return types;
69 }
70
71 }