1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.spdy;
17
18
19
20
21 public class SpdySessionStatus implements Comparable<SpdySessionStatus> {
22
23
24
25
26 public static final SpdySessionStatus OK =
27 new SpdySessionStatus(0, "OK");
28
29
30
31
32 public static final SpdySessionStatus PROTOCOL_ERROR =
33 new SpdySessionStatus(1, "PROTOCOL_ERROR");
34
35
36
37
38 public static final SpdySessionStatus INTERNAL_ERROR =
39 new SpdySessionStatus(2, "INTERNAL_ERROR");
40
41
42
43
44
45
46 public static SpdySessionStatus valueOf(int code) {
47 switch (code) {
48 case 0:
49 return OK;
50 case 1:
51 return PROTOCOL_ERROR;
52 case 2:
53 return INTERNAL_ERROR;
54 }
55
56 return new SpdySessionStatus(code, "UNKNOWN (" + code + ')');
57 }
58
59 private final int code;
60
61 private final String statusPhrase;
62
63
64
65
66
67 public SpdySessionStatus(int code, String statusPhrase) {
68 if (statusPhrase == null) {
69 throw new NullPointerException("statusPhrase");
70 }
71
72 this.code = code;
73 this.statusPhrase = statusPhrase;
74 }
75
76
77
78
79 public int code() {
80 return code;
81 }
82
83
84
85
86 public String statusPhrase() {
87 return statusPhrase;
88 }
89
90 @Override
91 public int hashCode() {
92 return code();
93 }
94
95 @Override
96 public boolean equals(Object o) {
97 if (!(o instanceof SpdySessionStatus)) {
98 return false;
99 }
100
101 return code() == ((SpdySessionStatus) o).code();
102 }
103
104 @Override
105 public String toString() {
106 return statusPhrase();
107 }
108
109 @Override
110 public int compareTo(SpdySessionStatus o) {
111 return code() - o.code();
112 }
113 }