org.erights.e.elib.slot
Class NullOkGuard

java.lang.Object
  |
  +--org.erights.e.elib.slot.BaseGuard
        |
        +--org.erights.e.elib.slot.NullOkGuard
All Implemented Interfaces:
Guard, SlotGuard, ValueGuard

public class NullOkGuard
extends BaseGuard

Safe: The canonical instance (THE_ONE) is bound to "nullOk" in the initial environment, and accepts null as a valid value.

As a ValueGuard, "nullOk" accepts only null as a valid value.

As a SlotGuard, "nullOk" makes a settable slot that only accepts nulls.

As a ValueGuard & SlotGuard template, "nullOk(valueGuard)" produces an object that implements ValueGuard and SlotGuard. (This object is also an instance of NullOkGuard, but no one should care.) As a ValueGuard, this object accepts null and whatever the argument valueGuard accepts. As a SlotGuard, it makes settable slots that accept null and whatever the original valueGuard accepts. In both cases, non-null values are coerced according to the original valueGuard.

Author:
Mark S. Miller

Field Summary
private  ValueGuard myOptSubGuard
           
static NullOkGuard THE_ONE
          Enabled:
 
Fields inherited from class org.erights.e.elib.slot.BaseGuard
myOptValueGuard
 
Constructor Summary
private NullOkGuard(ValueGuard optSubGuard)
           
 
Method Summary
 Object coerce(Object specimen, OneArgFunc optEjector)
          Enabled: If specimen is null, returns null.
 String getName()
          Enabled: "nullOk" or "nullOk(sub-guard-name)"
 NullOkGuard run(ValueGuard subGuard)
          Enabled: Makes a Guard that accepts either null or values that the argument 'subGuard' accepts.
 
Methods inherited from class org.erights.e.elib.slot.BaseGuard
__printOn, accepts, and, butNot, coerce, get, makeSlot, makeSlot, not, or, toString, xor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

THE_ONE

public static final NullOkGuard THE_ONE
Enabled:


myOptSubGuard

private final ValueGuard myOptSubGuard
Constructor Detail

NullOkGuard

private NullOkGuard(ValueGuard optSubGuard)
Method Detail

coerce

public Object coerce(Object specimen,
                     OneArgFunc optEjector)
Enabled: If specimen is null, returns null. Otherwise passes it to my wrapped ValueGuard, if there is one.

Specified by:
coerce in interface ValueGuard
Overrides:
coerce in class BaseGuard

run

public NullOkGuard run(ValueGuard subGuard)
Enabled: Makes a Guard that accepts either null or values that the argument 'subGuard' accepts.

Non-null values are coerced by the argument. As a SlotGuard, makes settable slots.


getName

public String getName()
Enabled: "nullOk" or "nullOk(sub-guard-name)"

Specified by:
getName in interface SlotGuard
Overrides:
getName in class BaseGuard


comments?