View Javadoc
1   /*
2    * Copyright 2014 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    *   http://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  
17  package io.netty.handler.codec.mqtt;
18  
19  import io.netty.util.internal.StringUtil;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  
25  /**
26   * Payload of the {@link MqttSubAckMessage}
27   */
28  public class MqttSubAckPayload {
29  
30      private final List<Integer> grantedQoSLevels;
31  
32      public MqttSubAckPayload(int... grantedQoSLevels) {
33          if (grantedQoSLevels == null) {
34              throw new NullPointerException("grantedQoSLevels");
35          }
36  
37          List<Integer> list = new ArrayList<Integer>(grantedQoSLevels.length);
38          for (int v: grantedQoSLevels) {
39              list.add(v);
40          }
41          this.grantedQoSLevels = Collections.unmodifiableList(list);
42      }
43  
44      public MqttSubAckPayload(Iterable<Integer> grantedQoSLevels) {
45          if (grantedQoSLevels == null) {
46              throw new NullPointerException("grantedQoSLevels");
47          }
48          List<Integer> list = new ArrayList<Integer>();
49          for (Integer v: grantedQoSLevels) {
50              if (v == null) {
51                  break;
52              }
53              list.add(v);
54          }
55          this.grantedQoSLevels = Collections.unmodifiableList(list);
56      }
57  
58      public List<Integer> grantedQoSLevels() {
59          return grantedQoSLevels;
60      }
61  
62      @Override
63      public String toString() {
64          return new StringBuilder(StringUtil.simpleClassName(this))
65              .append('[')
66              .append("grantedQoSLevels=").append(grantedQoSLevels)
67              .append(']')
68              .toString();
69      }
70  }