|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgoldman.collection.tagged.TaggedCollectionWrapper<T,E>
public class TaggedCollectionWrapper<T,E>
Rather than implement each of the tagged collections from scratch, we define a tagged collection wrapper that can be used to transform any untagged collection into a tagged collection. Each element in the collection is a tagged element. For a tagged collection to have the specified behavior, it is required that the equivalence tester over a tagged element be defined according to the tag.
Field Summary | |
---|---|
protected Collection<TaggedElement<T,E>> |
pairs
|
protected MutableTaggedElement<T,E> |
target
|
Constructor Summary | |
---|---|
TaggedCollectionWrapper(Collection<TaggedElement<T,E>> pairs)
|
Method Summary | |
---|---|
void |
accept(Visitor<? super TaggedElement<T,E>> v)
Traverses the entire collection on behalf of a visitor. |
void |
clear()
Removes all elements from this collection. |
boolean |
contains(T tag)
Returns true if a tagged element with an equivalent tag exists in this collection. |
Iterator<E> |
elements()
Returns an iterator over the elements that has been initialized to just before the first element in the iteration order. |
void |
ensureCapacity(int capacity)
Increases the capacity of the collection, if necessary, to ensure that it can hold at least capacity elements. |
E |
get(T tag)
Returns an element with the given tag. |
int |
getCapacity()
Returns the current capacity of this tagged collection. |
Locator<TaggedElement<T,E>> |
getLocator(T tag)
Returns a locator that has been initialized to a tagged element with an equivalent tag. |
int |
getSize()
Returns the number of tagged elements, size, in this collection. |
boolean |
isEmpty()
Returns true if this collection contains no elements, and otherwise returns false. |
Iterator<TaggedElement<T,E>> |
iterator()
Creates a new iterator at FORE. |
void |
put(T tag,
E data)
Creates a new tagged element with the given values and inserts this tagged element into this collection. |
void |
putAll(TaggedCollection<T,E> tc)
Adds all tagged elements in tc to this tagged collection. |
E |
remove(T tag)
Removes some tagged element in this collection with an tag equivalent to the given tag |
Iterator<T> |
tags()
Returns an iterator over the tags that has been initialized to just before the first tag in the iteration order. |
String |
toString()
Returns a string that describes each tagged element in the collection, in the iteration order. |
void |
trimToSize()
Trims the capacity of this collection to be its current size. |
Collection<E> |
values()
This implementation creates a positional collection (specifically, an array), and the elements are inserted in the iteration order |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Collection<TaggedElement<T,E>> pairs
protected MutableTaggedElement<T,E> target
Constructor Detail |
---|
public TaggedCollectionWrapper(Collection<TaggedElement<T,E>> pairs)
pairs
- the collection
to wrap
IllegalArgumentException
- the provided collection
is not emptyMethod Detail |
---|
public int getCapacity()
TaggedCollection
getCapacity
in interface TaggedCollection<T,E>
public int getSize()
TaggedCollection
getSize
in interface TaggedCollection<T,E>
public boolean isEmpty()
TaggedCollection
isEmpty
in interface TaggedCollection<T,E>
public boolean contains(T tag)
TaggedCollection
contains
in interface TaggedCollection<T,E>
tag
- the target tag
public E get(T tag)
TaggedCollection
tag
be in use. It throws a
NoSuchElementException
otherwise
get
in interface TaggedCollection<T,E>
tag
- the target tag
NoSuchElementException
- there is no element
with an equivalent tagpublic Locator<TaggedElement<T,E>> getLocator(T tag)
TaggedCollection
iterator
method, this method enables
navigation, but from a specified starting point. This method
throws a NoSuchElementException
if there is no tagged element with an equivalent tag
in the collection.
getLocator
in interface TaggedCollection<T,E>
tag
- the target tag
NoSuchElementException
- there is no element
with an equivalent tagpublic Collection<E> values()
values
in interface TaggedCollection<T,E>
public String toString()
TaggedCollection
toString
in interface TaggedCollection<T,E>
toString
in class Object
public void accept(Visitor<? super TaggedElement<T,E>> v)
accept
in interface TaggedCollection<T,E>
v
- a visitor
VisitAbortedException
- the traversal is aborted due to an
exception raised by the visitor,
in which case the cause held by the VisitAbortedException is the
exception thrown by the visitor.public void ensureCapacity(int capacity)
capacity
elements.
ensureCapacity
in interface TaggedCollection<T,E>
capacity
- the desired capacity for the collectionpublic void trimToSize()
trimToSize
in interface TaggedCollection<T,E>
public void put(T tag, E data)
put
in interface TaggedCollection<T,E>
tag
- the tag for the tagged element to adddata
- the associated data
AtCapacityException
- the
collection is already at capacity.public void putAll(TaggedCollection<T,E> tc)
TaggedCollection
tc
to this tagged collection.
putAll
in interface TaggedCollection<T,E>
tc
- the tagged collection to be added to this
collectionpublic E remove(T tag)
remove
in interface TaggedCollection<T,E>
tag
- the target tag
NoSuchElementException
- there is no element
with an equivalent tagpublic void clear()
clear
in interface TaggedCollection<T,E>
public Iterator<TaggedElement<T,E>> iterator()
iterator
in interface TaggedCollection<T,E>
iterator
in interface Iterable<TaggedElement<T,E>>
public Iterator<T> tags()
TaggedCollection
tags
in interface TaggedCollection<T,E>
public Iterator<E> elements()
TaggedCollection
elements
in interface TaggedCollection<T,E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |