1 package org.sim0mq.message;
2
3 import java.util.LinkedHashMap;
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-2019 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 NONE. */
22 NONE(0),
23
24 /** message status NEW. */
25 NEW(1),
26
27 /** message status CHANGE. */
28 CHANGE(2),
29
30 /** message status DELETE. */
31 DELETE(3);
32
33 /** the status code, 1, 2, or 3. */
34 private final byte status;
35
36 /** the types for retrieval. */
37 private static ImmutableHashMap<Integer, MessageStatus> types = null;
38
39 /**
40 * @param status the status code, 1, 2, or 3.
41 */
42 MessageStatus(final int status)
43 {
44 this.status = (byte) status;
45 }
46
47 /**
48 * @return status code
49 */
50 public final byte getStatus()
51 {
52 return this.status;
53 }
54
55 /**
56 * make the types after initialization.
57 * @return the map of message status codes
58 */
59 public static ImmutableHashMap<Integer, MessageStatus> getTypes()
60 {
61 Map<Integer, MessageStatus> t = new LinkedHashMap<>();
62 if (types == null)
63 {
64 for (int i = 0; i < values().length; i++)
65 {
66 MessageStatus ms = values()[i];
67 t.put((int) ms.getStatus(), ms);
68 }
69 types = new ImmutableHashMap<>(t, Immutable.WRAP);
70 }
71 return types;
72 }
73
74 }