*/
package org.wamblee.usermgt;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicLong;
/**
* In-memory group set implementation.
* @author Erik Brakkee
*/
public class InMemoryGroupSet implements GroupSet {
+
+ private AtomicLong pk = new AtomicLong(1l);
+
/**
* Groups.
*/
- private Set<Group> groups;
+ private List<Group> groups;
/**
* Constructs an empty group set.
*/
public InMemoryGroupSet() {
- groups = new TreeSet<Group>();
+ groups = new ArrayList<Group>();
}
/*
* org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group)
*/
public void groupModified(Group aGroup) {
- groups.remove(aGroup);
- groups.add(aGroup);
+ for (int i = 0; i < groups.size(); i++) {
+ if (groups.get(i).getPrimaryKey().equals(aGroup.getPrimaryKey())) {
+ groups.remove(i);
+ groups.add(aGroup);
+ return;
+ }
+ }
}
/*
public Group find(String aName) {
for (Group group : groups) {
if (group.getName().equals(aName)) {
- return new Group(group);
+ return group;
}
}
* @see org.wamblee.usermgt.GroupSet#add(org.wamblee.usermgt.Group)
*/
public boolean add(Group aGroup) {
+ aGroup.setPrimaryKey(pk.getAndIncrement());
+ if ( find(aGroup.getName()) != null ) {
+ return false;
+ }
return groups.add(aGroup);
}