games.strategy.util
Class Match<T>

java.lang.Object
  extended by games.strategy.util.Match<T>
Direct Known Subclasses:
CompositeMatch, InverseMatch

public abstract class Match<T>
extends java.lang.Object

A utilty for seeing which elements in a collection satisfy a given condition.

An instance of match allows you to test that an object matches some condition.

Static utility methods allow you to find what elements in a collection satisfy a match,
count the number of matches, see if any elements match etc.

Version:
1.0
Author:
Sean Bridges

Field Summary
static Match ALWAYS_MATCH
          A match that always returns true.
static Match NEVER_MATCH
          A match that always returns false.
 
Constructor Summary
Match()
           
 
Method Summary
static
<T> boolean
allMatch(java.util.Collection<T> collection, Match<T> aMatch)
          returns true if all elements in the collection match.
static
<T> int
countMatches(java.util.Collection<T> collection, Match<T> aMatch)
          Returns the number of matches found.
static
<K,V> java.util.Set<K>
getKeysWhereValueMatch(java.util.Map<K,V> aMap, Match<V> valueMatch)
          return the keys where the value keyed by the key matches valueMatch
static
<T> java.util.List<T>
getMatches(java.util.Collection<T> collection, Match<T> aMatch)
          Returns the elements of the collection that match.
static
<T> java.util.List<T>
getNMatches(java.util.Collection<T> collection, int max, Match<T> aMatch)
          Only returns the first n matches.
 Match<T> invert()
           
abstract  boolean match(T o)
          Subclasses must override this method.
static
<T> boolean
noneMatch(java.util.Collection<T> collection, Match<T> aMatch)
          Returns true if no matches could be found.
static
<T> boolean
someMatch(java.util.Collection<T> collection, Match<T> aMatch)
          Returns true if any matches could be found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALWAYS_MATCH

public static final Match ALWAYS_MATCH
A match that always returns true.


NEVER_MATCH

public static final Match NEVER_MATCH
A match that always returns false.

Constructor Detail

Match

public Match()
Method Detail

getMatches

public static final <T> java.util.List<T> getMatches(java.util.Collection<T> collection,
                                                     Match<T> aMatch)
Returns the elements of the collection that match.


getNMatches

public static final <T> java.util.List<T> getNMatches(java.util.Collection<T> collection,
                                                      int max,
                                                      Match<T> aMatch)
Only returns the first n matches. If n matches cannot be found will return all matches that can be found.


allMatch

public static final <T> boolean allMatch(java.util.Collection<T> collection,
                                         Match<T> aMatch)
returns true if all elements in the collection match.


someMatch

public static final <T> boolean someMatch(java.util.Collection<T> collection,
                                          Match<T> aMatch)
Returns true if any matches could be found.


noneMatch

public static final <T> boolean noneMatch(java.util.Collection<T> collection,
                                          Match<T> aMatch)
Returns true if no matches could be found.


countMatches

public static final <T> int countMatches(java.util.Collection<T> collection,
                                         Match<T> aMatch)
Returns the number of matches found.


getKeysWhereValueMatch

public static <K,V> java.util.Set<K> getKeysWhereValueMatch(java.util.Map<K,V> aMap,
                                                            Match<V> valueMatch)
return the keys where the value keyed by the key matches valueMatch


match

public abstract boolean match(T o)
Subclasses must override this method. Returns true if the object matches some condition.


invert

public final Match<T> invert()