1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45:
46: import ;
47:
48: import ;
49: import ;
50: import ;
51:
52: public class ClientCertificateTypeList implements Iterable<ClientCertificateType>
53: {
54: private final ByteBuffer buffer;
55: private int modCount;
56:
57: public ClientCertificateTypeList (final ByteBuffer buffer)
58: {
59: this.buffer = buffer;
60: modCount = 0;
61: }
62:
63: public int size ()
64: {
65: return (buffer.get (0) & 0xFF);
66: }
67:
68: public CertificateRequest.ClientCertificateType get (final int index)
69: {
70: int size = size ();
71: if (index < 0 || index >= size)
72: throw new IndexOutOfBoundsException ("limit: " + size
73: + "; requested: " + index);
74: return CertificateRequest.ClientCertificateType.forValue
75: (buffer.get (index + 1) & 0xFF);
76: }
77:
78: public java.util.Iterator<ClientCertificateType> iterator()
79: {
80: return new Iterator();
81: }
82:
83: public void put (final int index, final CertificateRequest.ClientCertificateType type)
84: {
85: int size = size ();
86: if (index < 0 || index >= size)
87: throw new IndexOutOfBoundsException ("limit: " + size
88: + "; requested: " + index);
89: buffer.put (index + 1, (byte) type.getValue ());
90: modCount++;
91: }
92:
93: public void setSize (final int newSize)
94: {
95: if (newSize < 0 || newSize > 255)
96: throw new IllegalArgumentException ("size must be between 0 and 255");
97: if (newSize + 1 > buffer.capacity ())
98: throw new IllegalArgumentException ("limit: " + (buffer.capacity () - 1)
99: + "; requested: " + newSize);
100: buffer.put (0, (byte) newSize);
101: modCount++;
102: }
103:
104: public String toString ()
105: {
106: return toString (null);
107: }
108:
109: public String toString (final String prefix)
110: {
111: StringWriter str = new StringWriter ();
112: PrintWriter out = new PrintWriter (str);
113: if (prefix != null) out.print (prefix);
114: out.print ("[");
115: out.print (size ());
116: out.println ("] {");
117: for (Iterator it = new Iterator (); it.hasNext (); )
118: {
119: if (prefix != null) out.print (prefix);
120: out.print (" ");
121: out.print (it.next ());
122: if (it.hasNext ())
123: out.print (",");
124: out.println ();
125: }
126: if (prefix != null) out.print (prefix);
127: out.println ("};");
128: return str.toString ();
129: }
130:
131: public boolean equals (Object o)
132: {
133: if (!(o instanceof ClientCertificateTypeList))
134: return false;
135: ClientCertificateTypeList that = (ClientCertificateTypeList) o;
136:
137: if (size () != that.size ())
138: return false;
139:
140: for (Iterator it1 = new Iterator (), it2 = that.new Iterator ();
141: it1.hasNext () && it2.hasNext (); )
142: {
143: if (!it1.next ().equals (it2.next ()))
144: return false;
145: }
146: return true;
147: }
148:
149: public class Iterator implements ListIterator<CertificateRequest.ClientCertificateType>
150: {
151: private int index;
152: private final int modCount;
153:
154: Iterator ()
155: {
156: index = 0;
157: modCount = ClientCertificateTypeList.this.modCount;
158: }
159:
160: public void add (CertificateRequest.ClientCertificateType type)
161: {
162: throw new UnsupportedOperationException ();
163: }
164:
165: public boolean hasNext ()
166: {
167: return (index < size ());
168: }
169:
170: public boolean hasPrevious ()
171: {
172: return (index > 0);
173: }
174:
175: public CertificateRequest.ClientCertificateType next () throws NoSuchElementException
176: {
177: if (modCount != ClientCertificateTypeList.this.modCount)
178: throw new ConcurrentModificationException ();
179: try
180: {
181: return get (index++);
182: }
183: catch (IndexOutOfBoundsException ioobe)
184: {
185: throw new NoSuchElementException ();
186: }
187: }
188:
189: public int nextIndex ()
190: {
191: if (hasNext ())
192: return (index + 1);
193: return -1;
194: }
195:
196: public CertificateRequest.ClientCertificateType previous () throws NoSuchElementException
197: {
198: if (index == 0)
199: throw new NoSuchElementException ();
200: if (modCount != ClientCertificateTypeList.this.modCount)
201: throw new ConcurrentModificationException ();
202: try
203: {
204: return get (--index);
205: }
206: catch (IndexOutOfBoundsException ioobe)
207: {
208: throw new NoSuchElementException ();
209: }
210: }
211:
212: public int previousIndex ()
213: {
214: return (index - 1);
215: }
216:
217: public void remove ()
218: {
219: throw new UnsupportedOperationException ();
220: }
221:
222: public void set (final CertificateRequest.ClientCertificateType type)
223: {
224: put (index, type);
225: }
226: }
227: }