public final class Matchers
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <E> Matcher<E> |
and(Matcher<? super E>... matchers)
Returns a Matcher which returns a match when all of the
given
matchers report a match. |
static <E> Matcher<E> |
beanPropertyMatcher(java.lang.Class<E> beanClass,
java.lang.String propertyName,
java.lang.Object expectedValue)
Creates a
Matcher that uses Reflection to compare the expectedValue
of the specified property of an object to the expectedValue. |
static <E> boolean |
contains(java.util.Collection<E> collection,
Matcher<? super E> matcher)
Returns true if the given
collection contains an
element that satisfies the given matcher; false
otherise. |
static <E> int |
count(java.util.Collection<E> collection,
Matcher<? super E> matcher)
Iterate through the specified collection and count all elements
that match the specified matcher.
|
static <E> Matcher<E> |
falseMatcher()
Get a
Matcher that always returns false, therefore matching nothing.. |
static <E> boolean |
filter(java.util.Collection<E> collection,
Matcher<? super E> matcher)
Iterate through the specified collection and remove all elements
that don't match the specified matcher.
|
static <E> int |
indexOf(java.util.List<E> list,
Matcher<? super E> matcher)
Returns the index of the first element from the given
list
that satisfies the matcher or -1 if no such
element exists. |
static <E> Matcher<E> |
invert(Matcher<E> original)
|
static <E> Matcher<E> |
isNotNull()
Get a
Matcher that returns returns true iff it is
given a null object. |
static <E> Matcher<E> |
isNull()
Get a
Matcher that returns returns true iff it is
given a non-null object. |
static Matcher<java.lang.String> |
nonNullAndNonEmptyString()
|
static <E> Matcher<E> |
or(Matcher<? super E>... matchers)
Returns a Matcher which returns a match when any of the
given
matchers reports a match. |
static Matcher<java.beans.PropertyChangeEvent> |
propertyEventNameMatcher(boolean matchPropertyNames,
java.lang.String... propertyNames)
Create a
Matcher that uses the given propertyNames to match
PropertyChangeEvents by their property name. |
static <D extends java.lang.Comparable,E> |
rangeMatcher(D start,
D end)
Creates a
Matcher that matches Comparable objects for
containment within the range between the given start
and end. |
static <D extends java.lang.Comparable,E> |
rangeMatcher(D start,
D end,
Filterator<D,E> filterator)
Creates a
Matcher that uses the given filterator
to extract Comparable objects from filtered objects and compares
those Comparables against the range between the given start
and end. |
static <E> java.util.Collection<? super E> |
select(java.util.Collection<E> collection,
Matcher<? super E> matcher)
Add all elements from the given
collection that satisfy the
matcher to a new ArrayList. |
static <E> java.util.Collection<? super E> |
select(java.util.Collection<E> collection,
Matcher<? super E> matcher,
java.util.Collection<? super E> results)
Add all elements from the given
collection that satisfy the
matcher to the given results Collection. |
static <E> E[] |
select(E[] items,
Matcher<? super E> matcher)
Return a new array containing only the
items that satisfy
the matcher. |
static <E> Matcher<E> |
trueMatcher()
Get a
Matcher that always returns true, therefore matching everything. |
static <E> Matcher<E> |
types(java.lang.Class... classes)
Returns a Matcher which reports a match when the given object to match
is not null and reports on of the given
classes as its type. |
static <E> MatcherEditor<E> |
weakReferenceProxy(MatcherEditor<E> matcherEditor)
Provides a proxy to another MatcherEditor that may go out of scope
without explicitly removing itself from the source MatcherEditor's set
of listeners.
|
public static <E> MatcherEditor<E> weakReferenceProxy(MatcherEditor<E> matcherEditor)
This exists to solve a garbage collection problem. Suppose I have a
MatcherEditor M which is long lived and many
MatcherEditor.Listeners, t which must listen to M
while they exist. Instead of adding each of the t directly as
listeners of M, add a proxy instead. The proxy will retain a
WeakReference to the t, and will remove itself from
the list of listeners for M.
MatcherEditor returned by this method makes implementing the
above scheme trivial. It does two things for you automatically:
MatcherEditor.Listener passed to
MatcherEditor.addMatcherEditorListener(ca.odell.glazedlists.matchers.MatcherEditor.Listener<E>) in a
WeakReference so that the listeners are
garbage collected when they become unreachable.
matcherEditor so the MatcherEditor returned by
this method will be garbage collected when it becomes unreachable.
WeakReferencepublic static <E> Matcher<E> trueMatcher()
Matcher that always returns true, therefore matching everything.public static <E> Matcher<E> falseMatcher()
Matcher that always returns false, therefore matching nothing..public static <E> Matcher<E> isNull()
Matcher that returns returns true iff it is
given a non-null object.public static <E> Matcher<E> isNotNull()
Matcher that returns returns true iff it is
given a null object.public static Matcher<java.lang.String> nonNullAndNonEmptyString()
public static <E> Matcher<E> beanPropertyMatcher(java.lang.Class<E> beanClass, java.lang.String propertyName, java.lang.Object expectedValue)
Matcher that uses Reflection to compare the expectedValue
of the specified property of an object to the expectedValue.public static <D extends java.lang.Comparable,E> Matcher<E> rangeMatcher(D start, D end)
Matcher that matches Comparable objects for
containment within the range between the given start
and end.public static <D extends java.lang.Comparable,E> Matcher<E> rangeMatcher(D start, D end, Filterator<D,E> filterator)
Matcher that uses the given filterator
to extract Comparable objects from filtered objects and compares
those Comparables against the range between the given start
and end. If at least one Comparable returned by the
filterator is within the range, the object is considered
a match.
null start or end values are
allowed and are interpreted as "no start" or
"no end" to the range respectively.
start - the Comparable which starts the rangeend - the Comparable which ends the rangefilterator - the logic for extracting filter Comparables
from filtered objectspublic static Matcher<java.beans.PropertyChangeEvent> propertyEventNameMatcher(boolean matchPropertyNames, java.lang.String... propertyNames)
Matcher that uses the given propertyNames to match
PropertyChangeEvents by their property name. The concrete behaviour depends on the
matchPropertyNames parameter. If you want to match property change events
against a known set of property names, use a value of true. Alternatively,
when you specify false, the specified property names will serve as an exclude
list, e.g. if an event matches a specified property name, it will be filtered out.
These matchers are especially useful as an event matcher in a bean connector.
matchPropertyNames - if true, match property change events against the
specified property names, if false filter thempropertyNames - the property names to considerGlazedLists.beanConnector(Class, Matcher)public static <E> int count(java.util.Collection<E> collection,
Matcher<? super E> matcher)
public static <E> boolean filter(java.util.Collection<E> collection,
Matcher<? super E> matcher)
true if any elements were removed from the specified
Collectionpublic static <E> E[] select(E[] items,
Matcher<? super E> matcher)
items that satisfy
the matcher.items - the array of Objects to searchmatcher - the criteria for considering an element a matchitems that satisfy
the matcherpublic static <E> java.util.Collection<? super E> select(java.util.Collection<E> collection,
Matcher<? super E> matcher)
collection that satisfy the
matcher to a new ArrayList.collection - the Collection to searchmatcher - the criteria for considering an element a matchArrayList containing the elements which satisfy
the matcherpublic static <E> java.util.Collection<? super E> select(java.util.Collection<E> collection,
Matcher<? super E> matcher,
java.util.Collection<? super E> results)
collection that satisfy the
matcher to the given results Collection.
results can be any Collection that supports the
Collection.add(E) operation.collection - the Collection to searchmatcher - the criteria for considering an element a matchresults - the Collection into which matching elements are addedresults Collection containing the
elements which satisfy the matcherpublic static <E> boolean contains(java.util.Collection<E> collection,
Matcher<? super E> matcher)
collection contains an
element that satisfies the given matcher; false
otherise.collection - the Collection to searchmatcher - the criteria for considering an element a matchcollection contains an
element that satisfies the given matcher;
false otherisepublic static <E> int indexOf(java.util.List<E> list,
Matcher<? super E> matcher)
list
that satisfies the matcher or -1 if no such
element exists.list - the List to searchmatcher - the criteria for considering an element a matchlist
that satisfies the matcher or -1 if no such
element existspublic static <E> Matcher<E> or(Matcher<? super E>... matchers)
matchers reports a match.matchers - the Collection of Matchers to combine with an "or" operatormatchers via an "or" operatorpublic static <E> Matcher<E> and(Matcher<? super E>... matchers)
matchers report a match.matchers - the Collection of Matchers to combine with an "and" operatormatchers via an "and" operatorpublic static <E> Matcher<E> types(java.lang.Class... classes)
classes as its type.classes - the object types that are matchedclasses as its
typeGlazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by buildd at 2016-02-14 5:12