Class TypeRefSet
java.lang.Object
net.okapia.osid.torrefacto.collect.TypeRefSet
A reference-counted
Types collection. Each type is uniquely
identified by its namespace, authority, and identifier, and the same
type may be added more than once. A type is reported as present
until it has been removed as many times as it was added; only the
removal that matches the last outstanding add drops it.
This suits a provider that registers type support from several
independent sources and must keep a type available until the last
source withdraws it. For plain set behavior, where repeated adds
collapse to one, use TypeSet instead.
The backing map is synchronized.-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TypeRefSet.TypeRefSet(Collection<Type> types) Creates a new TypeRefSet for a given collection of types.TypeRefSet(Type[] types) Creates a new TypeRefSet for a given array of types. -
Method Summary
Modifier and TypeMethodDescriptionvoidTracks a supported type, incrementing its reference count.voidclear()Removes all types and their reference counts.booleanTests for the existience of a type.iterator()Returns an iterator of Types.voidRemoves a reference to a type.Type[]toArray()Gets an array of the types.Gets an iterable collection of the types.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
TypeRefSet
public TypeRefSet()Creates a new TypeRefSet. -
TypeRefSet
Creates a new TypeRefSet for a given collection of types.- Parameters:
types- the initial types- Throws:
NullArgumentException-typesisnull
-
TypeRefSet
Creates a new TypeRefSet for a given array of types.- Parameters:
types- the initial types- Throws:
NullArgumentException-typesisnull
-
-
Method Details
-
add
Tracks a supported type, incrementing its reference count.- Specified by:
addin interfaceTypes- Parameters:
type- the type to add- Throws:
NullArgumentException-typeisnull
-
remove
Removes a reference to a type. The type is dropped only when its last outstanding reference is removed; removing a type that is not present has no effect.- Specified by:
removein interfaceTypes- Parameters:
type- the type to remove- Throws:
NullArgumentException-typeisnull
-
contains
Tests for the existience of a type.- Specified by:
containsin interfaceTypes- Parameters:
type- the type to test for- Returns:
trueif the type exists,falseotherwise- Throws:
NullArgumentException-typeisnull
-
toCollection
Gets an iterable collection of the types. Each distinct type appears once, regardless of its reference count.- Specified by:
toCollectionin interfaceTypes- Returns:
- a collection
-
toArray
-
clear
-
iterator
-