01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.tomcat.util.collections;
18:
19: import java.util.Enumeration;
20:
21: import org.apache.tomcat.util.buf.MessageBytes;
22:
23: /** Enumerate the values for a (possibly ) multiple
24: * value element.
25: */
26: class MultiMapValuesEnumeration implements Enumeration {
27: int pos;
28: int size;
29: MessageBytes next;
30: MultiMap headers;
31: String name;
32:
33: MultiMapValuesEnumeration(MultiMap headers, String name,
34: boolean toString) {
35: this .name = name;
36: this .headers = headers;
37: pos = 0;
38: size = headers.size();
39: findNext();
40: }
41:
42: private void findNext() {
43: next = null;
44: for (; pos < size; pos++) {
45: MessageBytes n1 = headers.getName(pos);
46: if (n1.equalsIgnoreCase(name)) {
47: next = headers.getValue(pos);
48: break;
49: }
50: }
51: pos++;
52: }
53:
54: public boolean hasMoreElements() {
55: return next != null;
56: }
57:
58: public Object nextElement() {
59: MessageBytes current = next;
60: findNext();
61: return current.toString();
62: }
63: }
|