goldman.collection
Class DefaultBucketizer<T>
java.lang.Object
goldman.collection.DefaultBucketizer<T>
- All Implemented Interfaces:
- Bucketizer<T>, Comparator<T>
public class DefaultBucketizer<T>
- extends Object
- implements Bucketizer<T>
This class illustrates an implementation of
the Bucketizer
interface.
Method Summary |
int |
compare(T o1,
T o2)
|
protected void |
computeRange()
Computes the range of values created by the quantizer and stores
the minimum value in min and the maximum value in max to avoid
the need to recompute these values. |
int |
getBucket(T element)
Returns the bucket to which element x
belongs. |
int |
getNumBuckets()
Returns the number of buckets used. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultBucketizer
public DefaultBucketizer(Collection<T> coll,
Quantizer<? super T> quantizer)
- Parameters:
coll
- the collection to which the bucketizer appliesquantizer
- for converting each element to a double
compare
public int compare(T o1,
T o2)
- Specified by:
compare
in interface Comparator<T>
- Parameters:
o1
- one element to compareo2
- the second element
to compare
- Returns:
- a negative integer when
o1 is less than o2, zero when o1 is equivalent to o2, and a positive
integer when o1 is greater than o2.
computeRange
protected void computeRange()
- Computes the range of values created by the quantizer and stores
the minimum value in
min
and the maximum value in max
to avoid
the need to recompute these values.
getNumBuckets
public int getNumBuckets()
- Description copied from interface:
Bucketizer
- Returns the number of buckets used.
- Specified by:
getNumBuckets
in interface Bucketizer<T>
- Returns:
- the number of buckets
among which the elements are placed.
getBucket
public int getBucket(T element)
- Description copied from interface:
Bucketizer
- Returns the bucket to which element
x
belongs. The value returned must be an integer in the range 0 to
getNumBuckets
() - 1.
- Specified by:
getBucket
in interface Bucketizer<T>
- Parameters:
element
- the desired
element in the collection
- Returns:
- the bucket where
element
should be placed. The return value is guaranteed to be an integer between 0 and
numBuckets
- 1.