1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.newsclub.net.unix.tipc;
19
20 import java.io.Serializable;
21 import java.util.Objects;
22
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.newsclub.net.unix.NamedInteger;
26
27
28
29
30
31
32 public final class AFTIPCErrInfo implements Serializable {
33 private static final long serialVersionUID = 1L;
34
35
36
37
38 private final ErrorCode errorCode;
39
40
41
42
43 private final int dataLength;
44
45
46
47
48
49
50 @NonNullByDefault
51 public static final class ErrorCode extends NamedInteger {
52 private static final long serialVersionUID = 1L;
53
54
55
56
57 public static final ErrorCode TIPC_OK;
58
59
60
61
62 public static final ErrorCode TIPC_ERR_NO_NAME;
63
64
65
66
67 public static final ErrorCode TIPC_ERR_NO_PORT;
68
69
70
71
72 public static final ErrorCode TIPC_ERR_NO_NODE;
73
74
75
76
77 public static final ErrorCode TIPC_ERR_OVERLOAD;
78
79
80
81
82 public static final ErrorCode TIPC_ERR_CONN_SHUTDOWN;
83
84 private static final @NonNull ErrorCode[] VALUES = init(new @NonNull ErrorCode[] {
85 TIPC_OK = new ErrorCode("TIPC_OK", 0),
86 TIPC_ERR_NO_NAME = new ErrorCode("TIPC_ERR_NO_NAME", 1),
87 TIPC_ERR_NO_PORT = new ErrorCode("TIPC_ERR_NO_PORT", 2),
88 TIPC_ERR_NO_NODE = new ErrorCode("TIPC_ERR_NO_NODE", 3),
89 TIPC_ERR_OVERLOAD = new ErrorCode("TIPC_ERR_OVERLOAD", 4),
90 TIPC_ERR_CONN_SHUTDOWN = new ErrorCode("TIPC_ERR_CONN_SHUTDOWN", 5),
91 });
92
93 private ErrorCode(int id) {
94 super(id);
95 }
96
97 private ErrorCode(String name, int id) {
98 super(name, id);
99 }
100
101
102
103
104
105
106
107 public static ErrorCode ofValue(int v) {
108 return ofValue(VALUES, ErrorCode::new, v);
109 }
110 }
111
112
113
114
115
116
117
118 public AFTIPCErrInfo(ErrorCode errorCode, int dataLength) {
119 this.errorCode = errorCode;
120 this.dataLength = dataLength;
121 }
122
123
124
125
126
127
128 public ErrorCode getErrorCode() {
129 return errorCode;
130 }
131
132
133
134
135
136
137 public int getDataLength() {
138 return dataLength;
139 }
140
141 @Override
142 public String toString() {
143 return getClass().getName() + "(" + errorCode + ";dataLength=" + dataLength + ")";
144 }
145
146 @Override
147 public int hashCode() {
148 return Objects.hash(dataLength, errorCode);
149 }
150
151 @Override
152 public boolean equals(Object obj) {
153 if (this == obj) {
154 return true;
155 } else if (obj == null) {
156 return false;
157 } else if (getClass() != obj.getClass()) {
158 return false;
159 }
160 AFTIPCErrInfo other = (AFTIPCErrInfo) obj;
161 return dataLength == other.dataLength && errorCode.equals(other.errorCode);
162 }
163
164 @SuppressWarnings("PMD.ShortMethodName")
165 static AFTIPCErrInfo of(int[] tipcErrInfo) {
166 if (tipcErrInfo == null) {
167 return null;
168 }
169 if (tipcErrInfo.length != 2) {
170 throw new IllegalArgumentException();
171 }
172 return new AFTIPCErrInfo(ErrorCode.ofValue(tipcErrInfo[0]), tipcErrInfo[1]);
173 }
174 }