Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Glazed Lists (c) 2003-2006 */
/* http://publicobject.com/glazedlists/ publicobject.com,*/
/* O'Dell Engineering Ltd.*/
package ca.odell.glazedlists;
import ca.odell.glazedlists.FunctionList.Function;
import ca.odell.glazedlists.event.ListEventListener;
import ca.odell.glazedlists.event.ListEventPublisher;
import ca.odell.glazedlists.gui.AdvancedTableFormat;
import ca.odell.glazedlists.gui.TableFormat;
import ca.odell.glazedlists.gui.WritableTableFormat;
import ca.odell.glazedlists.impl.*;
import ca.odell.glazedlists.impl.beans.*;
import ca.odell.glazedlists.impl.filter.StringTextFilterator;
import ca.odell.glazedlists.impl.functions.ConstantFunction;
import ca.odell.glazedlists.impl.matchers.FixedMatcherEditor;
import ca.odell.glazedlists.impl.sort.*;
import ca.odell.glazedlists.matchers.Matcher;
import ca.odell.glazedlists.matchers.MatcherEditor;
import ca.odell.glazedlists.matchers.Matchers;
import ca.odell.glazedlists.util.concurrent.ReadWriteLock;
import java.beans.PropertyChangeEvent;
import java.util.*;
/**
* A factory for creating all sorts of objects to be used with Glazed Lists.
*
* @author Jesse Wilson
*/
public final class GlazedLists {
/**
* A dummy constructor to prevent instantiation of this class
*/
private GlazedLists() {
throw new UnsupportedOperationException();
}
// Utility Methods // // // // // // // // // // // // // // // // // // //
/**
* Replace the complete contents of the target {@link EventList} with the complete
* contents of the source {@link 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 {@link 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 {@link List#clear() clear()}; {@link List#addAll(Collection) 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 {@link #replaceAllSorted sorted} version
* of replaceAll.
*
* @param updates whether to fire update events for Objects that are equal in
* both {@link List}s.
*/
public static void replaceAll(EventList target, List source, boolean updates) {
Diff.replaceAll(target, source, updates);
}
/**
* Overloaded version of {@link #replaceAll(EventList,List,boolean)} that uses
* a {@link Comparator} to determine equality rather than
* {@link Object#equals(Object) equals()}.
*
* @param comparator the {@link Comparator} to determine equality between
* elements. This {@link Comparator} must return 0 for
* elements that are equal and nonzero for elements that are not equal.
* Sort order is not used.
*/
public static void replaceAll(EventList target, List source, boolean updates, Comparator comparator) {
Diff.replaceAll(target, source, updates, comparator);
}
/**
* Replace the complete contents of the target {@link EventList} with the complete
* contents of the source {@link Collection} while making as few list changes
* as possible.
*
*
Unlike the {@link #replaceAll 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
* {@link Comparator} specified. If they're sorted in {@link Comparable natural}
* order, use {@link #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 {@link 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 {@link List#clear() clear()}; {@link List#addAll(Collection) 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 {@link #replaceAll general} version of replaceAll.
*
* @see Collections#sort
* @see SortedSet
*
* @param target an EventList sorted with the {@link Comparator} specified.
* Its contents will be replaced with those in source.
* @param source a collection sorted with the {@link Comparator} specified.
* @param 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 {@link #comparableComparator} will be used,
* which means that all elements must implement {@link Comparable}.
* @param updates whether to fire update events for Objects that are equal in
* both {@link List}s.
*/
public static void replaceAllSorted(EventList target, Collection source, boolean updates, Comparator comparator) {
GlazedListsImpl.replaceAll(target, source, updates, comparator);
}
// Comparators // // // // // // // // // // // // // // // // // // // //
/** Provide Singleton access for all Comparators with no internal state */
private static Comparator booleanComparator = null;
private static Comparator comparableComparator = null;
private static Comparator reversedComparable = null;
/**
* Creates a {@link Comparator} that uses Reflection to compare two
* instances of the specified {@link Class} by the given JavaBean
* properties. The JavaBean property and any extra
* properties must implement {@link Comparable}.
*
*
The following example code sorts a List of Customers by first name,
* with ties broken by last name.
*
*
*
* @param clazz the name of the class which defines the accessor method
* for the given property and optionaly properties
* @param property the name of the first Comparable property to be extracted
* and used to compare instances of the clazz
* @param properties the name of optional Comparable properties, each of
* which is used to break ties for the prior property.
*/
public static Comparator beanPropertyComparator(Class clazz, String property, String... properties) {
// build the Comparator that must exist
Comparator firstComparator = beanPropertyComparator(clazz, property, comparableComparator());
// if only one Comparator is specified, return it immediately
if (properties.length == 0) return firstComparator;
// build the remaining Comparators
final List> comparators = new ArrayList>(properties.length+1);
comparators.add(firstComparator);
for (int i = 0; i < properties.length; i++)
comparators.add(beanPropertyComparator(clazz, properties[i], comparableComparator()));
// chain all Comparators together
return chainComparators(comparators);
}
/**
* Creates a {@link Comparator} that uses Reflection to compare two instances
* of the specified {@link Class} by the given JavaBean property. The JavaBean
* property is compared using the provided {@link Comparator}.
*/
public static Comparator beanPropertyComparator(Class className, String property, Comparator propertyComparator) {
return new BeanPropertyComparator(className, property, propertyComparator);
}
/**
* Creates a {@link Comparator} for use with {@link Boolean} objects.
*/
public static Comparator booleanComparator() {
if(booleanComparator == null) booleanComparator = new BooleanComparator();
return booleanComparator;
}
/**
* Creates a {@link Comparator} that compares {@link String} objects in
* a case-insensitive way. This {@link Comparator} is equivalent to using
* {@link String#CASE_INSENSITIVE_ORDER} and exists here for convenience.
*/
public static Comparator caseInsensitiveComparator() {
return String.CASE_INSENSITIVE_ORDER;
}
/**
* Creates a chain of {@link Comparator}s that applies the provided
* {@link Comparator}s in the sequence specified until differences or
* absolute equality is determined.
*/
public static Comparator chainComparators(List> comparators) {
return new ComparatorChain(comparators);
}
/**
* Creates a chain of {@link Comparator}s that applies the provided
* {@link Comparator}s in the sequence specified until differences or
* absolute equality is determined.
*/
public static Comparator chainComparators(Comparator... comparators) {
return chainComparators(Arrays.asList(comparators));
}
/**
* Creates a {@link Comparator} that compares {@link Comparable} objects.
*/
@SuppressWarnings("unchecked")
public static Comparator comparableComparator() {
if(comparableComparator == null) comparableComparator = new ComparableComparator();
return (Comparator)comparableComparator;
}
/**
* Creates a reverse {@link Comparator} that works for {@link Comparable} objects.
*/
@SuppressWarnings("unchecked")
public static Comparator reverseComparator() {
if(reversedComparable == null) reversedComparable = reverseComparator(comparableComparator());
return (Comparator)reversedComparable;
}
/**
* Creates a reverse {@link Comparator} that inverts the given {@link Comparator}.
*/
public static Comparator reverseComparator(Comparator forward) {
return new ReverseComparator(forward);
}
// TableFormats // // // // // // // // // // // // // // // // // // // //
/**
* Creates a {@link TableFormat} that binds JavaBean properties to
* table columns via Reflection.
*/
public static TableFormat tableFormat(String[] propertyNames, String[] columnLabels) {
return new BeanTableFormat(null, propertyNames, columnLabels);
}
/**
* Creates a {@link TableFormat} that binds JavaBean properties to
* table columns via Reflection.
*
* @param baseClass the class of the Object to divide into columns. If specified,
* the returned class will provide implementation of
* {@link AdvancedTableFormat#getColumnClass(int)} and
* {@link AdvancedTableFormat#getColumnComparator(int)} by examining the
* classes of the column value.
*/
public static TableFormat tableFormat(Class baseClass, String[] propertyNames, String[] columnLabels) {
return new BeanTableFormat(baseClass, propertyNames, columnLabels);
}
/**
* Creates a {@link TableFormat} that binds JavaBean properties to
* table columns via Reflection. The returned {@link TableFormat} implements
* {@link WritableTableFormat} and may be used for an editable table.
*/
public static TableFormat tableFormat(String[] propertyNames, String[] columnLabels, boolean[] editable) {
return new BeanTableFormat(null, propertyNames, columnLabels, editable);
}
/**
* Creates a {@link TableFormat} that binds JavaBean properties to
* table columns via Reflection. The returned {@link TableFormat} implements
* {@link WritableTableFormat} and may be used for an editable table.
*
* @param baseClass the class of the Object to divide into columns. If specified,
* the returned class will provide implementation of
* {@link AdvancedTableFormat#getColumnClass(int)} and
* {@link AdvancedTableFormat#getColumnComparator(int)} by examining the
* classes of the column value.
*/
public static TableFormat tableFormat(Class baseClass, String[] propertyNames, String[] columnLabels, boolean[] editable) {
return new BeanTableFormat(baseClass, propertyNames, columnLabels, editable);
}
// TextFilterators // // // // // // // // // // // // // // // // // // //
private static TextFilterator