View Javadoc
1   /*
2    * Copyright 2020 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http2;
17  
18  /**
19   * Default implementation of {@linkplain Http2PriorityFrame}
20   */
21  public final class DefaultHttp2PriorityFrame extends AbstractHttp2StreamFrame implements Http2PriorityFrame {
22  
23      private final int streamDependency;
24      private final short weight;
25      private final boolean exclusive;
26  
27      public DefaultHttp2PriorityFrame(int streamDependency, short weight, boolean exclusive) {
28          this.streamDependency = streamDependency;
29          this.weight = weight;
30          this.exclusive = exclusive;
31      }
32  
33      @Override
34      public int streamDependency() {
35          return streamDependency;
36      }
37  
38      @Override
39      public short weight() {
40          return weight;
41      }
42  
43      @Override
44      public boolean exclusive() {
45          return exclusive;
46      }
47  
48      @Override
49      public DefaultHttp2PriorityFrame stream(Http2FrameStream stream) {
50          super.stream(stream);
51          return this;
52      }
53  
54      @Override
55      public String name() {
56          return "PRIORITY_FRAME";
57      }
58  
59      @Override
60      public boolean equals(Object o) {
61          if (!(o instanceof DefaultHttp2PriorityFrame)) {
62              return false;
63          }
64          DefaultHttp2PriorityFrame other = (DefaultHttp2PriorityFrame) o;
65          boolean same = super.equals(other);
66          return same && streamDependency == other.streamDependency
67                  && weight == other.weight && exclusive == other.exclusive;
68      }
69  
70      @Override
71      public int hashCode() {
72          int hash = super.hashCode();
73          hash = hash * 31 + streamDependency;
74          hash = hash * 31 + weight;
75          hash = hash * 31 + (exclusive ? 1 : 0);
76          return hash;
77      }
78  
79      @Override
80      public String toString() {
81          return "DefaultHttp2PriorityFrame(" +
82                  "stream=" + stream() +
83                  ", streamDependency=" + streamDependency +
84                  ", weight=" + weight +
85                  ", exclusive=" + exclusive +
86                  ')';
87      }
88  }