View Javadoc

1   /*
2    * Copyright 2009 Red Hat, Inc.
3    *
4    * Red Hat licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the
6    * 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  package org.jboss.netty.handler.codec.http2;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  /**
22   * This Attribute is only for Encoder use to insert special command between object if needed
23   * (like Multipart Mixed mode)
24   *
25   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
26   * @author Andy Taylor (andy.taylor@jboss.org)
27   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
28   * @author <a href="http://openr66.free.fr/">Frederic Bregier</a>
29   *
30   */
31  public class InternalAttribute implements InterfaceHttpData {
32      protected List<String> value = new ArrayList<String>();
33  
34      /**
35       *
36       * @throws NullPointerException
37       * @throws IllegalArgumentException
38       * @throws IOException
39       */
40      public InternalAttribute() {
41      }
42  
43      public HttpDataType getHttpDataType() {
44          return HttpDataType.InternalAttribute;
45      }
46  
47      public List<String> getValue() {
48          return value;
49      }
50  
51      public void addValue(String value) {
52          if (value == null) {
53              throw new NullPointerException("value");
54          }
55          this.value.add(value);
56      }
57  
58      public void addValue(String value, int rank) {
59          if (value == null) {
60              throw new NullPointerException("value");
61          }
62          this.value.add(rank, value);
63      }
64  
65      public void setValue(String value, int rank) {
66          if (value == null) {
67              throw new NullPointerException("value");
68          }
69          this.value.set(rank, value);
70      }
71  
72      @Override
73      public int hashCode() {
74          return getName().hashCode();
75      }
76  
77      @Override
78      public boolean equals(Object o) {
79          if (!(o instanceof Attribute)) {
80              return false;
81          }
82          Attribute attribute = (Attribute) o;
83          return getName().equalsIgnoreCase(attribute.getName());
84      }
85  
86      public int compareTo(InterfaceHttpData arg0) {
87          if (!(arg0 instanceof InternalAttribute)) {
88              throw new ClassCastException("Cannot compare " + getHttpDataType() +
89                      " with " + arg0.getHttpDataType());
90          }
91          return compareTo((InternalAttribute) arg0);
92      }
93  
94      public int compareTo(InternalAttribute o) {
95          return getName().compareToIgnoreCase(o.getName());
96      }
97  
98      public int size() {
99          int size = 0;
100         for (String elt : value) {
101             size += elt.length();
102         }
103         return size;
104     }
105     @Override
106     public String toString() {
107         StringBuilder result = new StringBuilder();
108         for (String elt : value) {
109             result.append(elt);
110         }
111         return result.toString();
112     }
113 
114     public String getName() {
115         return "InternalAttribute";
116     }
117 }