T
- subclass of Named
to keep in this set.public class NamedSet<T extends Named> extends AbstractSet<T> implements SortedSet<T>
Set
of Named
WorkflowBean
.
This set will guarantee to never contain more than one Named
object per
Named.getName()
.
It is also possible to retrieve values by name using getByName(String)
, or remove using
removeByName(String)
. The names can also be found in getNames()
and
nameIterator()
Internally this set is backed by a TreeMap
.
Constructor and Description |
---|
NamedSet()
Constructs an empty
NamedSet . |
NamedSet(Collection<? extends T> collection)
Constructs a
NamedSet containing all the elements of the given collection. |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T named)
Adds the
Named WorkflowBean and returns true iff the set did not
already contain an element with the same name. |
String |
addWithUniqueName(T element)
Adds the
Named WorkflowBean with a unique name if the name already exist. |
void |
clear() |
NamedSet<T> |
clone() |
Comparator<? super T> |
comparator() |
boolean |
contains(Object o)
Return
true if the NamedSet contains the given object, as compared
using its Object.equals(Object) method. |
boolean |
containsName(String name)
Return
true if the NamedSet contains an element with the given
name. |
T |
first() |
T |
getByName(String name)
Return the element with the given name from the set.
|
Set<String> |
getNames()
Returns a set of the names of the elements in this set.
|
SortedSet<T> |
headSet(T toElement) |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
T |
last() |
Iterator<String> |
nameIterator() |
boolean |
remove(Object o) |
T |
removeByName(String name)
Removes the element with the given name.
|
int |
size() |
SortedSet<T> |
subSet(T fromElement,
T toElement) |
SortedSet<T> |
tailSet(T fromElement) |
equals, hashCode, removeAll
addAll, containsAll, retainAll, toArray, toArray, toString
public NamedSet()
NamedSet
.public NamedSet(Collection<? extends T> collection)
NamedSet
containing all the elements of the given collection.
If the collection contains several Named
elements with the same name, only the last
of those elements will be in the new NamedSet
.
collection
- the collection whose elements are to be added to the setpublic boolean add(T named)
Named
WorkflowBean
and returns true
iff the set did not
already contain an element with the same name.
The element must not be null
If a different (object identity) element with the same name already exists in the set, the
element will be replaced the new element and false
will be returned.
Inserting the same object instance a second time will have no effect.
public String addWithUniqueName(T element)
Named
WorkflowBean
with a unique name if the name already exist.
Similar to add(Named)
, but if a (object identity) different element with the same
name already exists in the set, the element to be inserted will be given a unique name before
inserting.
This means that inserting the same object instance a second time will have no effect, as with
add(Named)
.
The unique name is generated by appending _x
to the existing name, where x is a
number from 2 or higher. An existing numeric prefix will first be removed.
For example, if the set already contains elements named "fish", "fish_2" and "fish_5", but you try to insert a different element which is named "fish" or "fish_5", it will be renamed to "fish_3" before inserting.
Note: If the element is a Child
instance, and it's
Child.getParent()
is not null
(or this set) the renaming could
potentially cause a conflict in the old parent set. (In the example above, if the element's
old parent has a child "fish_3" it will be overwritten by this instance).
element
- the Named WorkflowBean
to addT#getName()
after insertionpublic void clear()
public Comparator<? super T> comparator()
comparator
in interface SortedSet<T extends Named>
public boolean contains(Object o)
true
if the NamedSet
contains the given object, as compared
using its Object.equals(Object)
method.
Note that if a different object with the same name exists, this method will return
false
. To check for existence of a name, use containsName(String)
.
contains
in interface Collection<T extends Named>
contains
in interface Set<T extends Named>
contains
in class AbstractCollection<T extends Named>
o
- Collection.contains(Object)
public boolean containsName(String name)
true
if the NamedSet
contains an element with the given
name.name
- the name of objecttrue
if an element with given name is in setpublic T getByName(String name)
null
if the set does not contain an element with the given name.name
- the name of the element to returnpublic Set<String> getNames()
public boolean isEmpty()
public boolean remove(Object o)
public T removeByName(String name)
Named
element that was removed or null
if the set did not
contain an element with the given name.name
- the name of the element to removeNamed
element that was removed or null
if the set did not
contain an element with the given namepublic int size()
Copyright © 2013 myGrid. All rights reserved.