View Javadoc
1   /*
2    * Copyright 2021 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.quic;
17  
18  import io.netty.util.internal.ObjectUtil;
19  
20  import java.util.Objects;
21  
22  /**
23   * The priority of a {@link QuicStreamChannel}.
24   */
25  public final class QuicStreamPriority {
26  
27      private final int urgency;
28      private final boolean incremental;
29  
30      /**
31       * Create a new instance
32       *
33       * @param urgency       the urgency of the stream.
34       * @param incremental   {@code true} if incremental.
35       */
36      public QuicStreamPriority(int urgency, boolean incremental) {
37          this.urgency = ObjectUtil.checkInRange(urgency, 0, Byte.MAX_VALUE, "urgency");
38          this.incremental = incremental;
39      }
40  
41      /**
42       * The urgency of the stream. Smaller number means more urgent and so data will be send earlier.
43       *
44       * @return  the urgency.
45       */
46      public int urgency() {
47          return urgency;
48      }
49  
50      /**
51       * {@code true} if incremental, {@code false} otherwise.
52       *
53       * @return  if incremental.
54       */
55      public boolean isIncremental() {
56          return incremental;
57      }
58  
59      @Override
60      public boolean equals(Object o) {
61          if (this == o) {
62              return true;
63          }
64          if (o == null || getClass() != o.getClass()) {
65              return false;
66          }
67          QuicStreamPriority that = (QuicStreamPriority) o;
68          return urgency == that.urgency && incremental == that.incremental;
69      }
70  
71      @Override
72      public int hashCode() {
73          return Objects.hash(urgency, incremental);
74      }
75  
76      @Override
77      public String toString() {
78          return "QuicStreamPriority{" +
79                  "urgency=" + urgency +
80                  ", incremental=" + incremental +
81                  '}';
82      }
83  }