messif.objects.util
Class DoubleSortedCollection

java.lang.Object
  extended by messif.utility.SortedArrayData<T,T>
      extended by messif.utility.SortedCollection<RankedAbstractObject>
          extended by messif.objects.util.RankedSortedCollection
              extended by messif.objects.util.DoubleSortedCollection
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<RankedAbstractObject>, java.util.Collection<RankedAbstractObject>

public abstract class DoubleSortedCollection
extends RankedSortedCollection

This class resorts the ranked objects according to new distances (returned by method implemented in the child classes). It keeps the original distances in order to return correctly the threshold distance.

See Also:
Serialized Form

Field Summary
protected  java.util.Map<RankedAbstractObject,java.lang.Float> originalDistances
          Distances to be used for pivot filtering - the original distances without the new sorting distances.
protected  RankedAbstractObject thresholdObject
          Object from the collectio with the threshold distance for pivot filtering - this distance cannot be simply the last distance including the keywords distance, because the keywords ditance cannot be considered for filtering.
 
Constructor Summary
DoubleSortedCollection(int initialCapacity, int maximalCapacity)
          Creates new sorted collection sorted according to pixmac shape+color distance + weighted keywords distance
 
Method Summary
 boolean add(RankedAbstractObject e)
          Adds the specified element to this list.
 boolean add(RankedAbstractObject newObject, float oldDistance)
          Adds the specified element to this list.
abstract  float getNewDistance(AbstractObject origObject, float origDistance)
          Given an object, this method should return the new distance this collection is sorted according to.
 float getThresholdDistance()
          Returns the threshold distance for this collection.
protected  boolean remove(int index)
          Removes the element at the specified position in this collection.
 
Methods inherited from class messif.objects.util.RankedSortedCollection
getLastDistance
 
Methods inherited from class messif.utility.SortedCollection
addAll, clear, clone, compare, contains, containsAll, get, getMaximalCapacity, isEmpty, isFull, iterator, iterator, popLast, remove, removeAll, removeFirst, removeLast, retainAll, size, toArray, toArray, toString
 
Methods inherited from class messif.utility.SortedArrayData
binarySearch, first, fullSearch, indexOf, last, mergeSort
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Field Detail

originalDistances

protected final java.util.Map<RankedAbstractObject,java.lang.Float> originalDistances
Distances to be used for pivot filtering - the original distances without the new sorting distances.


thresholdObject

protected RankedAbstractObject thresholdObject
Object from the collectio with the threshold distance for pivot filtering - this distance cannot be simply the last distance including the keywords distance, because the keywords ditance cannot be considered for filtering.

Constructor Detail

DoubleSortedCollection

public DoubleSortedCollection(int initialCapacity,
                              int maximalCapacity)
                       throws java.lang.IllegalArgumentException
Creates new sorted collection sorted according to pixmac shape+color distance + weighted keywords distance

Parameters:
initialCapacity - capacity of the collection to allocate initially
maximalCapacity - max capacity of the collection
Throws:
java.lang.IllegalArgumentException
Method Detail

getNewDistance

public abstract float getNewDistance(AbstractObject origObject,
                                     float origDistance)
Given an object, this method should return the new distance this collection is sorted according to.

Parameters:
origObject - the original object
origDistance - the original distance
Returns:
new sorting distance

add

public boolean add(RankedAbstractObject e)
Description copied from class: SortedCollection
Adds the specified element to this list. The element is added according the to order defined by the comparator.

Specified by:
add in interface java.util.Collection<RankedAbstractObject>
Overrides:
add in class SortedCollection<RankedAbstractObject>
Parameters:
e - element to be appended to this list
Returns:
true (as specified by Collection.add(E))

add

public boolean add(RankedAbstractObject newObject,
                   float oldDistance)
Adds the specified element to this list. The element is added according the to order defined by the comparator.

Parameters:
newObject - the element to add to this list
oldDistance - old ranking distance (used for keeping the threshold)
Returns:
true (as specified by Collection.add(E))

remove

protected boolean remove(int index)
Description copied from class: SortedCollection
Removes the element at the specified position in this collection.

Overrides:
remove in class SortedCollection<RankedAbstractObject>
Parameters:
index - index of the element to remove
Returns:
false if the object was not removed (e.g. because there is no object with this index)

getThresholdDistance

public float getThresholdDistance()
Description copied from class: RankedSortedCollection
Returns the threshold distance for this collection. If this collection has not reached the maximal size (specified in constructor) yet, LocalAbstractObject.MAX_DISTANCE is returned. Otherwise, the distance of the last object of this collection is returned.

Overrides:
getThresholdDistance in class RankedSortedCollection
Returns:
the distance to the last object in this collection or LocalAbstractObject.MAX_DISTANCE if there are not enough objects.