public class SortedPreferentialArray<T extends Comparable<? super T>> extends Object
Insertion time is n, search is log(n)
Clients must manage thread safety on previous version. I synchronized the public methods to add easy thread safety. I synchronized all public methods that make modifications.
| Constructor and Description |
|---|
SortedPreferentialArray(int maxSize)
Construct the array with the maximum size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T obj)
If the array is full this will remove the smallest if preferLarge==true and if obj is bigger,
or the largest if preferLarge=false and obj is smaller than the largest.
|
protected String |
dumpArray()
Debugging method to return a human readable display of array data.
|
T |
getLargest()
Returns the largest without removing it from the array.
|
T |
getSmallest()
Returns the smallest element without removing it from the array.
|
void |
setPreferLarge(boolean pref)
Determines whether the preference is for large or small.
|
int |
size()
Returns the current size of the array.
|
T |
takeNearestLargerOrEqual(T obj)
Returns and removes the nearer larger or equal object from the aray.
|
public SortedPreferentialArray(int maxSize)
maxSize - intpublic void add(T obj)
obj - Objectpublic T getLargest()
public T getSmallest()
public void setPreferLarge(boolean pref)
pref - booleanpublic T takeNearestLargerOrEqual(T obj)
obj - Comparablepublic int size()
protected String dumpArray()
Copyright © 2002–2015 The Apache Software Foundation. All rights reserved.