1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.http2;
17
18 import io.netty5.channel.ChannelId;
19
20
21
22
23 final class Http2StreamChannelId implements ChannelId {
24 private static final long serialVersionUID = -6642338822166867585L;
25
26 private final int id;
27 private final ChannelId parentId;
28
29 Http2StreamChannelId(ChannelId parentId, int id) {
30 this.parentId = parentId;
31 this.id = id;
32 }
33
34 @Override
35 public String asShortText() {
36 return parentId.asShortText() + '/' + id;
37 }
38
39 @Override
40 public String asLongText() {
41 return parentId.asLongText() + '/' + id;
42 }
43
44 @Override
45 public int compareTo(ChannelId o) {
46 if (o instanceof Http2StreamChannelId) {
47 Http2StreamChannelId otherId = (Http2StreamChannelId) o;
48 int res = parentId.compareTo(otherId.parentId);
49 if (res == 0) {
50 return id - otherId.id;
51 } else {
52 return res;
53 }
54 }
55 return parentId.compareTo(o);
56 }
57
58 @Override
59 public int hashCode() {
60 return id * 31 + parentId.hashCode();
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (!(obj instanceof Http2StreamChannelId)) {
66 return false;
67 }
68 Http2StreamChannelId otherId = (Http2StreamChannelId) obj;
69 return id == otherId.id && parentId.equals(otherId.parentId);
70 }
71
72 @Override
73 public String toString() {
74 return asShortText();
75 }
76 }