1 /* |
1 /* |
2 * Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
190 } |
190 } |
191 } |
191 } |
192 return Default; |
192 return Default; |
193 } |
193 } |
194 |
194 |
195 class ParserIterator implements Iterator { |
195 class ParserIterator implements Iterator<String> { |
196 int index; |
196 int index; |
197 boolean returnsValue; // or key |
197 boolean returnsValue; // or key |
198 |
198 |
199 ParserIterator (boolean returnValue) { |
199 ParserIterator (boolean returnValue) { |
200 returnsValue = returnValue; |
200 returnsValue = returnValue; |
201 } |
201 } |
202 public boolean hasNext () { |
202 public boolean hasNext () { |
203 return index<nkeys; |
203 return index<nkeys; |
204 } |
204 } |
205 public Object next () { |
205 public String next () { |
206 return tab[index++][returnsValue?1:0]; |
206 return tab[index++][returnsValue?1:0]; |
207 } |
207 } |
208 public void remove () { |
208 public void remove () { |
209 throw new UnsupportedOperationException ("remove not supported"); |
209 throw new UnsupportedOperationException ("remove not supported"); |
210 } |
210 } |
211 } |
211 } |
212 |
212 |
213 public Iterator keys () { |
213 public Iterator<String> keys () { |
214 return new ParserIterator (false); |
214 return new ParserIterator (false); |
215 } |
215 } |
216 |
216 |
217 public Iterator values () { |
217 public Iterator<String> values () { |
218 return new ParserIterator (true); |
218 return new ParserIterator (true); |
219 } |
219 } |
220 |
220 |
221 public String toString () { |
221 public String toString () { |
222 Iterator k = keys(); |
222 Iterator<String> k = keys(); |
223 StringBuffer sbuf = new StringBuffer(); |
223 StringBuffer sbuf = new StringBuffer(); |
224 sbuf.append ("{size="+asize+" nkeys="+nkeys+" "); |
224 sbuf.append ("{size="+asize+" nkeys="+nkeys+" "); |
225 for (int i=0; k.hasNext(); i++) { |
225 for (int i=0; k.hasNext(); i++) { |
226 String key = (String)k.next(); |
226 String key = k.next(); |
227 String val = findValue (i); |
227 String val = findValue (i); |
228 if (val != null && "".equals (val)) { |
228 if (val != null && "".equals (val)) { |
229 val = null; |
229 val = null; |
230 } |
230 } |
231 sbuf.append (" {"+key+(val==null?"":","+val)+"}"); |
231 sbuf.append (" {"+key+(val==null?"":","+val)+"}"); |