org.sadun.util
Class TelnetInputStreamConsumer.CompositeCriterium

java.lang.Object
  extended byorg.sadun.util.TelnetInputStreamConsumer.CompositeCriterium
All Implemented Interfaces:
TelnetInputStreamConsumer.Criterium
Direct Known Subclasses:
TelnetInputStreamConsumer.AndCriterium, TelnetInputStreamConsumer.OrCriterium
Enclosing class:
TelnetInputStreamConsumer

public abstract static class TelnetInputStreamConsumer.CompositeCriterium
extends java.lang.Object
implements TelnetInputStreamConsumer.Criterium

An abstract criterium based on other criteria.

The class offers services to compose criteria and to retrieve which criterium or criteria hold, after that holds(String)has been invoked.

All composing criteria are initially in an undefined state. After holds(String)is called, and depending on the implementation of that method by the subclass, some will have been verified and found holding or not, while others won't. (For example, ANDing many criteria requires that every one is checked, while ORing them doesn't).

Subclasses must implement the method holdsMultiple(String)to define the precise semantics of the criteria (the member operandscontains the TelnetInputStreamConsumer.Criteriumto check).

If the verifyAllRequestedproperty is set, invoking holds(String)will trigger the verification of all the composing criteria, regardless of the implementation of {@link #holdsMultiple(String).

Version:
1.0
Author:
Cristiano Sadun

Field Summary
protected  org.sadun.util.TelnetInputStreamConsumer.CompositeCriterium.OperandWrapper[] operands
          The criteria to check.
protected  boolean verifyAllRequested
          VerifyAll mode
 
Constructor Summary
protected TelnetInputStreamConsumer.CompositeCriterium(TelnetInputStreamConsumer.Criterium[] criteria)
          Create an instance using the given criteria as components, without requesting that all be verified when holds(String)is invoked.
protected TelnetInputStreamConsumer.CompositeCriterium(TelnetInputStreamConsumer.Criterium[] criteria, boolean verifyAllRequested)
          Create an instance using the given criteria as components, possibly requesting that all be verified when holds(String)is invoked.
 
Method Summary
 TelnetInputStreamConsumer.Criterium[] getHoldingCriteria()
          Return the component criteria the did hold, after TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has bee called.
 TelnetInputStreamConsumer.Criterium getHoldingCriterium()
          Return the first criterium that holds, or null if no criteria holds.
 TelnetInputStreamConsumer.Criterium[] getNotHoldingCriteria()
          Return the component criteria the did not hold, after TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has bee called.
 TelnetInputStreamConsumer.Criterium[] getUndefinedCriteria()
          Return the component criteria which have not been verified after TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has bee called.
 boolean holds(java.lang.String input)
           
protected abstract  boolean holdsMultiple(java.lang.String input)
          This method is to be implemented by subclasses to do the actual verification of the multiple criterium.
 boolean isVerified(TelnetInputStreamConsumer.Criterium criteria)
          Return true if the given criteria has not verified.
 boolean isVerifiedAndDoesNotHold(TelnetInputStreamConsumer.Criterium criteria)
          Return true if the given criteria has been verified and did not hold.
 boolean isVerifiedAndHolds(TelnetInputStreamConsumer.Criterium criteria)
          Return true if the given criteria has been verified and did hold.
 boolean isVerifyAllRequested()
          Return true if all the composing criteria are to be checked when holds(String)is invoked.
 void setVerifyAllRequested(boolean verifyAllRequested)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

operands

protected org.sadun.util.TelnetInputStreamConsumer.CompositeCriterium.OperandWrapper[] operands
The criteria to check.


verifyAllRequested

protected boolean verifyAllRequested
VerifyAll mode

Constructor Detail

TelnetInputStreamConsumer.CompositeCriterium

protected TelnetInputStreamConsumer.CompositeCriterium(TelnetInputStreamConsumer.Criterium[] criteria)
Create an instance using the given criteria as components, without requesting that all be verified when holds(String)is invoked.

Parameters:
criteria - the composing criteria

TelnetInputStreamConsumer.CompositeCriterium

protected TelnetInputStreamConsumer.CompositeCriterium(TelnetInputStreamConsumer.Criterium[] criteria,
                                                       boolean verifyAllRequested)
Create an instance using the given criteria as components, possibly requesting that all be verified when holds(String)is invoked.

Parameters:
criteria - the composing criteria
Method Detail

holds

public final boolean holds(java.lang.String input)
Specified by:
holds in interface TelnetInputStreamConsumer.Criterium

holdsMultiple

protected abstract boolean holdsMultiple(java.lang.String input)
This method is to be implemented by subclasses to do the actual verification of the multiple criterium.

It has the same role as TelnetInputStreamConsumer.Criterium.holds(java.lang.String) in TelnetInputStreamConsumer.Criterium

Parameters:
input - the input to verify
Returns:
true if the multiple criterium is verified.

getHoldingCriteria

public TelnetInputStreamConsumer.Criterium[] getHoldingCriteria()
Return the component criteria the did hold, after TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has bee called. Criteria that have not yet been verified (that is, for which TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has not been called) are excluded. Use getUndefinedCriteria()to know which they are).

Returns:
the criteria the did hold.

getHoldingCriterium

public TelnetInputStreamConsumer.Criterium getHoldingCriterium()
Return the first criterium that holds, or null if no criteria holds.

Returns:
the first criterium that holds, or null if no criteria did hold.

getNotHoldingCriteria

public TelnetInputStreamConsumer.Criterium[] getNotHoldingCriteria()
Return the component criteria the did not hold, after TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has bee called. Criteria that have not yet been verified (that is, for which TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has not been called) are excluded. Use getUndefinedCriteria()to know which they are).

Returns:
the criteria the did not hold.

getUndefinedCriteria

public TelnetInputStreamConsumer.Criterium[] getUndefinedCriteria()
Return the component criteria which have not been verified after TelnetInputStreamConsumer.Criterium.holds(java.lang.String) has bee called.

Returns:
the criteria the did not hold.

isVerifiedAndHolds

public boolean isVerifiedAndHolds(TelnetInputStreamConsumer.Criterium criteria)
Return true if the given criteria has been verified and did hold.

Parameters:
criteria - the criteria to verify, which must be part of this composite criterium
Returns:
true if the given criteria has been verified and holds.
Throws:
java.lang.IllegalArgumentException - if the criteria is not part of this composite

isVerifiedAndDoesNotHold

public boolean isVerifiedAndDoesNotHold(TelnetInputStreamConsumer.Criterium criteria)
Return true if the given criteria has been verified and did not hold.

Parameters:
criteria - the criteria to verify, which must be part of this composite criterium
Returns:
true if the given criteria has been verified and holds.
Throws:
java.lang.IllegalArgumentException - if the criteria is not part of this composite

isVerified

public boolean isVerified(TelnetInputStreamConsumer.Criterium criteria)
Return true if the given criteria has not verified.

Parameters:
criteria - the criteria to verify, which must be part of this composite criterium
Returns:
true if the given criteria has been verified and holds.
Throws:
java.lang.IllegalArgumentException - if the criteria is not part of this composite

isVerifyAllRequested

public boolean isVerifyAllRequested()
Return true if all the composing criteria are to be checked when holds(String)is invoked.

Returns:

setVerifyAllRequested

public void setVerifyAllRequested(boolean verifyAllRequested)