1 /*
2 * hunt-proton: AMQP Protocol library for D programming language.
3 *
4 * Copyright (C) 2018-2019 HuntLabs
5 *
6 * Website: https://www.huntlabs.net/
7 *
8 * Licensed under the Apache-2.0 License.
9 *
10 */11 12 13 modulehunt.proton.amqp.transport.Role;
14 15 importhunt.Enum;
16 importstd.concurrency : initOnce;
17 importhunt.Boolean;
18 importhunt.Exceptions;
19 importhunt.util.Common;
20 importhunt.util.Comparator;
21 22 classRole {
23 24 protectedstring_name;
25 26 staticRoleSENDER() {
27 __gsharedRoleinst;
28 returninitOnce!inst(newRole("SENDER",0));
29 }
30 31 staticRoleRECEIVER() {
32 __gsharedRoleinst;
33 returninitOnce!inst(newRole("RECEIVER",1));
34 }
35 36 37 this(stringname, intordinal) {
38 this._name = name;
39 this._ordinal = ordinal;
40 }
41 42 /**
43 * The name of this enum constant, as declared in the enum declaration.
44 * Most programmers should use the {@link #toString} method rather than
45 * accessing this field.
46 */47 48 49 /**
50 * Returns the name of this enum constant, exactly as declared in its
51 * enum declaration.
52 *
53 * <b>Most programmers should use the {@link #toString} method in
54 * preference to this one, as the toString method may return
55 * a more user-friendly name.</b> This method is designed primarily for
56 * use in specialized situations where correctness depends on getting the
57 * exact name, which will not vary from release to release.
58 *
59 * @return the name of this enum constant
60 */61 finalstringname() {
62 return_name;
63 }
64 65 /**
66 * The ordinal of this enumeration constant (its position
67 * in the enum declaration, where the initial constant is assigned
68 * an ordinal of zero).
69 *
70 * Most programmers will have no use for this field. It is designed
71 * for use by sophisticated enum-based data structures, such as
72 * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
73 */74 protectedint_ordinal;
75 76 /**
77 * Returns the ordinal of this enumeration constant (its position
78 * in its enum declaration, where the initial constant is assigned
79 * an ordinal of zero).
80 *
81 * Most programmers will have no use for this method. It is
82 * designed for use by sophisticated enum-based data structures, such
83 * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
84 *
85 * @return the ordinal of this enumeration constant
86 */87 finalintordinal() {
88 return_ordinal;
89 }
90 91 /**
92 * Returns the name of this enum constant, as contained in the
93 * declaration. This method may be overridden, though it typically
94 * isn't necessary or desirable. An enum type should override this
95 * method when a more "programmer-friendly" string form exists.
96 *
97 * @return the name of this enum constant
98 */99 overridestringtoString() {
100 return_name;
101 }
102 103 publicBooleangetValue()
104 {
105 returnnewBoolean (this.name() == "RECEIVER");
106 }
107 108 publicintgetVal()
109 {
110 returnthis._ordinal;
111 }
112 113 114 overrideintopCmp(Objecto) {
115 Roleother = cast(Role) o;
116 Roleself = this;
117 if (otherisnull)
118 thrownewNullPointerException();
119 returncompare(self.ordinal, other.ordinal);
120 }
121 122 //int opCmp(int o)123 //{124 // return this._val - o;125 //}126 127 128 129 // SENDER, RECEIVER130 }
131 132 133