Class 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.

Mark S. Miller

Field Summary
private  ValueGuard myOptSubGuard
static NullOkGuard THE_ONE
Fields inherited from class org.erights.e.elib.slot.BaseGuard
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


public static final NullOkGuard THE_ONE


private final ValueGuard myOptSubGuard
Constructor Detail


private NullOkGuard(ValueGuard optSubGuard)
Method Detail


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
coerce in class BaseGuard


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.


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

Specified by:
getName in interface SlotGuard
getName in class BaseGuard