Class GlazedLists
- java.lang.Object
-
- ca.odell.glazedlists.GlazedLists
-
public final class GlazedLists extends java.lang.ObjectA factory for creating all sorts of objects to be used with Glazed Lists.- Author:
- Jesse Wilson
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <E> ObservableElementList.Connector<E>beanConnector(java.lang.Class<E> beanClass)Create a new Connector for theObservableElementListthat works with JavaBeans'PropertyChangeListener.static <E> ObservableElementList.Connector<E>beanConnector(java.lang.Class<E> beanClass, boolean matchPropertyNames, java.lang.String... propertyNames)Create a new Connector for theObservableElementListthat works with JavaBeans'PropertyChangeListener.static <E> ObservableElementList.Connector<E>beanConnector(java.lang.Class<E> beanClass, Matcher<java.beans.PropertyChangeEvent> eventMatcher)Create a new Connector for theObservableElementListthat works with JavaBeans'PropertyChangeListener.static <E> ObservableElementList.Connector<E>beanConnector(java.lang.Class<E> beanClass, java.lang.String addListener, java.lang.String removeListener)Create a new Connector for theObservableElementListthat works with JavaBeans'PropertyChangeListener.static <E> ObservableElementList.Connector<E>beanConnector(java.lang.Class<E> beanClass, java.lang.String addListener, java.lang.String removeListener, Matcher<java.beans.PropertyChangeEvent> eventMatcher)Create a new Connector for theObservableElementListthat works with JavaBeans'PropertyChangeListener.static <E,V>
FunctionList.Function<E,V>beanFunction(java.lang.Class<E> beanClass, java.lang.String propertyName)Get aFunctionList.Functionthat extracts the property with the givenpropertyNamefrom objects of the givenbeanClass.static <T> java.util.Comparator<T>beanPropertyComparator(java.lang.Class<T> clazz, java.lang.String property, java.lang.String... properties)Creates aComparatorthat uses Reflection to compare two instances of the specifiedClassby the given JavaBean properties.static <T> java.util.Comparator<T>beanPropertyComparator(java.lang.Class<T> className, java.lang.String property, java.util.Comparator propertyComparator)Creates aComparatorthat uses Reflection to compare two instances of the specifiedClassby the given JavaBean property.static <E> Matcher<E>beanPropertyMatcher(java.lang.Class<E> beanClass, java.lang.String propertyName, java.lang.Object value)Deprecated.as of 3/3/2006 - this method has been replaced byMatchers.beanPropertyMatcher(java.lang.Class<E>, java.lang.String, java.lang.Object).static java.util.Comparator<java.lang.Boolean>booleanComparator()Creates aComparatorfor use withBooleanobjects.static java.util.Comparator<java.lang.String>caseInsensitiveComparator()Creates aComparatorthat comparesStringobjects in a case-insensitive way.static <T> java.util.Comparator<T>chainComparators(java.util.Comparator<T>... comparators)Creates a chain ofComparators that applies the providedComparators in the sequence specified until differences or absolute equality is determined.static <T> java.util.Comparator<T>chainComparators(java.util.List<java.util.Comparator<T>> comparators)Creates a chain ofComparators that applies the providedComparators in the sequence specified until differences or absolute equality is determined.static <T extends java.lang.Comparable>
java.util.Comparator<T>comparableComparator()Creates aComparatorthat comparesComparableobjects.static <E,V>
FunctionList.Function<E,V>constantFunction(V value)Get aFunctionList.Functionthat always returns the givenvalue, regardless of its input.static <E> EventList<E>eventList(ListEventPublisher publisher, ReadWriteLock lock, java.util.Collection<? extends E> contents)Creates a newEventListwith the givenListEventPublisherandReadWriteLockwhich contains the contents of the specifiedCollection.static <E> EventList<E>eventList(java.util.Collection<? extends E> contents)Creates a newEventListwhich contains the contents of the specifiedCollection.static <E> EventList<E>eventListOf(ListEventPublisher publisher, ReadWriteLock lock, E... contents)Creates a newEventListwith the givenListEventPublisherandReadWriteLockwhich contains the given elements.static <E> EventList<E>eventListOf(E... contents)Creates a newEventListwhich contains the given elements.static <D,E>
Filterator<D,E>filterator(java.lang.Class<E> beanClass, java.lang.String... propertyNames)Creates aTextFilteratorthat searches the given JavaBean properties of the specified class.static <D,E>
Filterator<D,E>filterator(java.lang.String... propertyNames)Creates aTextFilteratorthat searches the given JavaBean properties.static <E> MatcherEditor<E>fixedMatcherEditor(Matcher<E> matcher)Get aMatcherEditorthat is fixed on the specifiedMatcher.static <E> CollectionList.Model<java.util.List<E>,E>listCollectionListModel()Creates aCollectionList.Modelthat whereLists orEventLists are the elements of a parentEventList.static <E extends java.util.Observable>
ObservableElementList.Connector<E>observableConnector()Create a new Connector for theObservableElementListthat works with subclasses of the archaicObservablebase class.static <E> TransformedList<E,E>readOnlyList(EventList<? extends E> source)Wraps the source in anEventListthat does not allow writing operations.static <E> voidreplaceAll(EventList<E> target, java.util.List<E> source, boolean updates)static <E> voidreplaceAll(EventList<E> target, java.util.List<E> source, boolean updates, java.util.Comparator<E> comparator)Overloaded version ofreplaceAll(EventList,List,boolean)that uses aComparatorto determine equality rather thanequals().static <E> voidreplaceAllSorted(EventList<E> target, java.util.Collection<E> source, boolean updates, java.util.Comparator<E> comparator)Replace the complete contents of the targetEventListwith the complete contents of the sourceCollectionwhile making as few list changes as possible.static <T extends java.lang.Comparable>
java.util.Comparator<T>reverseComparator()Creates a reverseComparatorthat works forComparableobjects.static <T> java.util.Comparator<T>reverseComparator(java.util.Comparator<T> forward)Creates a reverseComparatorthat inverts the givenComparator.static <E> ListEventListener<E>syncEventListToList(EventList<E> source, java.util.List<E> target)Synchronize the specifiedEventListto the specifiedList.static <K,V>
DisposableMap<K,V>syncEventListToMap(EventList<V> source, FunctionList.Function<V,K> keyMaker)Synchronize the specifiedEventListto a Map that is returned from this method.static <K extends java.lang.Comparable,V>
DisposableMap<K,java.util.List<V>>syncEventListToMultiMap(EventList<V> source, FunctionList.Function<V,? extends K> keyMaker)Synchronize the specifiedEventListto a MultiMap that is returned from this method.static <K,V>
DisposableMap<K,java.util.List<V>>syncEventListToMultiMap(EventList<V> source, FunctionList.Function<V,? extends K> keyMaker, java.util.Comparator<? super K> keyGrouper)Synchronize the specifiedEventListto a MultiMap that is returned from this method.static <T> TableFormat<T>tableFormat(java.lang.Class<T> baseClass, java.lang.String[] propertyNames, java.lang.String[] columnLabels)Creates aTableFormatthat binds JavaBean properties to table columns via Reflection.static <T> TableFormat<T>tableFormat(java.lang.Class<T> baseClass, java.lang.String[] propertyNames, java.lang.String[] columnLabels, boolean[] editable)Creates aTableFormatthat binds JavaBean properties to table columns via Reflection.static <T> TableFormat<T>tableFormat(java.lang.String[] propertyNames, java.lang.String[] columnLabels)Creates aTableFormatthat binds JavaBean properties to table columns via Reflection.static <T> TableFormat<T>tableFormat(java.lang.String[] propertyNames, java.lang.String[] columnLabels, boolean[] editable)Creates aTableFormatthat binds JavaBean properties to table columns via Reflection.static <E> TextFilterator<E>textFilterator(java.lang.Class<E> beanClass, java.lang.String... propertyNames)Creates aTextFilteratorthat searches the given JavaBean properties.static <E> TextFilterator<E>textFilterator(java.lang.String... propertyNames)Creates aTextFilteratorthat searches the given JavaBean properties.static <E> TransformedList<E,E>threadSafeList(EventList<? extends E> source)Wraps the source in anEventListthat obtains aReadWritLockfor all operations.static <E> ThresholdList.Evaluator<E>thresholdEvaluator(java.lang.String propertyName)Creates aThresholdList.Evaluatorthat uses Reflection to utilize an integer JavaBean property as the threshold evaluation.static <E> FunctionList.Function<E,java.lang.String>toStringFunction(java.lang.Class<E> beanClass, java.lang.String propertyName)Get aFunctionList.Functionthat extracts the property with the givenpropertyNamefrom objects of the givenbeanClassand then formats the return value as a String.static <E> TextFilterator<E>toStringTextFilterator()Creates aTextFilteratorthat searches against an Object'stoString()value.static <S,E>
TransformedList<S,E>transformByFunction(EventList<S> source, FunctionList.Function<S,E> function)Returns aTransformedListthat maps each element of the source list to a target element by use of a specifiedFunctionList.Function.static <E> ListEventListener<E>typeSafetyListener(EventList<E> source, java.util.Set<java.lang.Class> types)Check list elements for type safety after they are added to an EventList using aListEventListener.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.
-
-
-
Method Detail
-
replaceAll
public static <E> void replaceAll(EventList<E> target, java.util.List<E> source, boolean updates)
Replace the complete contents of the targetEventListwith the complete contents of the sourceEventListwhile 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
sortedversion of replaceAll.- Parameters:
updates- whether to fire update events for Objects that are equal in bothLists.
-
replaceAll
public static <E> void replaceAll(EventList<E> target, java.util.List<E> source, boolean updates, java.util.Comparator<E> comparator)
Overloaded version ofreplaceAll(EventList,List,boolean)that uses aComparatorto determine equality rather thanequals().- Parameters:
comparator- theComparatorto determine equality between elements. ThisComparatormust return0for elements that are equal and nonzero for elements that are not equal. Sort order is not used.
-
replaceAllSorted
public static <E> void replaceAllSorted(EventList<E> target, java.util.Collection<E> source, boolean updates, java.util.Comparator<E> comparator)
Replace the complete contents of the targetEventListwith the complete contents of the sourceCollectionwhile making as few list changes as possible.Unlike the
generalversions of this method, the sorted version requires that both the input and the output are sorted collections, and that they're sorted with theComparatorspecified. If they're sorted innaturalorder, usecomparableComparator().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
generalversion of replaceAll.- Parameters:
target- an EventList sorted with theComparatorspecified. Its contents will be replaced with those insource.source- a collection sorted with theComparatorspecified.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. Ifnull, thecomparableComparatorwill be used, which means that all elements must implementComparable.updates- whether to fire update events for Objects that are equal in bothLists.- See Also:
Collections.sort(java.util.List<T>),SortedSet
-
beanPropertyComparator
public static <T> java.util.Comparator<T> beanPropertyComparator(java.lang.Class<T> clazz, java.lang.String property, java.lang.String... properties)Creates aComparatorthat uses Reflection to compare two instances of the specifiedClassby the given JavaBean properties. The JavaBeanpropertyand any extrapropertiesmust implementComparable.The following example code sorts a List of Customers by first name, with ties broken by last name.
Listcustomers = ... Comparator comparator = GlazedLists.beanPropertyComparator(Customer.class, "firstName", "lastName"); Collections.sort(customers, comparator); - Parameters:
clazz- the name of the class which defines the accessor method for the givenpropertyand optionalypropertiesproperty- the name of the first Comparable property to be extracted and used to compare instances of theclazzproperties- the name of optional Comparable properties, each of which is used to break ties for the prior property.
-
beanPropertyComparator
public static <T> java.util.Comparator<T> beanPropertyComparator(java.lang.Class<T> className, java.lang.String property, java.util.Comparator propertyComparator)Creates aComparatorthat uses Reflection to compare two instances of the specifiedClassby the given JavaBean property. The JavaBean property is compared using the providedComparator.
-
booleanComparator
public static java.util.Comparator<java.lang.Boolean> booleanComparator()
Creates aComparatorfor use withBooleanobjects.
-
caseInsensitiveComparator
public static java.util.Comparator<java.lang.String> caseInsensitiveComparator()
Creates aComparatorthat comparesStringobjects in a case-insensitive way. ThisComparatoris equivalent to usingString.CASE_INSENSITIVE_ORDERand exists here for convenience.
-
chainComparators
public static <T> java.util.Comparator<T> chainComparators(java.util.List<java.util.Comparator<T>> comparators)
Creates a chain ofComparators that applies the providedComparators in the sequence specified until differences or absolute equality is determined.
-
chainComparators
public static <T> java.util.Comparator<T> chainComparators(java.util.Comparator<T>... comparators)
Creates a chain ofComparators that applies the providedComparators in the sequence specified until differences or absolute equality is determined.
-
comparableComparator
public static <T extends java.lang.Comparable> java.util.Comparator<T> comparableComparator()
Creates aComparatorthat comparesComparableobjects.
-
reverseComparator
public static <T extends java.lang.Comparable> java.util.Comparator<T> reverseComparator()
Creates a reverseComparatorthat works forComparableobjects.
-
reverseComparator
public static <T> java.util.Comparator<T> reverseComparator(java.util.Comparator<T> forward)
Creates a reverseComparatorthat inverts the givenComparator.
-
tableFormat
public static <T> TableFormat<T> tableFormat(java.lang.String[] propertyNames, java.lang.String[] columnLabels)
Creates aTableFormatthat binds JavaBean properties to table columns via Reflection.
-
tableFormat
public static <T> TableFormat<T> tableFormat(java.lang.Class<T> baseClass, java.lang.String[] propertyNames, java.lang.String[] columnLabels)
Creates aTableFormatthat binds JavaBean properties to table columns via Reflection.- Parameters:
baseClass- the class of the Object to divide into columns. If specified, the returned class will provide implementation ofAdvancedTableFormat.getColumnClass(int)andAdvancedTableFormat.getColumnComparator(int)by examining the classes of the column value.
-
tableFormat
public static <T> TableFormat<T> tableFormat(java.lang.String[] propertyNames, java.lang.String[] columnLabels, boolean[] editable)
Creates aTableFormatthat binds JavaBean properties to table columns via Reflection. The returnedTableFormatimplementsWritableTableFormatand may be used for an editable table.
-
tableFormat
public static <T> TableFormat<T> tableFormat(java.lang.Class<T> baseClass, java.lang.String[] propertyNames, java.lang.String[] columnLabels, boolean[] editable)
Creates aTableFormatthat binds JavaBean properties to table columns via Reflection. The returnedTableFormatimplementsWritableTableFormatand may be used for an editable table.- Parameters:
baseClass- the class of the Object to divide into columns. If specified, the returned class will provide implementation ofAdvancedTableFormat.getColumnClass(int)andAdvancedTableFormat.getColumnComparator(int)by examining the classes of the column value.
-
textFilterator
public static <E> TextFilterator<E> textFilterator(java.lang.String... propertyNames)
Creates aTextFilteratorthat searches the given JavaBean properties.
-
textFilterator
public static <E> TextFilterator<E> textFilterator(java.lang.Class<E> beanClass, java.lang.String... propertyNames)
Creates aTextFilteratorthat searches the given JavaBean properties.
-
filterator
public static <D,E> Filterator<D,E> filterator(java.lang.String... propertyNames)
Creates aTextFilteratorthat searches the given JavaBean properties.
-
filterator
public static <D,E> Filterator<D,E> filterator(java.lang.Class<E> beanClass, java.lang.String... propertyNames)
Creates aTextFilteratorthat searches the given JavaBean properties of the specified class.
-
toStringTextFilterator
public static <E> TextFilterator<E> toStringTextFilterator()
Creates aTextFilteratorthat searches against an Object'stoString()value.
-
thresholdEvaluator
public static <E> ThresholdList.Evaluator<E> thresholdEvaluator(java.lang.String propertyName)
Creates aThresholdList.Evaluatorthat uses Reflection to utilize an integer JavaBean property as the threshold evaluation.
-
listCollectionListModel
public static <E> CollectionList.Model<java.util.List<E>,E> listCollectionListModel()
Creates aCollectionList.Modelthat whereLists orEventLists are the elements of a parentEventList. This can be used to composeEventLists from otherEventLists.
-
eventListOf
public static <E> EventList<E> eventListOf(E... contents)
Creates a newEventListwhich contains the given elements.- Parameters:
contents- the list elements, ifnullthe result will be an empty list- Returns:
- the new
EventList
-
eventList
public static <E> EventList<E> eventList(java.util.Collection<? extends E> contents)
Creates a newEventListwhich contains the contents of the specifiedCollection. TheEventList's order will be determined bycontents.iterator().- Parameters:
contents- the collection with list elements, ifnullthe result will be an empty list
-
eventListOf
public static <E> EventList<E> eventListOf(ListEventPublisher publisher, ReadWriteLock lock, E... contents)
Creates a newEventListwith the givenListEventPublisherandReadWriteLockwhich contains the given elements.- Parameters:
publisher- theListEventPublisherfor the new list, may benulllock- theReadWriteLockfor the new list, may benullcontents- the list elements, ifnullthe result will be an empty list- Returns:
- the new
EventList
-
eventList
public static <E> EventList<E> eventList(ListEventPublisher publisher, ReadWriteLock lock, java.util.Collection<? extends E> contents)
Creates a newEventListwith the givenListEventPublisherandReadWriteLockwhich contains the contents of the specifiedCollection. TheEventList's order will be determined bycontents.iterator().- Parameters:
publisher- theListEventPublisherfor the new list, may benulllock- theReadWriteLockfor the new list, may benullcontents- the collection with list elements, ifnullthe result will be an empty list
-
readOnlyList
public static <E> TransformedList<E,E> readOnlyList(EventList<? extends E> source)
Wraps the source in anEventListthat does not allow writing operations.The returned
EventListis useful for programming defensively. AEventListis useful to supply an unknown class read-only access to yourEventList.The returned
EventListwill provides an up-to-date view of its sourceEventListso changes to the sourceEventListwill still be reflected. For a static copy of anyEventListit is necessary to copy the contents of thatEventListinto anArrayList.Warning: This returned EventList is thread ready but not thread safe. See
EventListfor an example of thread safe code.
-
threadSafeList
public static <E> TransformedList<E,E> threadSafeList(EventList<? extends E> source)
Wraps the source in anEventListthat obtains aReadWritLockfor all operations.This provides some support for sharing
EventLists between multiple threads.Using a
ThreadSafeListfor concurrent access to lists can be expensive because aReadWriteLockis 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
EventListmay change between calls tosize()andget():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.- See Also:
ca.odell.glazedlists.util.concurrent
-
transformByFunction
public static <S,E> TransformedList<S,E> transformByFunction(EventList<S> source, FunctionList.Function<S,E> function)
Returns aTransformedListthat maps each element of the source list to a target element by use of a specifiedFunctionList.Function.Warning: The returned
EventListis thread ready but not thread safe. SeeEventListfor 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.- Parameters:
source- the source list to transformfunction- the function to tranform each list element- Returns:
- a
TransformedListthat needs to be disposed after use
-
weakReferenceProxy
public 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.This exists to solve a garbage collection problem. Suppose I have an
EventListL and I obtain aListIteratorfor L. TheListIteratormust 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
WeakReferenceto 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.- See Also:
WeakReference
-
beanConnector
public static <E> ObservableElementList.Connector<E> beanConnector(java.lang.Class<E> beanClass)
Create a new Connector for theObservableElementListthat 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 singlePropertyChangeListenerargument.- Parameters:
beanClass- a class with bothaddPropertyChangeListener(PropertyChangeListener)andremovePropertyChangeListener(PropertyChangeListener), or similar methods.- Returns:
- an ObservableElementList.Connector for the specified class
-
beanConnector
public static <E> ObservableElementList.Connector<E> beanConnector(java.lang.Class<E> beanClass, boolean matchPropertyNames, java.lang.String... propertyNames)
Create a new Connector for theObservableElementListthat 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 singlePropertyChangeListenerargument.Use this variant, if you want to control which
PropertyChangeEvents are delivered to the ObservableElementList. You can match or filter events by name.If
matchPropertyNamesistrue, thepropertyNamesparameter specifies the set of properties by name whosePropertyChangeEvents should be delivered to the ObservableElementList, e.g. property change events for properties not contained in the specifiedpropertyNamesare ignored in this case. IfmatchPropertyNamesisfalse, then the specifiedpropertyNamesare filtered, e.g. all but the specified property change events are delivered to the ObservableElementList.- Parameters:
beanClass- a class with bothaddPropertyChangeListener(PropertyChangeListener)andremovePropertyChangeListener(PropertyChangeListener), or similar methods.matchPropertyNames- iftrue, match property change events against the specified property names, iffalsefilter thempropertyNames- specifies the properties by name whosePropertyChangeEvents should be matched or filtered- Returns:
- an ObservableElementList.Connector for the specified class
-
beanConnector
public static <E> ObservableElementList.Connector<E> beanConnector(java.lang.Class<E> beanClass, Matcher<java.beans.PropertyChangeEvent> eventMatcher)
Create a new Connector for theObservableElementListthat 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 singlePropertyChangeListenerargument.The event matcher allows filtering of
PropertyChangeEvents. Only matching events are delivered to the ObservableElementList. To create a matcher that matches PropertyChangeEvents by property names, you can useMatchers.propertyEventNameMatcher(boolean, String[])- Parameters:
beanClass- a class with bothaddPropertyChangeListener(PropertyChangeListener)andremovePropertyChangeListener(PropertyChangeListener), or similar methods.eventMatcher- for matching PropertyChangeEvents that will be delivered to the ObservableElementList- Returns:
- an ObservableElementList.Connector for the specified class
-
beanConnector
public static <E> ObservableElementList.Connector<E> beanConnector(java.lang.Class<E> beanClass, java.lang.String addListener, java.lang.String removeListener)
Create a new Connector for theObservableElementListthat works with JavaBeans'PropertyChangeListener. The methods to add and remove listeners are specified by name. Such methods must take a singlePropertyChangeListenerargument.- Parameters:
beanClass- a class with both methods as specified.addListener- a method name such as "addPropertyChangeListener"removeListener- a method name such as "removePropertyChangeListener"- Returns:
- an ObservableElementList.Connector for the specified class
-
beanConnector
public static <E> ObservableElementList.Connector<E> beanConnector(java.lang.Class<E> beanClass, java.lang.String addListener, java.lang.String removeListener, Matcher<java.beans.PropertyChangeEvent> eventMatcher)
Create a new Connector for theObservableElementListthat works with JavaBeans'PropertyChangeListener. The methods to add and remove listeners are specified by name. Such methods must take a singlePropertyChangeListenerargument.The event matcher allows filtering of
PropertyChangeEvents. Only matching events are delivered to the ObservableElementList. To create a matcher that matches PropertyChangeEvents by property names, you can useMatchers.propertyEventNameMatcher(boolean, String[])- Parameters:
beanClass- 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 ObservableElementList- Returns:
- an ObservableElementList.Connector for the specified class
-
observableConnector
public static <E extends java.util.Observable> ObservableElementList.Connector<E> observableConnector()
Create a new Connector for theObservableElementListthat works with subclasses of the archaicObservablebase class. Each element of the ObservableElementList must extend the Observable base class.- Returns:
- an ObservableElementList.Connector for objects that extend
Observable
-
beanPropertyMatcher
public static <E> Matcher<E> beanPropertyMatcher(java.lang.Class<E> beanClass, java.lang.String propertyName, java.lang.Object value)
Deprecated.as of 3/3/2006 - this method has been replaced byMatchers.beanPropertyMatcher(java.lang.Class<E>, java.lang.String, java.lang.Object).Matchersis now the permanent factory class which creates all basic Matcher implementations.Create a new Matcher which uses reflection to read properties with the givenpropertyNamefrom instances of the givenbeanClassand compare them with the givenvalue.- Parameters:
beanClass- the type of class containing the named bean propertypropertyName- the name of the bean propertyvalue- the value to compare with the bean property- Returns:
- true if the named bean property equals the given
value
-
fixedMatcherEditor
public static <E> MatcherEditor<E> fixedMatcherEditor(Matcher<E> matcher)
Get aMatcherEditorthat is fixed on the specifiedMatcher.
-
constantFunction
public static <E,V> FunctionList.Function<E,V> constantFunction(V value)
Get aFunctionList.Functionthat always returns the givenvalue, regardless of its input.
-
toStringFunction
public static <E> FunctionList.Function<E,java.lang.String> toStringFunction(java.lang.Class<E> beanClass, java.lang.String propertyName)
Get aFunctionList.Functionthat extracts the property with the givenpropertyNamefrom objects of the givenbeanClassand then formats the return value as a String.
-
beanFunction
public static <E,V> FunctionList.Function<E,V> beanFunction(java.lang.Class<E> beanClass, java.lang.String propertyName)
Get aFunctionList.Functionthat extracts the property with the givenpropertyNamefrom objects of the givenbeanClass.
-
syncEventListToList
public static <E> ListEventListener<E> syncEventListToList(EventList<E> source, java.util.List<E> target)
Synchronize the specifiedEventListto the specifiedList. Each time theEventListis changed, the changes are applied to theListas well, so that the two lists are always equal.This is useful when a you need to support a
Listdatamodel but would prefer to manipulate thatListwith the convenience ofEventLists: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));- Parameters:
source- theEventListwhich provides the master view. Each change to thisEventListwill be applied to theList.target- theListto host a copy of theEventList. ThisListshould not be changed after the lists have been synchronized. Otherwise aRuntimeExceptionwill be thrown when the drift is detected. This class must support all mutatingListoperations.- Returns:
- the
ListEventListenerproviding the link from the sourceEventListto the targetList. To stop the synchronization, useEventList.removeListEventListener(ListEventListener).
-
typeSafetyListener
public static <E> ListEventListener<E> typeSafetyListener(EventList<E> source, java.util.Set<java.lang.Class> types)
Check list elements for type safety after they are added to an EventList using aListEventListener. TheListEventListenerwhich is installed and returned to the caller (which they may uninstall at their leisure) will throw anIllegalArgumentExceptionif it detects the addition of an element with an unsupported type.This
ListEventListeneris typically used as a tool to check invariants of the elements ofEventLists during software development and testing phases.- Parameters:
source- theEventListon 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 theEventListexpects to contain null elements- Returns:
- the
ListEventListenerproviding the safety checking on the givensource. To stop the type safety checking, useEventList.removeListEventListener(ListEventListener).
-
syncEventListToMultiMap
public static <K extends java.lang.Comparable,V> DisposableMap<K,java.util.List<V>> syncEventListToMultiMap(EventList<V> source, FunctionList.Function<V,? extends K> keyMaker)
Synchronize the specifiedEventListto a MultiMap that is returned from this method. Each time theEventListis changed the MultiMap is updated to reflect the change.This can be useful when it is known that an
EventListwill 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
sourceelement with thekeyMakerfunction. This form of the MultiMap requires that the keys produced by thekeyMakerareComparableand that the natural ordering of those keys also defines the grouping of values. If either of those assumptions are false, consider usingsyncEventListToMultiMap(EventList, FunctionList.Function, Comparator).If two distinct values, say
v1andv2each produce a common key,k, when they are evaluated by thekeyMakerfunction, then a corresponding entry in the MultiMap will resemble:k -> {v1, v2}For example, assume the
keyMakerfunction returns the first letter of a name and thesourceEventListcontains 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
Mapinterface "write through" to the backingEventListas expected. These mutating methods include:- the mutating methods of
Map.keySet()and itsIterator - the mutating methods of
Map.values()and itsIterator - the mutating methods of
Map.entrySet()and itsIterator - the
Map.Entry.setValue(V)method - the mutating methods of
Mapitself, includingMap.put(K, V),Map.putAll(java.util.Map<? extends K, ? extends V>),Map.remove(java.lang.Object), andMap.clear()
- Parameters:
source- theEventListwhich provides the master view. Each change to thisEventListwill be applied to the MultiMapkeyMaker- theFunctionList.Functionwhich produces a key for each value in thesource. It is imperative that the keyMaker produce immutable objects.- Returns:
- a MultiMap which remains in sync with changes that occur to the
underlying
sourceEventList
- the mutating methods of
-
syncEventListToMultiMap
public static <K,V> DisposableMap<K,java.util.List<V>> syncEventListToMultiMap(EventList<V> source, FunctionList.Function<V,? extends K> keyMaker, java.util.Comparator<? super K> keyGrouper)
Synchronize the specifiedEventListto a MultiMap that is returned from this method. Each time theEventListis changed the MultiMap is updated to reflect the change.This can be useful when it is known that an
EventListwill 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
sourceelement with thekeyMakerfunction. This form of the MultiMap makes no assumptions about the keys of the MultiMap and relies on the givenkeyGrouperto define the grouping of values.If two distinct values, say
v1andv2each produce a common key,k, when they are evaluated by thekeyMakerfunction, then a corresponding entry in the MultiMap will resemble:k -> {v1, v2}For example, assume the
keyMakerfunction returns the first letter of a name and thesourceEventListcontains 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
Mapinterface "write through" to the backingEventListas expected. These mutating methods include:- the mutating methods of
Map.keySet()and itsIterator - the mutating methods of
Map.values()and itsIterator - the mutating methods of
Map.entrySet()and itsIterator - the
Map.Entry.setValue(V)method - the mutating methods of
Mapitself, includingMap.put(K, V),Map.putAll(java.util.Map<? extends K, ? extends V>),Map.remove(java.lang.Object), andMap.clear()
- Parameters:
source- theEventListwhich provides the master view. Each change to thisEventListwill be applied to the MultiMapkeyMaker- theFunctionList.Functionwhich produces a key for each value in thesource. It is imperative that the keyMaker produce immutable objects.keyGrouper- theComparatorwhich groups together values that share common keys- Returns:
- a MultiMap which remains in sync with changes that occur to the
underlying
sourceEventList
- the mutating methods of
-
syncEventListToMap
public static <K,V> DisposableMap<K,V> syncEventListToMap(EventList<V> source, FunctionList.Function<V,K> keyMaker)
Synchronize the specifiedEventListto a Map that is returned from this method. Each time theEventListis changed the Map is updated to reflect the change.This can be useful when it is known that an
EventListwill 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
sourceelement with thekeyMakerfunction. 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, sayv1andv2each produce the keykwhen they are evaluated by thekeyMakerfunction, anIllegalStateExceptionis thrown to proactively indicate the error.As for example of normal usage, assume the
keyMakerfunction returns the first letter of a name and thesourceEventListcontains 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
Mapinterface "write through" to the backingEventListas expected. These mutating methods include:- the mutating methods of
Map.keySet()and itsIterator - the mutating methods of
Map.values()and itsIterator - the mutating methods of
Map.entrySet()and itsIterator - the
Map.Entry.setValue(V)method
- Parameters:
source- theEventListwhich provides the values of the map. Each change to thisEventListwill be applied to the Map.keyMaker- theFunctionList.Functionwhich produces a key for each value in thesource. It is imperative that the keyMaker produce immutable objects.- Returns:
- a Map which remains in sync with changes that occur to the
underlying
sourceEventList
- the mutating methods of
-
-