Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package ca.nrc.cadc.ac;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* A custom set built on a list implementation.
*
* Ordering will not be deterministic as per the Set specification.
*/
public class UserSet implements Set<User>
{
private List<User> users;
public UserSet()
{
users = new ArrayList<User>();
}
public User getUser(Principal identity)
{
User test = null;
for (User u : users)
{
test = new User();
test.getIdentities().add(identity);
if (test.isConsistent(u))
{
return u;
}
}
return null;
}
public List<User> getUserList()
{
return users;
}
@Override
public boolean add(User e)
{
if (!users.contains(e))
{
users.add(e);
return true;
}
return false;
}
@Override
public boolean addAll(Collection<? extends User> c)
{
Iterator<? extends User> i = c.iterator();
boolean modified = false;
while (i.hasNext())
{
if (this.add(i.next()))
{
modified = true;
}
}
return modified;
}
@Override
public void clear()
{
users.clear();
}
@Override
public boolean contains(Object o)
{
return users.contains(o);
}
@Override
public boolean containsAll(Collection<?> c)
{
return users.containsAll(c);
}
@Override
public boolean isEmpty()
{
return users.isEmpty();
}
@Override
public Iterator<User> iterator()
{
return users.iterator();
}
@Override
public boolean remove(Object o)
{
if (users.contains(o))
{
users.remove(o);
return true;
}
return false;
}
@Override
public boolean removeAll(Collection<?> c)
{
Iterator<?> i = c.iterator();
boolean modified = false;
while (i.hasNext())
{
if (this.remove(i.next()))
{
modified = true;
}
}
return modified;
}
@Override
public boolean retainAll(Collection<?> c)
{
Iterator<User> i = users.listIterator();
boolean modified = false;
User next = null;
while (i.hasNext())
{
next = i.next();
if (!c.contains(next))
{
i.remove();
modified = true;
}
}
return modified;
}
@Override
public int size()
{
return users.size();
}
@Override
public Object[] toArray()
{
return users.toArray();
}
@Override
public <T> T[] toArray(T[] a)
{
return users.toArray(a);
}
}