wyvern.lib.predicates
Class CounterPredicate

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

public class CounterPredicate
extends java.lang.Object
implements Predicate

This predicate looks for the nth occurrence of a match for some other predicate. The most common usage is to wrap a NameMatchPredicate, so the player can type things like "get key 3" and "put scroll 2 in bag 4".

Note: you have to call reset() to reset this predicate or you can't reuse it.

Version:
1.0, Sep 15, 1999
Author:
Steve Yegge

Constructor Summary
CounterPredicate(Predicate p, int item)
          Constructs a new CounterPredicate.
 
Method Summary
 boolean predicate(GameObject obj)
          Returns true if the passed item is the nth to match the internal predicate.
 void reset()
          Resets the internal count so the predicate can be reused.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CounterPredicate

public CounterPredicate(Predicate p,
                        int item)
Constructs a new CounterPredicate.

Parameters:
p - the Predicate to use for matching
item - the item number: a positive number. Item numbers <= 0 will be ignored, and the counter will always return null.
Method Detail

predicate

public boolean predicate(GameObject obj)
Returns true if the passed item is the nth to match the internal predicate.

Specified by:
predicate in interface Predicate
Parameters:
obj - the object to check
Returns:
true if it's the nth match

reset

public void reset()
Resets the internal count so the predicate can be reused.