Package org.apache.fulcrum.security.util
Class SecuritySet<T extends SecurityEntity>
- java.lang.Object
-
- org.apache.fulcrum.security.util.SecuritySet<T>
-
- All Implemented Interfaces:
Serializable
,Iterable<T>
,Collection<T>
,Set<T>
- Direct Known Subclasses:
GroupSet
,PermissionSet
,RoleSet
,UserSet
public abstract class SecuritySet<T extends SecurityEntity> extends Object implements Serializable, Set<T>, Iterable<T>
This class represents a set of Security Entities. It makes it easy to build a UI. It wraps a TreeSet object to enforce that only relevant methods are available. TreeSet's contain only unique Objects (no duplicates) based on the ID. They may or may not have a name, that depends on the implementation. Want to get away from requiring an ID and a name... Nothing should force Name to be unique in the basic architecture of Fulcrum Security.- Version:
- $Id$
- Author:
- Eric Pugh, John D. McNally, Brett McLaughlin, Marco Knüttel, Henning P. Schmiedehausen
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SecuritySet()
Constructs an empty Set
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Collection<? extends T> collection)
Adds the entities in a Collection to this SecuritySet.boolean
add(T o)
boolean
addAll(Collection<? extends T> collection)
void
clear()
Removes all Objects from this Set.boolean
contains(Object o)
Checks whether this SecuritySet contains an entity.boolean
containsAll(Collection<?> collection)
boolean
containsId(Object id)
Searches if an Object with a given Id is in the Setboolean
containsName(String name)
Searches if an Object with a given name is in the SetT
getById(Object id)
Returns an entity with the given id, if it is contained in this SecuritySet.T
getByName(String name)
Returns an entity with the given name, if it is contained in this SecuritySet.Set<Object>
getIds()
Returns a set of Id values in this Object.Set<String>
getNames()
Returns a set of Names in this Object.Set<T>
getSet()
Returns a set of security objects in this object.boolean
isEmpty()
Iterator<T>
iterator()
Returns an Iterator for Objects in this Set.boolean
remove(Object o)
Removes an entity from this SecuritySet.boolean
removeAll(Collection<?> collection)
boolean
retainAll(Collection<?> collection)
int
size()
Returns size (cardinality) of this set.Object[]
toArray()
<A> A[]
toArray(A[] a)
String
toString()
list of role names in this set-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
-
-
-
Field Detail
-
nameMap
protected Map<String,T extends SecurityEntity> nameMap
Map for "name" is "security object"
-
idMap
protected Map<Object,T extends SecurityEntity> idMap
Map for "id" is "security object"
-
-
Constructor Detail
-
SecuritySet
public SecuritySet()
Constructs an empty Set
-
-
Method Detail
-
getSet
public Set<T> getSet()
Returns a set of security objects in this object.- Returns:
- A Set Object
-
getNames
public Set<String> getNames()
Returns a set of Names in this Object.- Returns:
- The Set of Names in this Object, backed by the actual data.
-
getIds
public Set<Object> getIds()
Returns a set of Id values in this Object.- Returns:
- The Set of Ids in this Object, backed by the actual data.
-
clear
public void clear()
Removes all Objects from this Set.- Specified by:
clear
in interfaceCollection<T extends SecurityEntity>
- Specified by:
clear
in interfaceSet<T extends SecurityEntity>
-
containsName
public boolean containsName(String name)
Searches if an Object with a given name is in the Set- Parameters:
name
- Name of the Security Object.- Returns:
- True if argument matched an Object in this Set; false if no match.
-
containsId
public boolean containsId(Object id)
Searches if an Object with a given Id is in the Set- Parameters:
id
- Id of the Security Object.- Returns:
- True if argument matched an Object in this Set; false if no match.
-
iterator
public Iterator<T> iterator()
Returns an Iterator for Objects in this Set.- Specified by:
iterator
in interfaceCollection<T extends SecurityEntity>
- Specified by:
iterator
in interfaceIterable<T extends SecurityEntity>
- Specified by:
iterator
in interfaceSet<T extends SecurityEntity>
- Returns:
- An iterator for the Set
-
size
public int size()
Returns size (cardinality) of this set.- Specified by:
size
in interfaceCollection<T extends SecurityEntity>
- Specified by:
size
in interfaceSet<T extends SecurityEntity>
- Returns:
- The cardinality of this Set.
-
add
public boolean add(T o)
- Specified by:
add
in interfaceCollection<T extends SecurityEntity>
- Specified by:
add
in interfaceSet<T extends SecurityEntity>
- See Also:
Collection.add(java.lang.Object)
-
add
public boolean add(Collection<? extends T> collection)
Adds the entities in a Collection to this SecuritySet.- Parameters:
collection
- A Collection of entities.- Returns:
- True if this Set changed as a result; false if no change to this Set occurred (this Set already contained all members of the added Set).
-
addAll
public boolean addAll(Collection<? extends T> collection)
- Specified by:
addAll
in interfaceCollection<T extends SecurityEntity>
- Specified by:
addAll
in interfaceSet<T extends SecurityEntity>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<T extends SecurityEntity>
- Specified by:
isEmpty
in interfaceSet<T extends SecurityEntity>
-
containsAll
public boolean containsAll(Collection<?> collection)
- Specified by:
containsAll
in interfaceCollection<T extends SecurityEntity>
- Specified by:
containsAll
in interfaceSet<T extends SecurityEntity>
-
removeAll
public boolean removeAll(Collection<?> collection)
- Specified by:
removeAll
in interfaceCollection<T extends SecurityEntity>
- Specified by:
removeAll
in interfaceSet<T extends SecurityEntity>
-
retainAll
public boolean retainAll(Collection<?> collection)
- Specified by:
retainAll
in interfaceCollection<T extends SecurityEntity>
- Specified by:
retainAll
in interfaceSet<T extends SecurityEntity>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<T extends SecurityEntity>
- Specified by:
toArray
in interfaceSet<T extends SecurityEntity>
-
contains
public boolean contains(Object o)
Checks whether this SecuritySet contains an entity.- Specified by:
contains
in interfaceCollection<T extends SecurityEntity>
- Specified by:
contains
in interfaceSet<T extends SecurityEntity>
- Parameters:
o
- An entity.- Returns:
- True if this Set contains the entity, false otherwise.
-
remove
public boolean remove(Object o)
Removes an entity from this SecuritySet.- Specified by:
remove
in interfaceCollection<T extends SecurityEntity>
- Specified by:
remove
in interfaceSet<T extends SecurityEntity>
- Parameters:
o
- An entity.- Returns:
- True if this Set contained the entity before it was removed.
-
toArray
public <A> A[] toArray(A[] a)
- Specified by:
toArray
in interfaceCollection<T extends SecurityEntity>
- Specified by:
toArray
in interfaceSet<T extends SecurityEntity>
-
getByName
public T getByName(String name)
Returns an entity with the given name, if it is contained in this SecuritySet.- Parameters:
name
- Name of entity.- Returns:
- entity if argument matched an entity in this Set; null if no match.
-
-