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