|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgoldman.collection.tagged.bucket.TaggedBucketCollectionWrapper<T,E>
public class TaggedBucketCollectionWrapper<T,E>
The tagged bucket wrapper is implemented as a wrapper for any tagged collection, where each tag is placed in the wrapped collection only once, and the associated element for each tag is a bucket object of any collection type. An important distinction is that the size of a wrapped tagged collection only depends upon the number of distinct tags. Thus, for the time complexity of all methods delegated to the wrapped tagged collection, n is the number of distinct tags. However, from the view of the application, the size of a tagged bucket collection is the number of elements, not the number of tags.
Field Summary | |
---|---|
protected BucketFactory<E> |
factory
|
protected TaggedCollection<T,Collection<E>> |
tc
|
Constructor Summary | |
---|---|
TaggedBucketCollectionWrapper(TaggedCollection<T,Collection<E>> tc,
BucketFactory<E> factory)
|
|
TaggedBucketCollectionWrapper(TaggedCollection<T,Collection<E>> tc,
Class bucketType)
|
Method Summary | |
---|---|
void |
accept(Visitor<TaggedElement<T,Collection<E>>> v)
Traverses the entire collection on behalf of a visitor. |
int |
bucketSize(T tag)
Returns the number of elements with the given tag. |
void |
clear()
Removes all elements from this collection. |
boolean |
contains(T tag)
Returns true if an equivalent tag exists in this tagged bucket collection. |
void |
ensureCapacity(int capacity)
Increases the capacity of this tagged collection, if necessary, to ensure that it can hold at least capacity distinct tags. |
Collection<E> |
get(T tag)
Returns a collection of all elements with the given tag. |
int |
getCapacity()
Returns the current capacity (in terms of the number of tags) of this tagged collection. |
Locator<E> |
getElements(T tag)
Returns a locator positioned at FORE within the bucket associated with the given tag, or an iterator over an empty bucket if the tag is not in use. |
int |
getNumTags()
Returns the number of distinct tags used in this collection. |
int |
getSize()
Returns the number of elements, size, in this collection. |
TaggedCollection<T,Collection<E>> |
getTaggedCollection()
|
boolean |
isEmpty()
Returns true if this collection contains no elements, and otherwise returns false. |
Iterator<TaggedElement<T,Collection<E>>> |
iterator()
Creates a new iterator that is at FORE. |
void |
put(T tag,
E data)
Adds data to the bucket for the given tag . |
void |
putAll(TaggedCollection<T,E> tc)
|
Locator<E> |
putTracked(T tag,
E data)
Associates data with the given
tag by adding it to the bucket (which is
created if it does not exist) for tag . |
E |
remove(T tag)
Removes the first element in the bucket for that tag, according to the iteration order |
boolean |
remove(T tag,
E element)
Removes the specified element from the bucket associated with the given tag (if it exists in that bucket). |
Collection<E> |
removeBucket(T tag)
Removes all elements from this tagged bucket collection that are associated with the given tag. |
String |
toString()
Returns a string that describes each tagged element in the collection, as produced by the toString method for that element, in the iteration order. |
void |
trimToSize()
Trims the capacity of this tagged bucket collection to be its current size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected TaggedCollection<T,Collection<E>> tc
protected BucketFactory<E> factory
Constructor Detail |
---|
public TaggedBucketCollectionWrapper(TaggedCollection<T,Collection<E>> tc, BucketFactory<E> factory)
tc
- the (empty)
tagged collection from T to buckets that is to be wrappedfactory
- a bucket factory that is used to create a bucket for each new tagpublic TaggedBucketCollectionWrapper(TaggedCollection<T,Collection<E>> tc, Class bucketType)
tc
- the
tagged collection from T to buckets that is to be wrappedbucketType
- a class of the appropriate collection type for the buckets
bucketType
implement
the Collection
interfaceMethod Detail |
---|
public TaggedCollection<T,Collection<E>> getTaggedCollection()
public int getNumTags()
TaggedBucketCollection
getNumTags
in interface TaggedBucketCollection<T,E>
public boolean isEmpty()
TaggedBucketCollection
isEmpty
in interface TaggedBucketCollection<T,E>
public int getSize()
TaggedBucketCollection
getSize
in interface TaggedBucketCollection<T,E>
public int getCapacity()
TaggedBucketCollection
getCapacity
in interface TaggedBucketCollection<T,E>
public boolean contains(T tag)
TaggedBucketCollection
contains
in interface TaggedBucketCollection<T,E>
tag
- the target tag
public Collection<E> get(T tag)
TaggedBucketCollection
NoSuchElementException
otherwise.
get
in interface TaggedBucketCollection<T,E>
tag
- the target tag
NoSuchElementException
- tag
is not in usepublic Locator<E> getElements(T tag)
TaggedBucketCollection
getElements
in interface TaggedBucketCollection<T,E>
tag
- the target tag
tag
is not in use, an iterator for an empty bucket is returned.public String toString()
TaggedBucketCollection
toString
method for that element, in the iteration order.
toString
in interface TaggedBucketCollection<T,E>
toString
in class Object
toString
methods of the wrapped
tagged collection and the bucket typepublic void accept(Visitor<TaggedElement<T,Collection<E>>> v)
accept
in interface TaggedBucketCollection<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 int bucketSize(T tag)
TaggedBucketCollection
bucketSize
in interface TaggedBucketCollection<T,E>
tag
- the target tag
tag
(which by definition
is 0 when the tag is not in use)public void ensureCapacity(int capacity)
TaggedBucketCollection
capacity
distinct tags.
ensureCapacity
in interface TaggedBucketCollection<T,E>
public void trimToSize()
TaggedBucketCollection
trimToSize
in interface TaggedBucketCollection<T,E>
public void put(T tag, E data)
data
to the bucket for the given tag
.
If no bucket exists for the given tag
, a bucket is
created using the provided factory.
put
in interface TaggedBucketCollection<T,E>
tag
- the tag for the new elementdata
- the associated datapublic Locator<E> putTracked(T tag, E data)
data
with the given
tag
by adding it to the bucket (which is
created if it does not exist) for tag
.
tag
- the tag for the new elementdata
- the associated data
UnsupportedOperationException
- the bucket type does not implement the
Tracked
interfacepublic void putAll(TaggedCollection<T,E> tc)
tc
- the tagged collection to be added to this
collectionpublic E remove(T tag)
remove
in interface TaggedBucketCollection<T,E>
tag
- the target tag
NoSuchElementException
- there are no elements associated with the given tag
public boolean remove(T tag, E element)
remove
in interface TaggedBucketCollection<T,E>
tag
- the target tagelement
- the
associated element
to remove
public Collection<E> removeBucket(T tag)
removeBucket
in interface TaggedBucketCollection<T,E>
tag
- the target tag
NoSuchElementException
- there is
no bucket for the given tag.public void clear()
clear
in interface TaggedBucketCollection<T,E>
public Iterator<TaggedElement<T,Collection<E>>> iterator()
iterator
in interface TaggedBucketCollection<T,E>
iterator
in interface Iterable<TaggedElement<T,Collection<E>>>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |