This project has retired. For details please refer to its
Attic page.
RemovableKeySet 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.Collection;
26 import java.util.Enumeration;
27 import java.util.LinkedHashSet;
28 import java.util.Set;
29
30 import org.apache.tiles.request.attribute.HasRemovableKeys;
31
32
33
34
35
36
37 public class RemovableKeySet extends KeySet {
38
39
40
41
42 private HasRemovableKeys<?> request;
43
44
45
46
47
48
49 public RemovableKeySet(HasRemovableKeys<?> request) {
50 super(request);
51 this.request = request;
52 }
53
54 @Override
55 public boolean remove(Object o) {
56 String skey = key(o);
57 Object previous = request.getValue(skey);
58 if (previous != null) {
59 request.removeValue(skey);
60 return true;
61 }
62 return false;
63 }
64
65 @SuppressWarnings("unchecked")
66 @Override
67 public boolean removeAll(Collection<?> c) {
68 Collection<String> realCollection = (Collection<String>) c;
69 boolean retValue = false;
70 for (String entry : realCollection) {
71 retValue |= remove(entry);
72 }
73 return retValue;
74 }
75
76 @SuppressWarnings("unchecked")
77 @Override
78 public boolean retainAll(Collection<?> c) {
79 Collection<String> realCollection = (Collection<String>) c;
80 boolean retValue = false;
81 Set<String> keysToRemove = new LinkedHashSet<String>();
82 for (Enumeration<String> keys = request.getKeys(); keys.hasMoreElements();) {
83 String key = keys.nextElement();
84 if (!realCollection.contains(key)) {
85 retValue = true;
86 keysToRemove.add(key);
87 }
88 }
89 for (String key : keysToRemove) {
90 request.removeValue(key);
91 }
92 return retValue;
93 }
94
95 }