C
- the class of instances that represent the classification categoriespublic class ClassificationBase<C> extends java.lang.Object implements Classification<C>, java.io.Serializable
Classification
interface.Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_INITIAL_CAPACITY
Default initial capacity used in constructor
|
Modifier | Constructor and Description |
---|---|
|
ClassificationBase(java.lang.Class<? extends C> storedClass)
Creates an empty classification.
|
protected |
ClassificationBase(java.lang.Class<? extends C> storedClass,
java.util.Collection<C> storage)
Creates an empty classification with the given storage instance.
|
|
ClassificationBase(java.lang.Class<? extends C> storedClass,
int initialCapacity)
Creates an empty classification with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
ClassificationBase<C> |
add(C category)
Adds the given category to this classification.
|
ClassificationBase<C> |
addAll(java.lang.Iterable<?> categories,
boolean ignoreIncompatibleCategory)
Adds the categories provided by the
Iterable to this classification. |
ClassificationBase<C> |
addAll(java.util.Iterator<?> categories,
boolean ignoreIncompatibleCategory)
Adds the categories provided by the iterator to this classification.
|
ClassificationBase<C> |
addArray(java.lang.Object array,
boolean ignoreIncompatibleCategory)
Adds the categories from a static array to this classification.
|
protected C |
castToStored(java.lang.Object object,
boolean ignoreIncompatibleCategory)
Cast the given object to stored category class safely.
|
boolean |
contains(C category)
Returns whether this classification contains a given category or not.
|
protected static <C> java.util.Collection<C> |
createDefaultStorage(java.lang.Class<? extends C> storedClass,
int initialCapacity)
Creates a default storage instance for holding classifications.
|
java.lang.Class<? extends C> |
getStoredClass()
Returns the class of instances that represent the classification categories (classes).
|
java.util.Iterator<C> |
iterator()
Returns an iterator over all categories of this classification.
|
boolean |
remove(C category)
Removes the given category from this classification.
|
int |
size()
Returns the number of categories of this classification.
|
java.lang.String |
toString() |
protected static final int DEFAULT_INITIAL_CAPACITY
public ClassificationBase(java.lang.Class<? extends C> storedClass) throws java.lang.NullPointerException
storedClass
- the class of instances that represent the classification categoriesjava.lang.NullPointerException
- if the categoriesClass
is nullpublic ClassificationBase(java.lang.Class<? extends C> storedClass, int initialCapacity) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
storedClass
- the class of instances that represent the classification categoriesinitialCapacity
- the initial capacity of the classificationjava.lang.NullPointerException
- if the categoriesClass
is nulljava.lang.IllegalArgumentException
- if the specified initial capacity is negativeprotected ClassificationBase(java.lang.Class<? extends C> storedClass, java.util.Collection<C> storage) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
storedClass
- the class of instances that represent the classification categoriesstorage
- the instance responsible for holding the objects in this classificationjava.lang.NullPointerException
- if the categoriesClass
or storage
is nulljava.lang.IllegalArgumentException
- if the specified initial capacity is negativeprotected static <C> java.util.Collection<C> createDefaultStorage(java.lang.Class<? extends C> storedClass, int initialCapacity)
C
- the class of instances that represent the classification categoriesstoredClass
- the class of instances that represent the classification categoriesinitialCapacity
- the initial capacity of the classificationpublic ClassificationBase<C> add(C category)
category
- the category to addprotected C castToStored(java.lang.Object object, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException
ignoreIncompatibleCategory
is true,
a null is returned.object
- the object to castignoreIncompatibleCategory
- flag whether to silently ignore incompatible object (true) or
throw a ClassCastException
(false)ignoreIncompatibleCategory
is truejava.lang.ClassCastException
- if the object is not compatible with this classification categoriespublic ClassificationBase<C> addAll(java.util.Iterator<?> categories, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException
C
and null items are silently ignored.categories
- an iterator over the categories to addignoreIncompatibleCategory
- flag whether to silently ignore incompatible objects
from the iterator (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriespublic ClassificationBase<C> addAll(java.lang.Iterable<?> categories, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException
Iterable
to this classification.
Note that the objects from the Iterable
are type-checked to be compatible with C
and null items are silently ignored.categories
- an Iterable
over the categories to addignoreIncompatibleCategory
- flag whether to silently ignore incompatible objects
from the iterator (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriespublic ClassificationBase<C> addArray(java.lang.Object array, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException, java.lang.IllegalArgumentException
C
and null items are silently ignored.array
- a static array with the categories to addignoreIncompatibleCategory
- flag whether to silently ignore incompatible categories
from the array (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriesjava.lang.IllegalArgumentException
- if the object array
is not a static arraypublic boolean remove(C category) throws java.lang.NullPointerException
category
- the category to removejava.lang.NullPointerException
- if the given category is nullpublic java.lang.Class<? extends C> getStoredClass()
Classification
getStoredClass
in interface Classification<C>
public int size()
Classification
size
in interface Classification<C>
public java.util.Iterator<C> iterator() throws java.lang.UnsupportedOperationException
Classification
iterator
in interface java.lang.Iterable<C>
iterator
in interface Classification<C>
java.lang.UnsupportedOperationException
public boolean contains(C category) throws java.lang.NullPointerException
Classification
contains
in interface Classification<C>
category
- the category to search forjava.lang.NullPointerException
- if the given category is nullpublic java.lang.String toString()
toString
in class java.lang.Object