Homepage

org.talos.impl
Class AbstractContainer<T extends NamedObject>

java.lang.Object
  extended by org.talos.impl.AbstractContainer<T>
Type Parameters:
T - the type of entity the container holds
All Implemented Interfaces:
Container<T>
Direct Known Subclasses:
CategoryContainerImpl, ObjectContainerImpl, PermissionContainerImpl, SubjectContainerImpl

public abstract class AbstractContainer<T extends NamedObject>
extends Object
implements Container<T>

Provides an implementation of the Container interface. All containers in Talos implement this abstract class and inherit all the basic container functionality.


Field Summary
protected  Map<String,T> elements
           
 
Constructor Summary
protected AbstractContainer(Collection<T> elements)
          Constructor that gets a list of elements and builds a map of elements by name.
protected AbstractContainer(Map<String,T> elements)
          Constructor that gets a map of elements by name.
 
Method Summary
protected  void checkCloneAllowed()
          Throws an exception if the container is not capable of the cloneAs() operation
 boolean contains(String name)
          Verifies if the container contains an entity with the given name.
 boolean containsAll(String... names)
          Verifies if the container contains all the given entities.
 T getElement(String name)
          Get an especific element from this container.
protected  T getFirstElement()
          Gets the first element the container can find.
 boolean isEmpty()
          Check if the container is empty.
 Collection<T> list()
          Gets all the entities the container holds.
 void remove()
          Permanently deletes from Talos all the elements of the container.
protected abstract  void remove(T element)
          Removes an element from the storage permanently.
 int size()
          Returns the number of elements in this container
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

elements

protected Map<String,T extends NamedObject> elements
Constructor Detail

AbstractContainer

protected AbstractContainer(Map<String,T> elements)
Constructor that gets a map of elements by name. In such a map, the entry's key is the name of the entry's value

Parameters:
elements - a map of NamedObjects by name
See Also:
AbstractContainer(Collection)

AbstractContainer

protected AbstractContainer(Collection<T> elements)
Constructor that gets a list of elements and builds a map of elements by name. The collection is not stored.

Parameters:
elements - a collection of elements
See Also:
AbstractContainer(Map)
Method Detail

remove

protected abstract void remove(T element)
Removes an element from the storage permanently.

Parameters:
element - the element that must be deleted

remove

public void remove()
Description copied from interface: Container
Permanently deletes from Talos all the elements of the container.

Specified by:
remove in interface Container<T extends NamedObject>

isEmpty

public boolean isEmpty()
Description copied from interface: Container
Check if the container is empty.

Specified by:
isEmpty in interface Container<T extends NamedObject>
Returns:
true if it is empty, false otherwise.
See Also:
Container.list()

list

public Collection<T> list()
Description copied from interface: Container
Gets all the entities the container holds.

Specified by:
list in interface Container<T extends NamedObject>
Returns:
a collection with all the entities.
See Also:
Container.contains(String), Container.containsAll(String[])

contains

public boolean contains(String name)
Description copied from interface: Container
Verifies if the container contains an entity with the given name.

Specified by:
contains in interface Container<T extends NamedObject>
Parameters:
name - the name of the entity.
Returns:
true if it contains an entity with the given name, false otherwise.
See Also:
Container.list(), Container.containsAll(String[])

containsAll

public boolean containsAll(String... names)
Description copied from interface: Container
Verifies if the container contains all the given entities.

Specified by:
containsAll in interface Container<T extends NamedObject>
Parameters:
names - the name of each entities.
Returns:
true if it contains all the entities, false otherwise.
See Also:
Container.contains(String)

getElement

public T getElement(String name)
Description copied from interface: Container
Get an especific element from this container.

Specified by:
getElement in interface Container<T extends NamedObject>
Parameters:
name - the name of the element to get.
Returns:
the element if it is found, null if it is not.
See Also:
Container.list(), Container.contains(String)

size

public int size()
Description copied from interface: Container
Returns the number of elements in this container

Specified by:
size in interface Container<T extends NamedObject>
Returns:
the number of elements in this container
See Also:
Container.list(), Container.isEmpty()

getFirstElement

protected T getFirstElement()
Gets the first element the container can find. Callers should be sure that the container only contains zero or one element, unless they don't care which element comes.

Returns:
the first element found in the container, or null.

checkCloneAllowed

protected void checkCloneAllowed()
                          throws CloneNotAllowedException
Throws an exception if the container is not capable of the cloneAs() operation

Throws:
CloneNotAllowedException - if the container has too many (or too few) elements.

Homepage