org.qtunes.core.util
Class AbstractMatcher<E>

java.lang.Object
  extended by org.qtunes.core.util.AbstractMatcher<E>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ServiceMatcher, SessionMatcher, TrackMatcher

public abstract class AbstractMatcher<E>
extends java.lang.Object
implements java.io.Serializable

A Utility class that can be used to determine if an Object matches a specified filter. The filter is made up of multiple tests, each one taking one of the following forms

key = valueThe specified field equals the value, eg "type = 'mp3'"
key != valueThe specified field doesn't equal the value, eg "type != 'mp3'"
key < valueThe specified field is less than the value, eg "year < 2000"
key > valueThe specified field is greater than the value, eg "year > 2000"
key <= valueThe specified field is less than or equal to the value, eg "year <= 2000"
key >= valueThe specified field is greater than or equal to the value, eg "year >= 2000"
key =~ valueThe specified field matches the value regex, eg "title =~ '.*King.*'"
key !~ valueThe specified field doesn't match the value regex, eg "album !~ '^The'"
Each individual test can be linked using "or" or "and", and these can be grouped using brackets. Subclasses need to implement the getProperty(E, java.lang.String) method, which returns the named property from the object being tested.

See Also:
Serialized Form

Constructor Summary
AbstractMatcher(java.lang.String filter)
          Create a new AbstractMatcher
 
Method Summary
 boolean equals(java.lang.Object o)
           
 java.lang.String getFilter()
          Return the Filter String for this Matcher
abstract  java.lang.Object getProperty(E source, java.lang.String property)
          Return the specified Property from the source object being tested
 int hashCode()
           
 boolean isUniversal()
          Return true if the Filter will match anything
 boolean matches(E source)
          Return true if this AbstractMatcher matches the specified object
 boolean test(java.lang.String key, java.lang.String op, java.lang.String testval, java.lang.Object propval)
          Compare two values
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMatcher

public AbstractMatcher(java.lang.String filter)
Create a new AbstractMatcher

Parameters:
filter - the filter String
Method Detail

getProperty

public abstract java.lang.Object getProperty(E source,
                                             java.lang.String property)
Return the specified Property from the source object being tested


matches

public boolean matches(E source)
Return true if this AbstractMatcher matches the specified object


test

public boolean test(java.lang.String key,
                    java.lang.String op,
                    java.lang.String testval,
                    java.lang.Object propval)
Compare two values

Parameters:
key - the key the values are stored under
op - the operation, one of "=", "!=", "<", ">", "<=", ">=", "=~" or "!~"
testval - the value specified in the test
propval - the property value that we're testing, as returned from getProperty(E, java.lang.String)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getFilter

public final java.lang.String getFilter()
Return the Filter String for this Matcher


isUniversal

public boolean isUniversal()
Return true if the Filter will match anything