public class RankedSortedCollection extends DistanceRankedSortedCollection<RankedAbstractObject>
SortedCollection
that is specific for distance-ranked objects.DEFAULT_INITIAL_CAPACITY, UNLIMITED_CAPACITY
Constructor and Description |
---|
RankedSortedCollection()
Constructs an empty collection.
|
RankedSortedCollection(DistanceFunction<? super T> distanceFunction,
T referenceObject,
java.util.Iterator<? extends T> iterator)
Creates a new collection filled with objects provided by the
iterator . |
RankedSortedCollection(DistanceFunction<? super T> distanceFunction,
T referenceObject,
ObjectProvider<? extends T> objectProvider)
Creates a new collection filled with objects provided by the
objectProvider . |
RankedSortedCollection(int initialCapacity,
int maximalCapacity)
Constructs an empty collection with the specified initial and maximal capacity.
|
RankedSortedCollection(int initialCapacity,
int maximalCapacity,
java.util.Comparator<? super RankedAbstractObject> comparator)
Constructs an empty collection with the specified initial and maximal capacity.
|
RankedSortedCollection(LocalAbstractObject referenceObject,
java.util.Iterator<? extends LocalAbstractObject> iterator)
Creates a new collection filled with objects provided by the
iterator . |
RankedSortedCollection(LocalAbstractObject referenceObject,
ObjectProvider<? extends LocalAbstractObject> objectProvider)
Creates a new collection filled with objects provided by the
objectProvider . |
RankedSortedCollection(RankingQueryOperation operation)
Constructor from an existing operation - all parameters are copied from the operation answer.
|
Modifier and Type | Method and Description |
---|---|
RankedAbstractObject |
add(AnswerType answerType,
AbstractObject object,
float distance,
float[] objectDistances)
Add a distance-ranked object to this collection.
|
boolean |
add(RankedAbstractObject e)
Adds the specified element to this list.
|
protected boolean |
add(RankedAbstractObject e,
int index)
Adds the specified element to this list given an index on which the object should be stored.
|
void |
clear()
Removes all of the elements from this list.
|
protected boolean |
isEqual(AbstractObject e1,
AbstractObject e2)
Given two objects, this method compares them according to locator (if not null) and, if both locators null,
then according to
LocalAbstractObject.dataEquals(java.lang.Object) . |
boolean |
isIgnoringDuplicates()
Returns the flag whether the add method checks if the object that
isEqual(messif.objects.AbstractObject, messif.objects.AbstractObject) exists already in the collection. |
protected RankedAbstractObject |
rankObject(AnswerType answerType,
AbstractObject object,
float distance,
float[] objectDistances)
Internal method that creates a distance-ranked object for adding to this collection.
|
protected boolean |
remove(int index)
Removes the element at the specified position in this collection.
|
boolean |
remove(java.lang.Object o)
Removes the first occurrence of the specified element from this list,
if it is present.
|
RankedAbstractObject |
removeFirst()
Removes and returns the first element of this collection according to the order
specified by the comparator.
|
RankedAbstractObject |
removeLast()
Removes and returns the last element of this collection according to the order
specified by the comparator.
|
void |
setIgnoringDuplicates(boolean ignoringDuplicates)
Set the flag whether the add method checks if the object that
isEqual(messif.objects.AbstractObject, messif.objects.AbstractObject) exists already in the collection. |
void |
setMaximalCapacity(int capacity)
Set the maximal capacity of this collection.
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this list
in proper sequence (from first to last element).
|
<E> E[] |
toArray(E[] array)
Returns an array containing all of the elements in this list in proper
sequence (from first to last element); the runtime type of the returned
array is that of the specified array.
|
getLastDistance, getThresholdDistance, iteratorDistanceRestricted, iteratorDistanceRestricted
addAll, addAllSortedArray, clone, clone, compare, contains, containsAll, element, get, getComparator, getMaximalCapacity, isEmpty, isFull, iterator, iterator, offer, peek, poll, popLast, remove, removeAll, removeAll, removeFirstN, retainAll, size, toString
binarySearch, first, fullSearch, indexOf, last, mergeSort
public RankedSortedCollection(int initialCapacity, int maximalCapacity, java.util.Comparator<? super RankedAbstractObject> comparator) throws java.lang.IllegalArgumentException
initialCapacity
- the initial capacity of the collectionmaximalCapacity
- the maximal capacity of the collectioncomparator
- the comparator that defines orderingjava.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidpublic RankedSortedCollection(int initialCapacity, int maximalCapacity) throws java.lang.IllegalArgumentException
initialCapacity
- the initial capacity of the collectionmaximalCapacity
- the maximal capacity of the collectionjava.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidpublic RankedSortedCollection()
SortedCollection.DEFAULT_INITIAL_CAPACITY
and maximal capacity is not limited.public RankedSortedCollection(DistanceFunction<? super T> distanceFunction, T referenceObject, java.util.Iterator<? extends T> iterator)
iterator
.
Objects are ranked by the distance measured by the distanceFunction
from the given referenceObject
.T
- the type of object used to measure the distancedistanceFunction
- the distance function used for the measuringreferenceObject
- the reference object from which the distance is measurediterator
- the iterator on objects to add to the collectionpublic RankedSortedCollection(DistanceFunction<? super T> distanceFunction, T referenceObject, ObjectProvider<? extends T> objectProvider)
objectProvider
.
Objects are ranked by the distance measured by the distanceFunction
from the given referenceObject
.T
- the type of object used to measure the distancedistanceFunction
- the distance function used for the measuringreferenceObject
- the reference object from which the distance is measuredobjectProvider
- the provider of objects to add to the collectionpublic RankedSortedCollection(LocalAbstractObject referenceObject, java.util.Iterator<? extends LocalAbstractObject> iterator)
iterator
.
Objects are ranked by the distance measured from the given referenceObject
.referenceObject
- the reference object from which the distance is measurediterator
- the iterator on objects to add to the collectionpublic RankedSortedCollection(LocalAbstractObject referenceObject, ObjectProvider<? extends LocalAbstractObject> objectProvider)
objectProvider
.
Objects are ranked by the distance measured from the given referenceObject
.referenceObject
- the reference object from which the distance is measuredobjectProvider
- the provider of objects to add to the collectionpublic RankedSortedCollection(RankingQueryOperation operation)
operation
- operation with collection to copy all parameters frompublic void setMaximalCapacity(int capacity)
SortedCollection
SortedCollection.size
.setMaximalCapacity
in class SortedCollection<RankedAbstractObject>
capacity
- the new collection maximal capacity (zero or negative value means unlimited capacity)public void setIgnoringDuplicates(boolean ignoringDuplicates)
isEqual(messif.objects.AbstractObject, messif.objects.AbstractObject)
exists already in the collection.ignoringDuplicates
- the flag whether the add method checks for duplicate objectspublic boolean isIgnoringDuplicates()
isEqual(messif.objects.AbstractObject, messif.objects.AbstractObject)
exists already in the collection.public boolean add(RankedAbstractObject e)
SortedCollection
add
in interface java.util.Collection<RankedAbstractObject>
add
in interface java.util.Queue<RankedAbstractObject>
add
in class SortedCollection<RankedAbstractObject>
e
- element to be appended to this listprotected final boolean add(RankedAbstractObject e, int index)
SortedCollection
add
in class SortedCollection<RankedAbstractObject>
e
- element to be appended to this listindex
- index on which the object should be storedprotected boolean isEqual(AbstractObject e1, AbstractObject e2)
LocalAbstractObject.dataEquals(java.lang.Object)
.e1
- first objecte2
- second objectpublic void clear()
SortedCollection
clear
in interface java.util.Collection<RankedAbstractObject>
clear
in class SortedCollection<RankedAbstractObject>
public boolean remove(java.lang.Object o)
SortedCollection
remove
in interface java.util.Collection<RankedAbstractObject>
remove
in class SortedCollection<RankedAbstractObject>
o
- element to be removed from this list, if presentprotected boolean remove(int index)
SortedCollection
remove
in class SortedCollection<RankedAbstractObject>
index
- index of the element to removepublic RankedAbstractObject removeLast() throws java.util.NoSuchElementException
SortedCollection
removeLast
in class SortedCollection<RankedAbstractObject>
java.util.NoSuchElementException
- if the collection is emptypublic RankedAbstractObject removeFirst() throws java.util.NoSuchElementException
SortedCollection
removeFirst
in class SortedCollection<RankedAbstractObject>
java.util.NoSuchElementException
- if the collection is emptypublic java.lang.Object[] toArray()
SortedCollection
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
toArray
in interface java.util.Collection<RankedAbstractObject>
toArray
in class SortedCollection<RankedAbstractObject>
public <E> E[] toArray(E[] array)
SortedCollection
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
toArray
in interface java.util.Collection<RankedAbstractObject>
toArray
in class SortedCollection<RankedAbstractObject>
E
- the type of array componentsarray
- the array into which the elements of the list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.public RankedAbstractObject add(AnswerType answerType, AbstractObject object, float distance, float[] objectDistances)
RankedAbstractMetaObject
if the given objectDistances
array is not null.answerType
- the type of the objects added to this collectionobject
- the object to adddistance
- the distance of objectobjectDistances
- the array of distances to the respective sub-objects (can be null)java.lang.IllegalArgumentException
- if the answer type of this operation requires cloning but the passed object cannot be clonedprotected RankedAbstractObject rankObject(AnswerType answerType, AbstractObject object, float distance, float[] objectDistances)
RankedAbstractMetaObject
if the given objectDistances
array is not null.answerType
- the type of the objects added to this collectionobject
- the object to adddistance
- the distance of objectobjectDistances
- the array of distances to the respective sub-objects (can be null)java.lang.IllegalArgumentException
- if the answer type of this operation requires cloning but the passed object cannot be cloned