This project has retired. For details please refer to its
Attic page.
KeySet xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.request.collection;
22
23 import static org.apache.tiles.request.collection.CollectionUtil.*;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Enumeration;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Set;
31
32 import org.apache.tiles.request.attribute.HasKeys;
33
34
35
36
37
38
39 public class KeySet implements Set<String> {
40
41
42
43
44 private HasKeys<?> request;
45
46
47
48
49
50
51 public KeySet(HasKeys<?> request) {
52 this.request = request;
53 }
54
55 @Override
56 public boolean add(String e) {
57 throw new UnsupportedOperationException();
58 }
59
60 @Override
61 public boolean addAll(Collection<? extends String> c) {
62 throw new UnsupportedOperationException();
63 }
64
65 @Override
66 public void clear() {
67 throw new UnsupportedOperationException();
68 }
69
70 @Override
71 public boolean contains(Object o) {
72 return request.getValue(key(o)) != null;
73 }
74
75 @SuppressWarnings("unchecked")
76 @Override
77 public boolean containsAll(Collection<?> c) {
78 Collection<String> realCollection = (Collection<String>) c;
79 for (String key : realCollection) {
80 if (request.getValue(key(key)) == null) {
81 return false;
82 }
83 }
84 return true;
85 }
86
87 @Override
88 public boolean isEmpty() {
89 return !request.getKeys().hasMoreElements();
90 }
91
92 @Override
93 public Iterator<String> iterator() {
94 return new KeySetIterator();
95 }
96
97 @Override
98 public boolean remove(Object o) {
99 throw new UnsupportedOperationException();
100 }
101
102 @Override
103 public boolean removeAll(Collection<?> c) {
104 throw new UnsupportedOperationException();
105 }
106
107 @Override
108 public boolean retainAll(Collection<?> c) {
109 throw new UnsupportedOperationException();
110 }
111
112 @Override
113 public int size() {
114 return enumerationSize(request.getKeys());
115 }
116
117 @Override
118 public Object[] toArray() {
119 return toList().toArray();
120 }
121
122 @Override
123 public <T> T[] toArray(T[] a) {
124 return toList().toArray(a);
125 }
126
127
128
129
130
131
132 private List<String> toList() {
133 List<String> entries = new ArrayList<String>();
134 Enumeration<String> names = request.getKeys();
135 while (names.hasMoreElements()) {
136 entries.add(names.nextElement());
137 }
138 return entries;
139 }
140
141
142
143
144 private class KeySetIterator implements Iterator<String> {
145
146
147
148
149 private Enumeration<String> namesEnumeration = request.getKeys();
150
151 @Override
152 public boolean hasNext() {
153 return namesEnumeration.hasMoreElements();
154 }
155
156 @Override
157 public String next() {
158 return namesEnumeration.nextElement();
159 }
160
161 @Override
162 public void remove() {
163 throw new UnsupportedOperationException();
164 }
165 }
166 }