Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
ca.odell.glazedlists.matchers.Matchers
public final class Matchers
extends java.lang.Object
Method Summary | |
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static Matcher |
|
static Matcher |
|
public staticCollection super E> select(Collection collection, E> matcher)
Add all elements from the givencollection
that satisfy thematcher
to a newArrayList
.
- Parameters:
collection
- the Collection to searchmatcher
- the criteria for considering an element a match
- Returns:
- a new
ArrayList
containing the elements which satisfy thematcher
public staticCollection super E> select(Collection collection, E> matcher, E> results)
Add all elements from the givencollection
that satisfy thematcher
to the givenresults
Collection.results
can be any Collection that supports theCollection.add
operation.
- Parameters:
collection
- the Collection to searchmatcher
- the criteria for considering an element a matchresults
- the Collection into which matching elements are added
- Returns:
- the
results
Collection
containing the elements which satisfy thematcher
public staticE[] select(E[] items, E> matcher)
Return a new array containing only theitems
that satisfy thematcher
.
- Parameters:
items
- the array of Objects to searchmatcher
- the criteria for considering an element a match
- Returns:
- a new array containing only the
items
that satisfy thematcher
public staticMatcher and(E>... matchers)
Returns a Matcher which returns a match when all of the givenmatchers
report a match.
- Parameters:
matchers
- the Collection of Matchers to combine with an "and" operator
- Returns:
- a Matcher that combines the
matchers
via an "and" operator
public staticMatcher beanPropertyMatcher(Class beanClass, String propertyName, Object expectedValue)
Creates aMatcher
that uses Reflection to compare the expectedValue of the specified property of an object to theexpectedValue
.
public staticMatcher falseMatcher()
Get aMatcher
that always returns false, therefore matching nothing..
public staticMatcher invert(Matcher original)
public staticMatcher isNotNull()
Get aMatcher
that returns returns true iff it is given anull
object.
public staticMatcher isNull()
Get aMatcher
that returns returns true iff it is given anon-null
object.
public staticMatcher or(E>... matchers)
Returns a Matcher which returns a match when any of the givenmatchers
reports a match.
- Parameters:
matchers
- the Collection of Matchers to combine with an "or" operator
- Returns:
- a Matcher that combines the
matchers
via an "or" operator
public staticMatcher trueMatcher()
Get aMatcher
that always returns true, therefore matching everything.
public staticMatcher types(Class... classes)
Returns a Matcher which reports a match when the given object to match is not null and reports on of the givenclasses
as its type.
- Parameters:
classes
- the object types that are matched
- 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
public staticMatcherEditor weakReferenceProxy(MatcherEditor 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. This exists to solve a garbage collection problem. Suppose I have aMatcherEditor
M which is long lived and manyMatcherEditor.Listener
s, 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 aWeakReference
to the t, and will remove itself from the list of listeners for M. TheMatcherEditor
returned by this method makes implementing the above scheme trivial. It does two things for you automatically:
- It wraps each
MatcherEditor.Listener
passed toMatcherEditor.addMatcherEditorListener(Listener
in a) java.lang.ref.WeakReference
so that the listeners are garbage collected when they become unreachable.- It registers itself as a weak listener of the given
matcherEditor
so the MatcherEditor returned by this method will be garbage collected when it becomes unreachable.
- See Also:
java.lang.ref.WeakReference
public staticboolean contains(Collection collection, E> matcher)
Returns true if the givencollection
contains an element that satisfies the givenmatcher
; false otherise.
- Parameters:
collection
- the Collection to searchmatcher
- the criteria for considering an element a match
- Returns:
- true if the given
collection
contains an element that satisfies the givenmatcher
; false otherise
public staticboolean filter(Collection collection, E> matcher)
Iterate through the specified collection and remove all elements that don't match the specified matcher.
- Returns:
true
if any elements were removed from the specifiedCollection
public staticMatcher rangeMatcher(D start, D end)
Creates aMatcher
that matchesComparable
objects for containment within the range between the givenstart
andend
.
public staticMatcher rangeMatcher(D start, D end, Filterator filterator)
Creates aMatcher
that uses the givenfilterator
to extractComparable
objects from filtered objects and compares those Comparables against the range between the givenstart
andend
. If at least one Comparable returned by thefilterator
is within the range, the object is considered a match.null
start
orend
values are allowed and are interpreted as"no start"
or"no end"
to the range respectively.
- Parameters:
start
- theComparable
which starts the rangeend
- theComparable
which ends the rangefilterator
- the logic for extracting filterComparable
s from filtered objects
public staticint count(Collection collection, E> matcher)
Iterate through the specified collection and count all elements that match the specified matcher.
- Returns:
- the number of elements in the collection that are matched
public staticint indexOf(List list, E> matcher)
Returns the index of the first element from the givenlist
that satisfies thematcher
or -1 if no such element exists.
- Parameters:
list
- the List to searchmatcher
- the criteria for considering an element a match
- Returns:
- the index of the first element from the given
list
that satisfies thematcher
or -1 if no such element exists
public static MatchernonNullAndNonEmptyString()
public static MatcherpropertyEventNameMatcher(boolean matchPropertyNames, String... propertyNames)
Create aMatcher
that uses the givenpropertyNames
to matchPropertyChangeEvent
s by their property name. The concrete behaviour depends on thematchPropertyNames
parameter. If you want to match property change events against a known set of property names, use a value oftrue
. Alternatively, when you specifyfalse
, 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.
- Parameters:
matchPropertyNames
- iftrue
, match property change events against the specified property names, iffalse
filter thempropertyNames
- the property names to consider
- See Also:
GlazedLists.beanConnector(Class, Matcher)