wyvern.lib.predicates
Class AndPredicate

java.lang.Object
  extended bywyvern.lib.predicates.AndPredicate
All Implemented Interfaces:
Predicate, PrintablePredicate

public class AndPredicate
extends java.lang.Object
implements Predicate, PrintablePredicate

This predicate combines N other predicates with an AND operation. It returns true only when all sub-predicates return true.

Version:
1.0, Feb 09, 1998
Author:
Steve Yegge

Constructor Summary
AndPredicate(Predicate p1, Predicate p2)
          Constructs a new AndPredicate with 2 sub-predicates p1 and p2.
 
Method Summary
 AndPredicate add(Predicate p)
          Adds another predicate that must pass for the overall test to return true.
 java.util.List getPredicates()
          Returns both (or all) of the predicates being AND-ed together.
 boolean predicate(GameObject obj)
          Returns true if both sub-predicates return true for the object.
 java.lang.String print()
          Prints an English-like description of the predicate, e.g.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AndPredicate

public AndPredicate(Predicate p1,
                    Predicate p2)
Constructs a new AndPredicate with 2 sub-predicates p1 and p2. Returns true if p1 AND p2 return true, short-circuited in that order.

Method Detail

getPredicates

public java.util.List getPredicates()
Returns both (or all) of the predicates being AND-ed together.


add

public AndPredicate add(Predicate p)
Adds another predicate that must pass for the overall test to return true.

Parameters:
p - another Predicate that also must be true
Returns:
this object, so you can chain adding, e.g. andPredicate.add(p1).add(p2).add(p3)

predicate

public boolean predicate(GameObject obj)
Returns true if both sub-predicates return true for the object.

Specified by:
predicate in interface Predicate
Parameters:
obj - the object to predicate upon
Returns:
true if it passes the test

toString

public java.lang.String toString()

print

public java.lang.String print()
Description copied from interface: PrintablePredicate
Prints an English-like description of the predicate, e.g. "NOT name like 'bob'", or "quantity < 100 AND item is cursed"

Specified by:
print in interface PrintablePredicate