codesimian
Class NeedLiquid

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by codesimian.NeedLiquid
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable
Direct Known Subclasses:
NeedLiquid.Failed, NeedLiquids

public class NeedLiquid
extends java.lang.RuntimeException
implements java.lang.Runnable

A Liquid contains an amount (type double) and a name (type String).

When a NeedLiquid is thrown, a Runnable is given so execution can continue after the Liquid is given.

A NeedLiquid requires a specific amount of Liquid before the Runnable will be run.

You can not get the Runnable from a NeedLiquid because then code could cheat by running it directly.

See Also:
Serialized Form

Nested Class Summary
static class NeedLiquid.Failed
          needed a certain amount and name of Liquid, but could not get it, and it is too late to pay that now.
 
Field Summary
 double D
           
 java.lang.String name
           
 
Constructor Summary
protected NeedLiquid()
           
  NeedLiquid(java.lang.String liquidName, double needThisMuchMoreLiquid, java.lang.Runnable continueExecution)
           
protected NeedLiquid(java.lang.String message, java.lang.Runnable continueExecution)
           
 
Method Summary
 boolean canContinue()
          Returns true if would continues if the Liquid(s) described by this NeedLiquid are put into this NeedLiquid.
 boolean hasLiquid()
          has this NeedLiquid been paid all the Liquid it requires?
 int liquidCount()
           
 void run()
          throws this if hasLiquid() is false, else runs the inner Runnable
 void takeLiquid(Liquid liq)
          liq.amount() must >= this.liquidAmount
 void takeLiquidThenRun(Liquid liq)
          throws this if liq.amount() < this.liquidAmount OR liq.name is not this.liquidName
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public final java.lang.String name

D

public final double D
Constructor Detail

NeedLiquid

protected NeedLiquid()

NeedLiquid

protected NeedLiquid(java.lang.String message,
                     java.lang.Runnable continueExecution)

NeedLiquid

public NeedLiquid(java.lang.String liquidName,
                  double needThisMuchMoreLiquid,
                  java.lang.Runnable continueExecution)
Method Detail

canContinue

public boolean canContinue()
Returns true if would continues if the Liquid(s) described by this NeedLiquid are put into this NeedLiquid. Returns false if never continues.


liquidCount

public int liquidCount()

takeLiquidThenRun

public void takeLiquidThenRun(Liquid liq)
                       throws NeedLiquid
throws this if liq.amount() < this.liquidAmount OR liq.name is not this.liquidName

Throws:
NeedLiquid

takeLiquid

public void takeLiquid(Liquid liq)
liq.amount() must >= this.liquidAmount


hasLiquid

public boolean hasLiquid()
has this NeedLiquid been paid all the Liquid it requires?


run

public void run()
         throws NeedLiquid
throws this if hasLiquid() is false, else runs the inner Runnable

Specified by:
run in interface java.lang.Runnable
Throws:
NeedLiquid