wyvern.lib.predicates
Class GenericClassPredicate

java.lang.Object
  extended bywyvern.lib.predicates.GenericClassPredicate
All Implemented Interfaces:
GenericPredicate

public class GenericClassPredicate
extends java.lang.Object
implements GenericPredicate

This Predicate checks to see if the passed object is an instance of the specified class. This class is thread-safe.

Big Fat Note: This class does NOT work in jython, because of the proxy classes prevent Class.isInstance() from working correctly. However, you can create your own using jython's built-in isinstance operator:

      class open_predicate(Predicate):
              def predicate(self, obj):
                      return isinstance(obj, Openable)
 

Version:
1.0, Sep 27, 1997
Author:
Steve Yegge

Constructor Summary
GenericClassPredicate()
          Constructs a new GenericClassPredicate with no predicate classes.
GenericClassPredicate(java.lang.Class c)
          Constructs a new GenericClassPredicate with the specified class.
 
Method Summary
 void addClass(java.lang.Class c)
          Adds a class to check for.
 boolean predicate(java.lang.Object obj)
          Return true if the object is an instance of the class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericClassPredicate

public GenericClassPredicate()
Constructs a new GenericClassPredicate with no predicate classes. Call addClass() to add classes to the predicate.


GenericClassPredicate

public GenericClassPredicate(java.lang.Class c)
Constructs a new GenericClassPredicate with the specified class.

Parameters:
c - a class for which the predicate will return true
Method Detail

addClass

public void addClass(java.lang.Class c)
Adds a class to check for.

Parameters:
c - a class to add to the list of classes that pass the predicate.

predicate

public boolean predicate(java.lang.Object obj)
Return true if the object is an instance of the class.

Specified by:
predicate in interface GenericPredicate
Parameters:
obj - the object to check
Returns:
true if it's one of our predicated classes