ProgramixGenericLib v5.0.1

com.programix.util
Class TriState

java.lang.Object
  extended by com.programix.util.TriState
All Implemented Interfaces:
Serializable, Comparable<TriState>

public final class TriState
extends Object
implements Serializable, Comparable<TriState>

Holds one of three states: YES, NO, and UNKNOWN. This can be used instead of a boolean to hold a third state of "don't know" or "unknown". This can also be used instead of a Boolean reference so that "unknown" can be explicitly represented as opposed to using a null reference to implicitly indicate "unknown".

Author:
Paul Hyde
See Also:
Serialized Form

Field Summary
static TriState NO
          Indicates that the state is known and that it is "no" (or "false", or "off", or "negative").
static TriState UNKNOWN
          Indicates that the state is unknown (neither "yes" or "no" is known at this point).
static List<TriState> VALUE_LIST
          An unmodifiable List of all the instances of TriState.
static TriState YES
          Indicates that the state is known and that it is "yes" (or "true", or "on", or "affirmative").
 
Method Summary
 int compareTo(TriState other)
           
 boolean equals(Object obj)
           
 String getName()
          Returns the name of this instance, one of: "YES", "NO", or "UNKNOWN".
static TriState[] getValues()
          Returns an array of all the instances of TriState.
 int hashCode()
           
 boolean isKnown()
          Returns true if the state is either YES or NO (not UNKNOWN).
 boolean isNo()
          Returns true if the state is NO.
 boolean isNotNo()
          Returns true if the state is not NO, but is either YES or UNKNOWN.
 boolean isNotYes()
          Returns true if the state is not YES, but is either NO or UNKNOWN.
 boolean isUnknown()
          Returns true if the state is neither YES nor NO, but is UNKNOWN.
 boolean isYes()
          Returns true if the state is YES.
 String toString()
           
static TriState valueOf(String name)
          Returns the instance whose getName() method returns a String that matches the name passed in.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

YES

public static final TriState YES
Indicates that the state is known and that it is "yes" (or "true", or "on", or "affirmative").

See Also:
NO, UNKNOWN

NO

public static final TriState NO
Indicates that the state is known and that it is "no" (or "false", or "off", or "negative").

See Also:
YES, UNKNOWN

UNKNOWN

public static final TriState UNKNOWN
Indicates that the state is unknown (neither "yes" or "no" is known at this point).

See Also:
YES, NO

VALUE_LIST

public static final List<TriState> VALUE_LIST
An unmodifiable List of all the instances of TriState.

Method Detail

getValues

public static TriState[] getValues()
Returns an array of all the instances of TriState. A cloned copy is returned, so no special care is required.


valueOf

public static TriState valueOf(String name)
                        throws IllegalArgumentException
Returns the instance whose getName() method returns a String that matches the name passed in. The matching is done ignoring any case differences and after trimming any leading or trailing whitespace on the string passed in.

Parameters:
name - the name to search for.
Returns:
the matching instance
Throws:
IllegalArgumentException - if no match is found.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(TriState other)
Specified by:
compareTo in interface Comparable<TriState>

getName

public String getName()
Returns the name of this instance, one of: "YES", "NO", or "UNKNOWN".


isKnown

public boolean isKnown()
Returns true if the state is either YES or NO (not UNKNOWN).


isUnknown

public boolean isUnknown()
Returns true if the state is neither YES nor NO, but is UNKNOWN.


isYes

public boolean isYes()
Returns true if the state is YES.


isNotYes

public boolean isNotYes()
Returns true if the state is not YES, but is either NO or UNKNOWN.


isNo

public boolean isNo()
Returns true if the state is NO.


isNotNo

public boolean isNotNo()
Returns true if the state is not NO, but is either YES or UNKNOWN.


ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.