public final class GlazedLists extends Object
Modifier and Type | Method and Description |
---|---|
static <E> ObservableElementList.Connector<E> |
beanConnector(Class<E> beanClass)
Create a new Connector for the
ObservableElementList that works with JavaBeans'
PropertyChangeListener . |
static <E> ObservableElementList.Connector<E> |
beanConnector(Class<E> beanClass,
boolean matchPropertyNames,
String... propertyNames)
Create a new Connector for the
ObservableElementList that works with JavaBeans'
PropertyChangeListener . |
static <E> ObservableElementList.Connector<E> |
beanConnector(Class<E> beanClass,
Matcher<PropertyChangeEvent> eventMatcher)
Create a new Connector for the
ObservableElementList that works with JavaBeans'
PropertyChangeListener . |
static <E> ObservableElementList.Connector<E> |
beanConnector(Class<E> beanClass,
String addListener,
String removeListener)
Create a new Connector for the
ObservableElementList that works with JavaBeans'
PropertyChangeListener . |
static <E> ObservableElementList.Connector<E> |
beanConnector(Class<E> beanClass,
String addListener,
String removeListener,
Matcher<PropertyChangeEvent> eventMatcher)
Create a new Connector for the
ObservableElementList that works with JavaBeans'
PropertyChangeListener . |
static <E,V> FunctionList.Function<E,V> |
beanFunction(Class<E> beanClass,
String propertyName)
Get a
FunctionList.Function that extracts the property with the given propertyName from
objects of the given beanClass . |
static <T> Comparator<T> |
beanPropertyComparator(Class<T> className,
String property,
Comparator propertyComparator)
Creates a
Comparator that uses Reflection to compare two instances of the specified
Class by the given JavaBean property. |
static <T> Comparator<T> |
beanPropertyComparator(Class<T> clazz,
String property,
String... properties)
Creates a
Comparator that uses Reflection to compare two instances of the specified
Class by the given JavaBean properties. |
static <E> Matcher<E> |
beanPropertyMatcher(Class<E> beanClass,
String propertyName,
Object value)
Deprecated.
as of 3/3/2006 - this method has been replaced by
Matchers.beanPropertyMatcher(java.lang.Class<E>, java.lang.String, java.lang.Object) . Matchers is now the permanent factory
class which creates all basic Matcher implementations. |
static Comparator<Boolean> |
booleanComparator() |
static Comparator<String> |
caseInsensitiveComparator()
Creates a
Comparator that compares String objects in a case-insensitive way. |
static <T> Comparator<T> |
chainComparators(Comparator<T>... comparators)
Creates a chain of
Comparator s that applies the provided Comparator s in the
sequence specified until differences or absolute equality is determined. |
static <T> Comparator<T> |
chainComparators(List<Comparator<T>> comparators)
Creates a chain of
Comparator s that applies the provided Comparator s in the
sequence specified until differences or absolute equality is determined. |
static <T extends Comparable> |
comparableComparator()
Creates a
Comparator that compares Comparable objects. |
static <E,V> FunctionList.Function<E,V> |
constantFunction(V value)
Get a
FunctionList.Function that always returns the given value , regardless of its
input. |
static <E> EventList<E> |
eventList(Collection<? extends E> contents)
Creates a new
EventList which contains the contents of the specified Collection . |
static <E> EventList<E> |
eventList(ListEventPublisher publisher,
ReadWriteLock lock,
Collection<? extends E> contents)
Creates a new
EventList with the given ListEventPublisher and
ReadWriteLock which contains the contents of the specified Collection . |
static <E> EventList<E> |
eventListOf(E... contents)
Creates a new
EventList which contains the given elements. |
static <E> EventList<E> |
eventListOf(ListEventPublisher publisher,
ReadWriteLock lock,
E... contents)
Creates a new
EventList with the given ListEventPublisher and
ReadWriteLock which contains the given elements. |
static <D,E> Filterator<D,E> |
filterator(Class<E> beanClass,
String... propertyNames)
Creates a
TextFilterator that searches the given JavaBean properties of the specified
class. |
static <D,E> Filterator<D,E> |
filterator(String... propertyNames)
Creates a
TextFilterator that searches the given JavaBean properties. |
static <E> MatcherEditor<E> |
fixedMatcherEditor(Matcher<E> matcher)
Get a
MatcherEditor that is fixed on the specified Matcher . |
static <E> CollectionList.Model<List<E>,E> |
listCollectionListModel()
Creates a
CollectionList.Model that where List s or EventList s are the
elements of a parent EventList . |
static <E extends Observable> |
observableConnector()
Create a new Connector for the
ObservableElementList that works with subclasses of the
archaic Observable base class. |
static <E> TransformedList<E,E> |
readOnlyList(EventList<? extends E> source)
Wraps the source in an
EventList that does not allow writing operations. |
static <E> void |
replaceAll(EventList<E> target,
List<E> source,
boolean updates)
|
static <E> void |
replaceAll(EventList<E> target,
List<E> source,
boolean updates,
Comparator<E> comparator)
Overloaded version of
replaceAll(EventList, List, boolean) that uses a
Comparator to determine equality rather than equals() . |
static <E> void |
replaceAllSorted(EventList<E> target,
Collection<E> source,
boolean updates,
Comparator<E> comparator)
Replace the complete contents of the target
EventList with the complete contents of the
source Collection while making as few list changes as possible. |
static <T extends Comparable> |
reverseComparator()
Creates a reverse
Comparator that works for Comparable objects. |
static <T> Comparator<T> |
reverseComparator(Comparator<T> forward)
Creates a reverse
Comparator that inverts the given Comparator . |
static <E> ListEventListener<E> |
syncEventListToList(EventList<E> source,
List<E> target)
|
static <K,V> DisposableMap<K,V> |
syncEventListToMap(EventList<V> source,
FunctionList.Function<V,K> keyMaker)
Synchronize the specified
EventList to a Map that is returned from this method. |
static <K extends Comparable,V> |
syncEventListToMultiMap(EventList<V> source,
FunctionList.Function<V,? extends K> keyMaker)
Synchronize the specified
EventList to a MultiMap that is returned from this method. |
static <K,V> DisposableMap<K,List<V>> |
syncEventListToMultiMap(EventList<V> source,
FunctionList.Function<V,? extends K> keyMaker,
Comparator<? super K> keyGrouper)
Synchronize the specified
EventList to a MultiMap that is returned from this method. |
static <T> TableFormat<T> |
tableFormat(Class<T> baseClass,
String[] propertyNames,
String[] columnLabels)
Creates a
TableFormat that binds JavaBean properties to table columns via Reflection. |
static <T> TableFormat<T> |
tableFormat(Class<T> baseClass,
String[] propertyNames,
String[] columnLabels,
boolean[] editable)
Creates a
TableFormat that binds JavaBean properties to table columns via Reflection. |
static <T> TableFormat<T> |
tableFormat(String[] propertyNames,
String[] columnLabels)
Creates a
TableFormat that binds JavaBean properties to table columns via Reflection. |
static <T> TableFormat<T> |
tableFormat(String[] propertyNames,
String[] columnLabels,
boolean[] editable)
Creates a
TableFormat that binds JavaBean properties to table columns via Reflection. |
static <E> TextFilterator<E> |
textFilterator(Class<E> beanClass,
String... propertyNames)
Creates a
TextFilterator that searches the given JavaBean properties. |
static <E> TextFilterator<E> |
textFilterator(String... propertyNames)
Creates a
TextFilterator that searches the given JavaBean properties. |
static <E> TransformedList<E,E> |
threadSafeList(EventList<? extends E> source)
Wraps the source in an
EventList that obtains a ReadWritLock for
all operations. |
static <E> ThresholdList.Evaluator<E> |
thresholdEvaluator(String propertyName)
Creates a
ThresholdList.Evaluator that uses Reflection to utilize an integer JavaBean
property as the threshold evaluation. |
static <E> FunctionList.Function<E,String> |
toStringFunction(Class<E> beanClass,
String propertyName)
Get a
FunctionList.Function that extracts the property with the given propertyName from
objects of the given beanClass and then formats the return value as a String. |
static <E> TextFilterator<E> |
toStringTextFilterator()
Creates a
TextFilterator that searches against an Object's toString() value. |
static <S,E> TransformedList<S,E> |
transformByFunction(EventList<S> source,
FunctionList.Function<S,E> function)
Returns a
TransformedList that maps each element of the source list to a target element
by use of a specified FunctionList.Function . |
static <E> ListEventListener<E> |
typeSafetyListener(EventList<E> source,
Set<Class> types)
Check list elements for type safety after they are added to an EventList using a
ListEventListener . |
static <E> ListEventListener<E> |
weakReferenceProxy(EventList<E> source,
ListEventListener<E> target)
Provides a proxy to another ListEventListener that may go out of scope without explicitly
removing itself from the source list's set of listeners.
|
public static <E> void replaceAll(EventList<E> target, List<E> source, boolean updates)
EventList
with the complete contents of the
source EventList
while making as few list changes as possible.
In a multi-threaded environment, it is necessary that the caller obtain the write lock for the
target list before this method is invoked. If the source list is an EventList
, its read
lock must also be acquired.
This method shall be used when it is necessary to update an EventList to a newer state while
minimizing the number of change events fired. It is desirable over clear()
; addAll()
because it will not cause selection to be lost if
unnecessary. It is also useful where firing changes may be expensive, such as when they will
cause writes to disk or the network.
This is implemented using Eugene W. Myer's paper, "An O(ND) Difference Algorithm and Its Variations", the same algorithm found in GNU diff.
Note that the runtime of this method is significantly less efficient in both time and memory
than the sorted
version of replaceAll.
E
- Unified generic type of listsource
- All contents will replace targettarget
- All contents will be replaced by sourceupdates
- whether to fire update events for Objects that are equal in both List
s.public static <E> void replaceAll(EventList<E> target, List<E> source, boolean updates, Comparator<E> comparator)
replaceAll(EventList, List, boolean)
that uses a
Comparator
to determine equality rather than equals()
.E
- Unified generic type of listsource
- All contents will replace targettarget
- All contents will be replaced by source contentsupdates
- Whether to fire update events for Objects that are equal in both List
s.comparator
- The Comparator
to determine equality between elements. This
Comparator
must return 0
for elements that are equal and non-zero
for elements that are not equal. Sort order is not used.public static <E> void replaceAllSorted(EventList<E> target, Collection<E> source, boolean updates, Comparator<E> comparator)
EventList
with the complete contents of the
source Collection
while making as few list changes as possible.
Unlike the general
versions of this method, the sorted version
requires that both the input and the output are sorted collections, and that
they're sorted with the Comparator
specified. If they're sorted in natural
order, use comparableComparator()
.
In a multi-threaded environment, it is necessary that the caller obtain the write lock for the
target list before this method is invoked. If the source list is an EventList
, its read
lock must also be acquired.
This method shall be used when it is necessary to update an EventList to a newer state while
minimizing the number of change events fired. It is desirable over clear()
; addAll()
because it will not cause selection to be lost if
unnecessary. It is also useful where firing changes may be expensive, such as when they will
cause writes to disk or the network.
Note that this method is significantly more efficient in both time and memory than the
general
version of replaceAll.
E
- Unified generic type of listtarget
- an EventList sorted with the Comparator
specified. Its contents will be
replaced with those in source
.source
- a collection sorted with the Comparator
specified.comparator
- defines the sort order for both target and source. It should also define
identity. Ie, elements that compare to 0 by this comparator represent the same logical
element in the list. If null
, the comparableComparator
will be
used, which means that all elements must implement Comparable
.updates
- whether to fire update events for Objects that are equal in both List
s.Collections.sort(java.util.List<T>)
,
SortedSet
public static <T> Comparator<T> beanPropertyComparator(Class<T> clazz, String property, String... properties)
Comparator
that uses Reflection to compare two instances of the specified
Class
by the given JavaBean properties. The JavaBean property
and any
extra properties
must implement Comparable
.
The following example code sorts a List of Customers by first name, with ties broken by last name.
List<Customer> customers = ... Comparator<Customer> comparator = GlazedLists.beanPropertyComparator(Customer.class, "firstName", "lastName"); Collections.sort(customers, comparator);
T
- Type of classclazz
- the name of the class which defines the accessor method for the given
property
and optionally properties
property
- the name of the first Comparable property to be extracted and used to compare
instances of the clazz
properties
- the name of optional Comparable properties, each of which is used to break
ties for the prior property.Comparator
.public static <T> Comparator<T> beanPropertyComparator(Class<T> className, String property, Comparator propertyComparator)
Comparator
that uses Reflection to compare two instances of the specified
Class
by the given JavaBean property. The JavaBean property is compared using the
provided Comparator
.T
- Type of classclassName
- the name of the class which defines the accessor method for the given
property
and optionally properties
property
- See BeanConnector(Class, String, String)
propertyComparator
- See BeanConnector(Class, String, String)
public static Comparator<Boolean> booleanComparator()
Comparator
for use with Boolean
objects.public static Comparator<String> caseInsensitiveComparator()
Comparator
that compares String
objects in a case-insensitive way.
This Comparator
is equivalent to using String.CASE_INSENSITIVE_ORDER
and exists
here for convenience.String.CASE_INSENSITIVE_ORDER
public static <T> Comparator<T> chainComparators(List<Comparator<T>> comparators)
Comparator
s that applies the provided Comparator
s in the
sequence specified until differences or absolute equality is determined.comparators
- A list of Comparator
s to chainpublic static <T> Comparator<T> chainComparators(Comparator<T>... comparators)
Comparator
s that applies the provided Comparator
s in the
sequence specified until differences or absolute equality is determined.comparators
- Variadic comparatorspublic static <T extends Comparable> Comparator<T> comparableComparator()
Comparator
that compares Comparable
objects.ComparableComparator
.public static <T extends Comparable> Comparator<T> reverseComparator()
Comparator
that works for Comparable
objects.ComparableComparator
.public static <T> Comparator<T> reverseComparator(Comparator<T> forward)
Comparator
that inverts the given Comparator
.T
- Type of which the comparator is capable of.forward
- Normal comparator.public static <T> TableFormat<T> tableFormat(String[] propertyNames, String[] columnLabels)
TableFormat
that binds JavaBean properties to table columns via Reflection.propertyNames
- Names of properties index mapped into table.columnLabels
- Column names index mapped into table.BeanTableFormat
.public static <T> TableFormat<T> tableFormat(Class<T> baseClass, String[] propertyNames, String[] columnLabels)
TableFormat
that binds JavaBean properties to table columns via Reflection.baseClass
- the class of the Object to divide into columns. If specified, the returned
class will provide implementation of AdvancedTableFormat.getColumnClass(int)
and AdvancedTableFormat.getColumnComparator(int)
by examining the classes of
the column value.propertyNames
- Names of properties index mapped into table.
* @param columnLabels Column names index mapped into table.BeanTableFormat
.public static <T> TableFormat<T> tableFormat(String[] propertyNames, String[] columnLabels, boolean[] editable)
TableFormat
that binds JavaBean properties to table columns via Reflection.
The returned TableFormat
implements WritableTableFormat
and may be used for an
editable table.propertyNames
- Names of properties index mapped into table.columnLabels
- Column names index mapped into table.editable
- Index based mapping of which column is editable.BeanTableFormat
.public static <T> TableFormat<T> tableFormat(Class<T> baseClass, String[] propertyNames, String[] columnLabels, boolean[] editable)
TableFormat
that binds JavaBean properties to table columns via Reflection.
The returned TableFormat
implements WritableTableFormat
and may be used for an
editable table.baseClass
- the class of the Object to divide into columns. If specified, the returned
class will provide implementation of AdvancedTableFormat.getColumnClass(int)
and AdvancedTableFormat.getColumnComparator(int)
by examining the classes of
the column value.propertyNames
- See BeanTableFormat(Class, String[], String[], boolean[])
columnLabels
- See BeanTableFormat(Class, String[], String[], boolean[])
editable
- See BeanTableFormat(Class, String[], String[], boolean[])
BeanTableFormat
.public static <E> TextFilterator<E> textFilterator(String... propertyNames)
TextFilterator
that searches the given JavaBean properties.propertyNames
- See BeanTextFilterator(String...)
.BeanTextFilterator(String...)
.public static <E> TextFilterator<E> textFilterator(Class<E> beanClass, String... propertyNames)
TextFilterator
that searches the given JavaBean properties.E
- See BeanTextFilterator(Class, String...)
.beanClass
- See BeanTextFilterator(Class, String...)
.propertyNames
- See BeanTextFilterator(Class, String...)
.BeanTextFilterator(String...)
.public static <D,E> Filterator<D,E> filterator(String... propertyNames)
TextFilterator
that searches the given JavaBean properties.propertyNames
- See BeanTextFilterator(String...)
.BeanTextFilterator(String...)
.public static <D,E> Filterator<D,E> filterator(Class<E> beanClass, String... propertyNames)
TextFilterator
that searches the given JavaBean properties of the specified
class.E
- See BeanTextFilterator(Class, String...)
propertyNames
- See BeanTextFilterator(Class, String...)
BeanTextFilterator(Class, String...)
public static <E> TextFilterator<E> toStringTextFilterator()
TextFilterator
that searches against an Object's toString()
value.StringTextFilterator
.public static <E> ThresholdList.Evaluator<E> thresholdEvaluator(String propertyName)
ThresholdList.Evaluator
that uses Reflection to utilize an integer JavaBean
property as the threshold evaluation.propertyName
- See BeanThresholdEvaluator(String)
.BeanThresholdEvaluator(String)
.public static <E> CollectionList.Model<List<E>,E> listCollectionListModel()
CollectionList.Model
that where List
s or EventList
s are the
elements of a parent EventList
. This can be used to compose EventList
s from
other EventList
s.ListCollectionListModel
.public static <E> EventList<E> eventListOf(E... contents)
EventList
which contains the given elements.E
- Unified type of allowed objects.contents
- the list elements, if null
the result will be an empty listEventList
public static <E> EventList<E> eventList(Collection<? extends E> contents)
EventList
which contains the contents of the specified Collection
. The
EventList
's order will be determined by contents.iterator()
.E
- Unified type of allowed objects.contents
- the collection with list elements, if null
the result will be an
empty listEventList
.public static <E> EventList<E> eventListOf(ListEventPublisher publisher, ReadWriteLock lock, E... contents)
EventList
with the given ListEventPublisher
and
ReadWriteLock
which contains the given elements.E
- Unified type of allowed objects.publisher
- the ListEventPublisher
for the new list, may be null
lock
- the ReadWriteLock
for the new list, may be null
contents
- the list elements, if null
the result will be an empty listEventList
public static <E> EventList<E> eventList(ListEventPublisher publisher, ReadWriteLock lock, Collection<? extends E> contents)
EventList
with the given ListEventPublisher
and
ReadWriteLock
which contains the contents of the specified Collection
. The
EventList
's order will be determined by contents.iterator()
.publisher
- the ListEventPublisher
for the new list, may be null
lock
- the ReadWriteLock
for the new list, may be null
contents
- the collection with list elements, if null
the result will be an
empty listEventList
.public static <E> TransformedList<E,E> readOnlyList(EventList<? extends E> source)
EventList
that does not allow writing operations.
The returned EventList
is useful for programming defensively. A EventList
is
useful to supply an unknown class read-only access to your EventList
.
The returned EventList
will provides an up-to-date view of its source EventList
so changes to the source EventList
will still be reflected. For a static copy of any
EventList
it is necessary to copy the contents of that EventList
into an
ArrayList
.
Warning: This returned EventList is thread ready
but not thread safe. See EventList
for an example of thread safe code.
E
- Unified type of allowed objects.source
- Contents to wrap.ReadOnlyList
.public static <E> TransformedList<E,E> threadSafeList(EventList<? extends E> source)
EventList
that obtains a ReadWritLock
for
all operations.
This provides some support for sharing EventList
s between multiple threads.
Using a ThreadSafeList
for concurrent access to lists can be expensive because a
ReadWriteLock
is aquired and released for every operation.
Warning: Although this class provides thread safe
access, it does not provide any guarantees that changes will not happen between method calls.
For example, the following code is unsafe because the source EventList
may change
between calls to size()
and get()
:
EventList source = ... ThreadSafeList myList = new ThreadSafeList(source); if(myList.size() > 3) { System.out.println(myList.get(3)); }
Warning: The objects returned by
iterator()
, subList()
, etc. are not thread safe.
E
- Unified type of allowed objects.source
- The list to wrapTransformedList
.org.jadice.util.glazedlists.util.concurrent
public static <S,E> TransformedList<S,E> transformByFunction(EventList<S> source, FunctionList.Function<S,E> function)
TransformedList
that maps each element of the source list to a target element
by use of a specified FunctionList.Function
.
Warning: The returned EventList
is thread
ready but not thread safe. See EventList
for an example of thread safe code.
Warning:This method will not
return a full-featured FunctionList
, but a much simpler list implementation, that is
not writable.
S
- See FunctionList.Function
E
- See FunctionList.Function
source
- the source list to transformfunction
- the function to tranform each list elementTransformedList
that needs to be disposed after usepublic static <E> ListEventListener<E> weakReferenceProxy(EventList<E> source, ListEventListener<E> target)
This exists to solve a garbage collection problem. Suppose I have an EventList
L
and I obtain a ListIterator
for L. The ListIterator
must listen for
change events to L in order to be consistent. Therefore such an iterator will register
itself as a listener for L. When the iterator goes out of scope (as they usually do), it
will remain as a listener of L. This prevents the iterator object from ever being
garbage collected, though the iterator can never be never used again! Because iterators can be
used very frequently, this will cause an unacceptable memory leak.
Instead of adding the iterator directly as a listener for L, add a proxy instead. The
proxy will retain a WeakReference
to the iterator and forward events to the
iterator as long as it is reachable. When the iterator is no longer reachable, the proxy will
remove itself from the list of listeners for L. All garbage is then available for
collection.
E
- See ListEventListener
source
- See WeakReferenceProxy(EventList, ListEventListener)
target
- See WeakReferenceProxy(EventList, ListEventListener)
WeakReferenceProxy
WeakReference
public static <E> ObservableElementList.Connector<E> beanConnector(Class<E> beanClass)
ObservableElementList
that works with JavaBeans'
PropertyChangeListener
. The methods to add and remove listeners are detected
automatically by examining the bean class and searching for a method prefixed with "add" or
"remove" taking a single PropertyChangeListener
argument.E
- Class of typebeanClass
- a class with both addPropertyChangeListener(PropertyChangeListener)
and
removePropertyChangeListener(PropertyChangeListener)
, or similar methods.public static <E> ObservableElementList.Connector<E> beanConnector(Class<E> beanClass, boolean matchPropertyNames, String... propertyNames)
ObservableElementList
that works with JavaBeans'
PropertyChangeListener
. The methods to add and remove listeners are detected
automatically by examining the bean class and searching for a method prefixed with "add" or
"remove" taking a single PropertyChangeListener
argument.
Use this variant, if you want to control which PropertyChangeEvent
s are delivered to
the ObservableElementList. You can match or filter events by name.
If matchPropertyNames
is true
, the propertyNames
parameter specifies the set of properties by name whose PropertyChangeEvent
s should be
delivered to the ObservableElementList, e.g. property change events for properties not
contained in the specified propertyNames
are ignored in this case. If
matchPropertyNames
is false
, then the specified
propertyNames
are filtered, e.g. all but the specified property change events are
delivered to the ObservableElementList.
E
- Class of typebeanClass
- a class with both addPropertyChangeListener(PropertyChangeListener)
and
removePropertyChangeListener(PropertyChangeListener)
, or similar methods.matchPropertyNames
- if true
, match property change events against the
specified property names, if false
filter thempropertyNames
- specifies the properties by name whose PropertyChangeEvent
s should
be matched or filteredpublic static <E> ObservableElementList.Connector<E> beanConnector(Class<E> beanClass, Matcher<PropertyChangeEvent> eventMatcher)
ObservableElementList
that works with JavaBeans'
PropertyChangeListener
. The methods to add and remove listeners are detected
automatically by examining the bean class and searching for a method prefixed with "add" or
"remove" taking a single PropertyChangeListener
argument.
The event matcher allows filtering of PropertyChangeEvent
s. Only matching events are
delivered to the ObservableElementList. To create a matcher that matches PropertyChangeEvents
by property names, you can use Matchers.propertyEventNameMatcher(boolean, String[])
E
- Class of typebeanClass
- a class with both addPropertyChangeListener(PropertyChangeListener)
and
removePropertyChangeListener(PropertyChangeListener)
, or similar methods.eventMatcher
- for matching PropertyChangeEvents that will be delivered to the ObservableElementListpublic static <E> ObservableElementList.Connector<E> beanConnector(Class<E> beanClass, String addListener, String removeListener)
ObservableElementList
that works with JavaBeans'
PropertyChangeListener
. The methods to add and remove listeners are
specified by name. Such methods must take a single PropertyChangeListener
argument.E
- Class of typebeanClass
- a class with both methods as specified.addListener
- a method name such as "addPropertyChangeListener"removeListener
- a method name such as "removePropertyChangeListener"public static <E> ObservableElementList.Connector<E> beanConnector(Class<E> beanClass, String addListener, String removeListener, Matcher<PropertyChangeEvent> eventMatcher)
ObservableElementList
that works with JavaBeans'
PropertyChangeListener
. The methods to add and remove listeners are
specified by name. Such methods must take a single PropertyChangeListener
argument.
The event matcher allows filtering of PropertyChangeEvent
s. Only matching events are
delivered to the ObservableElementList. To create a matcher that matches PropertyChangeEvents
by property names, you can use Matchers.propertyEventNameMatcher(boolean, String[])
E
- Class of typebeanClass
- a class with both methods as specified.addListener
- a method name such as "addPropertyChangeListener"removeListener
- a method name such as "removePropertyChangeListener"eventMatcher
- for matching PropertyChangeEvents that will be delivered to the
ObservableElementListpublic static <E extends Observable> ObservableElementList.Connector<E> observableConnector()
ObservableElementList
that works with subclasses of the
archaic Observable
base class. Each element of the ObservableElementList
must extend the Observable base class.Observable
@Deprecated public static <E> Matcher<E> beanPropertyMatcher(Class<E> beanClass, String propertyName, Object value)
Matchers.beanPropertyMatcher(java.lang.Class<E>, java.lang.String, java.lang.Object)
. Matchers
is now the permanent factory
class which creates all basic Matcher implementations.propertyName
from instances of the given beanClass
and compare them
with the given value
.E
- Class of beanbeanClass
- the type of class containing the named bean propertypropertyName
- the name of the bean propertyvalue
- the value to compare with the bean propertytrue
if the named bean property equals the given value
public static <E> MatcherEditor<E> fixedMatcherEditor(Matcher<E> matcher)
MatcherEditor
that is fixed on the specified Matcher
.public static <E,V> FunctionList.Function<E,V> constantFunction(V value)
FunctionList.Function
that always returns the given value
, regardless of its
input.public static <E> FunctionList.Function<E,String> toStringFunction(Class<E> beanClass, String propertyName)
FunctionList.Function
that extracts the property with the given propertyName
from
objects of the given beanClass
and then formats the return value as a String.public static <E,V> FunctionList.Function<E,V> beanFunction(Class<E> beanClass, String propertyName)
FunctionList.Function
that extracts the property with the given propertyName
from
objects of the given beanClass
.public static <E> ListEventListener<E> syncEventListToList(EventList<E> source, List<E> target)
EventList
to the specified List
. Each time the
EventList
is changed, the changes are applied to the List
as well, so that the
two lists are always equal.
This is useful when a you need to support a List
datamodel but would prefer to
manipulate that List
with the convenience of EventList
s:
List someList = ...
// create an EventList with the contents of someList
EventList eventList = GlazedLists.eventList(someList);
// propagate changes from eventList to someList
GlazedLists.syncEventListToList(eventList, someList);
// test it out, should print "true, true, true true"
eventList.add("boston creme");
System.out.println(eventList.equals(someList));
eventList.add("crueller");
System.out.println(eventList.equals(someList));
eventList.remove("bostom creme");
System.out.println(eventList.equals(someList));
eventList.clear();
System.out.println(eventList.equals(someList));
source
- the EventList
which provides the master view. Each change to this
EventList
will be applied to the List
.target
- the List
to host a copy of the EventList
. This List
should not be changed after the lists have been synchronized. Otherwise a
RuntimeException
will be thrown when the drift is detected. This class must
support all mutating List
operations.ListEventListener
providing the link from the source EventList
to
the target List
. To stop the synchronization, use
EventList.removeListEventListener(ListEventListener)
.public static <E> ListEventListener<E> typeSafetyListener(EventList<E> source, Set<Class> types)
ListEventListener
. The ListEventListener
which is installed and returned to the
caller (which they may uninstall at their leisure) will throw an
IllegalArgumentException
if it detects the addition of an element with an unsupported
type.
This ListEventListener
is typically used as a tool to check invariants of the elements
of EventList
s during software development and testing phases.
E
- Type of objects in list.source
- the EventList
on which to provide type safetytypes
- the set of types to which each list element must be assignable - the set itself
must not be null
, but null
is an acceptable type within the set and
indicates the EventList
expects to contain null
elementsListEventListener
providing the safety checking on the given
source
. To stop the type safety checking, use
EventList.removeListEventListener(ListEventListener)
.public static <K extends Comparable,V> DisposableMap<K,List<V>> syncEventListToMultiMap(EventList<V> source, FunctionList.Function<V,? extends K> keyMaker)
EventList
to a MultiMap that is returned from this method.
Each time the EventList
is changed the MultiMap is updated to reflect the change.
This can be useful when it is known that an EventList
will experience very few
mutations compared to read operation and wants to provide a data structure that guarantees fast
O(1) reads.
The keys of the MultiMap are determined by evaluating each source
element with the
keyMaker
function. This form of the MultiMap requires that the keys produced by
the keyMaker
are Comparable
and that the natural ordering of those keys
also defines the grouping of values. If either of those assumptions are false, consider using
#syncEventListToMultiMap(EventList, Function, Comparator)
.
If two distinct values, say v1
and v2
each produce a common key,
k
, when they are evaluated by the keyMaker
function, then a
corresponding entry in the MultiMap will resemble:
k -> {v1, v2}
For example, assume the keyMaker
function returns the first letter of a name and
the source
EventList
contains the names:
{"Andy", "Arthur", "Jesse", "Holger", "James"}
The MultiMap returned by this method would thus resemble:
"A" -> {"Andy", "Arthur"}
"H" -> {"Holger"}
"J" -> {"Jesse", "James"}
It is important to note that all mutating methods on the Map
interface "write through"
to the backing EventList
as expected. These mutating methods include:
Map.keySet()
and its Iterator
Map.values()
and its Iterator
Map.entrySet()
and its Iterator
Map.Entry#setValue
method
Map
itself, including Map.put(K, V)
, Map.putAll(java.util.Map<? extends K, ? extends V>)
,
Map.remove(java.lang.Object)
, and Map.clear()
For information on MultiMaps go here.
K
- Type of key.V
- Type of value.source
- the EventList
which provides the master view. Each change to this EventList
will be
applied to the MultiMapkeyMaker
- the FunctionList.Function
which produces a key for each value in the source
. It is
imperative that the keyMaker produce immutable objects.source
EventList
public static <K,V> DisposableMap<K,List<V>> syncEventListToMultiMap(EventList<V> source, FunctionList.Function<V,? extends K> keyMaker, Comparator<? super K> keyGrouper)
EventList
to a MultiMap that is returned from this method.
Each time the EventList
is changed the MultiMap is updated to reflect the change.
This can be useful when it is known that an EventList
will experience very few
mutations compared to read operation and wants to provide a data structure that guarantees fast
O(1) reads.
The keys of the MultiMap are determined by evaluating each source
element with the
keyMaker
function. This form of the MultiMap makes no assumptions about the keys
of the MultiMap and relies on the given keyGrouper
to define the grouping of
values.
If two distinct values, say v1
and v2
each produce a common key,
k
, when they are evaluated by the keyMaker
function, then a
corresponding entry in the MultiMap will resemble:
k -> {v1, v2}
For example, assume the keyMaker
function returns the first letter of a name and
the source
EventList
contains the names:
{"Andy", "Arthur", "Jesse", "Holger", "James"}
The MultiMap returned by this method would thus resemble:
"A" -> {"Andy", "Arthur"}
"H" -> {"Holger"}
"J" -> {"Jesse", "James"}
It is important to note that all mutating methods on the Map
interface "write through"
to the backing EventList
as expected. These mutating methods include:
Map.keySet()
and its Iterator
Map.values()
and its Iterator
Map.entrySet()
and its Iterator
Map.Entry#setValue
method
Map
itself, including Map.put(K, V)
, Map.putAll(java.util.Map<? extends K, ? extends V>)
,
Map.remove(java.lang.Object)
, and Map.clear()
For information on MultiMaps go here.
K
- Type of key.V
- Type of value.source
- the EventList
which provides the master view. Each change to this
EventList
will be applied to the MultiMapkeyMaker
- the FunctionList.Function
which produces a key for each value in the
source
. It is imperative that the keyMaker produce
immutable objects.keyGrouper
- the Comparator
which groups together values that share common keyssource
EventList
public static <K,V> DisposableMap<K,V> syncEventListToMap(EventList<V> source, FunctionList.Function<V,K> keyMaker)
EventList
to a Map that is returned from this method. Each
time the EventList
is changed the Map is updated to reflect the change.
This can be useful when it is known that an EventList
will experience very few
mutations compared to read operation and wants to provide a data structure that guarantees fast
O(1) reads.
The keys of the Map are determined by evaluating each source
element with the
keyMaker
function. The Map implementation assumes that each value has a unique
key, and verifies this invariant at runtime, throwing a RuntimeException if it is ever
violated.
For example, if two distinct values, say v1
and v2
each produce the
key k
when they are evaluated by the keyMaker
function, an
IllegalStateException
is thrown to proactively indicate the error.
As for example of normal usage, assume the keyMaker
function returns the first
letter of a name and the source
EventList
contains the names:
{"Kevin", "Jesse", "Holger"}
The Map returned by this method would thus resemble:
"K" -> "Kevin"
"J" -> "Jesse"
"H" -> "Holger"
It is important to note that all mutating methods on the Map
interface "write through"
to the backing EventList
as expected. These mutating methods include:
Map.keySet()
and its Iterator
Map.values()
and its Iterator
Map.entrySet()
and its Iterator
Map.Entry#setValue
method
K
- Type of key.V
- Type of value.source
- the EventList
which provides the values of the map. Each change to this
EventList
will be applied to the Map.keyMaker
- the FunctionList.Function
which produces a key for each value in the
source
. It is imperative that the keyMaker produce
immutable objects.source
EventList
Copyright © 2024 levigo holding gmbh. All rights reserved.