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