1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.codec.socksx.v5;
18
19 import io.netty.util.internal.ObjectUtil;
20
21
22
23
24 public class Socks5PasswordAuthStatus implements Comparable<Socks5PasswordAuthStatus> {
25
26 public static final Socks5PasswordAuthStatus SUCCESS = new Socks5PasswordAuthStatus(0x00, "SUCCESS");
27 public static final Socks5PasswordAuthStatus FAILURE = new Socks5PasswordAuthStatus(0xFF, "FAILURE");
28
29 public static Socks5PasswordAuthStatus valueOf(byte b) {
30 switch (b) {
31 case 0x00:
32 return SUCCESS;
33 case (byte) 0xFF:
34 return FAILURE;
35 }
36
37 return new Socks5PasswordAuthStatus(b);
38 }
39
40 private final byte byteValue;
41 private final String name;
42 private String text;
43
44 public Socks5PasswordAuthStatus(int byteValue) {
45 this(byteValue, "UNKNOWN");
46 }
47
48 public Socks5PasswordAuthStatus(int byteValue, String name) {
49 this.name = ObjectUtil.checkNotNull(name, "name");
50 this.byteValue = (byte) byteValue;
51 }
52
53 public byte byteValue() {
54 return byteValue;
55 }
56
57 public boolean isSuccess() {
58 return byteValue == 0;
59 }
60
61 @Override
62 public int hashCode() {
63 return byteValue;
64 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (!(obj instanceof Socks5PasswordAuthStatus)) {
69 return false;
70 }
71
72 return byteValue == ((Socks5PasswordAuthStatus) obj).byteValue;
73 }
74
75 @Override
76 public int compareTo(Socks5PasswordAuthStatus o) {
77 return byteValue - o.byteValue;
78 }
79
80 @Override
81 public String toString() {
82 String text = this.text;
83 if (text == null) {
84 this.text = text = name + '(' + (byteValue & 0xFF) + ')';
85 }
86 return text;
87 }
88 }