wyvern.lib.predicates
Class ClassPredicate

java.lang.Object
  extended bywyvern.lib.predicates.ClassPredicate
All Implemented Interfaces:
Predicate

public class ClassPredicate
extends java.lang.Object
implements Predicate

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
ClassPredicate()
          Constructs a new ClassPredicate with no predicate classes.
ClassPredicate(java.lang.Class c)
          Constructs a new ClassPredicate with the specified class.
 
Method Summary
 void addClass(java.lang.Class c)
          Adds a class to check for.
 boolean predicate(GameObject 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

ClassPredicate

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


ClassPredicate

public ClassPredicate(java.lang.Class c)
Constructs a new ClassPredicate 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(GameObject obj)
Return true if the object is an instance of the class.

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