Class ThresholdList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.RangeList<E>
-
- ca.odell.glazedlists.ThresholdList<E>
-
- All Implemented Interfaces:
ListEventListener<E>
,EventList<E>
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.EventListener
,java.util.List<E>
public final class ThresholdList<E> extends RangeList<E>
AnEventList
that shows a range of the elements of the sourceEventList
. Each element in the sourceEventList
is assigned an integer value via anThresholdList.Evaluator
. This integer is used to determine whether the element fits in theThresholdList
s range.By modifying the upper and lower thresholds in the range, the list can be filtered in a simple and powerful way.
The
ThresholdList
lends itself to use with a slider widget for manipulating one of the range's endpoints.One use case for
ThresholdList
is in a media player application. By creating aThresholdList.Evaluator
for a song's bitrate, the user could limit results to MP3 files between 192 and 320kbps.Note that the elements in the
ThresholdList
will be presented in order sorted by theirThresholdList.Evaluator
value.This
EventList
supports all write operations.Warning: This class breaks the contract required by
List
. SeeEventList
for an example.Warning: This class is thread ready but not thread safe. See
EventList
for an example of thread safe code.EventList Overview Writable: yes Concurrency: thread ready, not thread safe Performance: reads: O(log N), writes O(log N), change threshold O(log N) Memory: 72 bytes per element Unit Tests: N/A Issues: 47 137 217 218 246 277 - Author:
- Kevin Maltby
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ThresholdList.Evaluator<E>
Provide an integer value for a givenObject
in aThresholdList
.
-
Field Summary
-
Fields inherited from class ca.odell.glazedlists.TransformedList
source
-
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
-
-
Constructor Summary
Constructors Constructor Description ThresholdList(EventList<E> source, ThresholdList.Evaluator<E> evaluator)
Creates aThresholdList
that provides range-filtering on the specifiedEventList
using the specifiedThresholdList.Evaluator
.ThresholdList(EventList<E> source, java.lang.String propertyName)
Creates aThresholdList
that provides range-filtering based on the specifiedEventList
based on the specified integer JavaBean property.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(java.lang.Object object)
Returns true if this list contains the specified element.void
dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.int
getEndIndex()
ThresholdList.Evaluator<E>
getEvaluator()
A convenience method to allow access to theThresholdList.Evaluator
that was provided on construction.int
getLowerThreshold()
Gets the lower threshold for this listint
getStartIndex()
int
getUpperThreshold()
Gets the upper threshold for this listint
indexOf(java.lang.Object object)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.int
lastIndexOf(java.lang.Object object)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.void
setLowerThreshold(int lowerThreshold)
Sets the lower threshold for this list.void
setLowerThreshold(E object)
Sets the lower threshold for this list to be the result of callingevaluate()
on the given object.void
setRange(int startIndex, int endIndex)
Set the range of values displayed by thisRangeList
.void
setTailRange(int startIndex, int endIndex)
Set the range to include the specified indices, offset from the end of the sourceEventList
.void
setUpperThreshold(int upperThreshold)
Sets the upper threshold for this list.void
setUpperThreshold(E object)
Sets the upper threshold for this list to be the result of callingevaluate()
on the given object.-
Methods inherited from class ca.odell.glazedlists.RangeList
adjustRange, getSourceIndex, isWritable, listChanged, setHeadRange, setMiddleRange, size
-
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, get, remove, removeAll, retainAll, set
-
Methods inherited from class ca.odell.glazedlists.AbstractEventList
add, addAll, addListEventListener, containsAll, equals, getPublisher, getReadWriteLock, hashCode, isEmpty, iterator, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
ThresholdList
public ThresholdList(EventList<E> source, java.lang.String propertyName)
Creates aThresholdList
that provides range-filtering based on the specifiedEventList
based on the specified integer JavaBean property.
-
ThresholdList
public ThresholdList(EventList<E> source, ThresholdList.Evaluator<E> evaluator)
Creates aThresholdList
that provides range-filtering on the specifiedEventList
using the specifiedThresholdList.Evaluator
.
-
-
Method Detail
-
setLowerThreshold
public void setLowerThreshold(E object)
Sets the lower threshold for this list to be the result of callingevaluate()
on the given object.This list can be used programmatically rather than hooking it up to a UI component. Calling this method directly while this list is connected to a particular widget could result in errors.
Warning: This method is thread ready but not thread safe. See
EventList
for an example of thread safe code.
-
setLowerThreshold
public void setLowerThreshold(int lowerThreshold)
Sets the lower threshold for this list.This list can be used programmatically rather than hooking it up to a UI component. Calling this method directly while this list is connected to a particular widget could result in errors.
Warning: This method is thread ready but not thread safe. See
EventList
for an example of thread safe code.
-
getLowerThreshold
public int getLowerThreshold()
Gets the lower threshold for this list
-
setUpperThreshold
public void setUpperThreshold(E object)
Sets the upper threshold for this list to be the result of callingevaluate()
on the given object.This list can be used programmatically rather than hooking it up to a UI component. Calling this method directly while this list is connected to a particular widget could result in errors.
Warning: This method is thread ready but not thread safe. See
EventList
for an example of thread safe code.
-
setUpperThreshold
public void setUpperThreshold(int upperThreshold)
Sets the upper threshold for this list.Warning: This method is thread ready but not thread safe. See
EventList
for an example of thread safe code.
-
getUpperThreshold
public int getUpperThreshold()
Gets the upper threshold for this list
-
getEvaluator
public ThresholdList.Evaluator<E> getEvaluator()
A convenience method to allow access to theThresholdList.Evaluator
that was provided on construction.
-
contains
public boolean contains(java.lang.Object object)
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).- Specified by:
contains
in interfacejava.util.Collection<E>
- Specified by:
contains
in interfacejava.util.List<E>
- Overrides:
contains
in classAbstractEventList<E>
- Parameters:
object
- element whose presence in this list is to be tested.- Returns:
- true if this list contains the specified element.
-
indexOf
public int indexOf(java.lang.Object object)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
indexOf
in interfacejava.util.List<E>
- Overrides:
indexOf
in classAbstractEventList<E>
- Parameters:
object
- element to search for.- Returns:
- the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
-
lastIndexOf
public int lastIndexOf(java.lang.Object object)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
lastIndexOf
in interfacejava.util.List<E>
- Overrides:
lastIndexOf
in classAbstractEventList<E>
- Parameters:
object
- element to search for.- Returns:
- the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
-
setRange
public void setRange(int startIndex, int endIndex)
Set the range of values displayed by thisRangeList
.
-
setTailRange
public void setTailRange(int startIndex, int endIndex)
Set the range to include the specified indices, offset from the end of the sourceEventList
. For example, to show the last five values, use:RangeList.setTailRange(5, 0);
To include the 3rd last and 2nd last values, use:
RangeList.setTailRange(3, 1);
.- Overrides:
setTailRange
in classRangeList<E>
-
getStartIndex
public int getStartIndex()
- Overrides:
getStartIndex
in classRangeList<E>
-
getEndIndex
public int getEndIndex()
- Overrides:
getEndIndex
in classRangeList<E>
-
dispose
public void dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.A
TransformedList
will be garbage collected without a call toTransformedList.dispose()
, but not before its sourceEventList
is garbage collected. By callingTransformedList.dispose()
, you allow theTransformedList
to be garbage collected before its sourceEventList
. This is necessary for situations where aTransformedList
is short-lived but its sourceEventList
is long-lived.Warning: It is an error to call any method on a
TransformedList
after it has been disposed.
-
-