Class Literal
- All Implemented Interfaces:
Comparable<Literal>
A literal is a char that can be preceded by the symbol '\u00ac', negated literal, or by the symbol '\u00bf', 'unknown' literal.
While the semantics of a literal and its negation is the standard one, the semantics for unknown literal is
particular of the CSTN/CSTNU application.
An unknown literal, as '¿p' for example, is true if the value of
proposition letter 'p' is not assigned yet. False otherwise.
Therefore, if a state is characterized by the proposition '¿p', it means that the state is valid till the value of proposition letter 'p' is unknown. In the instant the value of 'p' is set, '¿p' became false and the associated state is not more valid.
A literal object is immutable and must have a propositional letter.
Lastly, for efficiency reasons, this class allows to represent literal using at most
Label.NUMBER_OF_POSSIBLE_PROPOSITIONS
propositions in the range PROPOSITION_ARRAY.
Label.NUMBER_OF_POSSIBLE_PROPOSITIONS
is given by the fact that
Label
represents propositional labels using integer (32 bits), so labels with at
most 32 different propositions.
- Version:
- $Rev: 840 $
- Author:
- Roberto Posenato
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
static final char
ConstantNEGATED=Constants.NOT
(package private) static final char[]
List of possible proposition managed by this class.
Such list is made concatenating 2 blocks: a-z, and A-F.static final String
R.E. representation of PROPOSITION_ARRAYstatic final String
R.E. representation of allowed propositions.static final char
ConstantSTRAIGHT=''
static final char
ConstantUNKNOWN=Constants.UNKNOWN
-
Method Summary
Modifier and TypeMethodDescription(package private) static boolean
areComplement
(char state1, char state2) static char
charValue
(int i) static boolean
check
(char c) int
boolean
Returns the complement of this.char
getName()
Returns a literal that is the negated of this.char
getState()
(package private) static byte
getStateOrdinal
(char state) Returns the ordinal associate tostate
.Returns a literal that is the straight literal of this.Returns a literal that is the unknown literal of this.int
hashCode()
(package private) static int
hashCode
(char c, char state) Hash code for a literal given as charc
and statestate
.(package private) static byte
index
(char c) boolean
boolean
boolean
boolean
static Literal
Parses the strings
returning the literal represented.(package private) static String
stateAsString
(char state) (package private) static char[]
toChars
(int propositionIndex, char state) toString()
static Literal
valueOf
(char v) Returns the positive literal ofv
.static Literal
valueOf
(char v, char state) Return the literal having the givenstate
ofv
.static Literal
Returns a new literal having same proposition ofv
but with state given bystate
.
-
Field Details
-
ABSENT
public static final char ABSENTOn 20171027 using VisualVM it has been shown that representing the state values of a literal using an enum consumes a lot of memory in this kind of application.
Therefore, I decided to simplify the representation using 4 constants value: ABSENT,STRAIGHT
,NEGATED
, andUNKNOWN
. The char corresponding to each such constant is exploit in the class (to make them more efficient). So, don't change them without revising all the class.
ABSENT is useful only for internal methods. It is not admitted for defining a literal.- See Also:
-
STRAIGHT
public static final char STRAIGHTConstantSTRAIGHT=''
- See Also:
-
NEGATED
public static final char NEGATEDConstantNEGATED=Constants.NOT
- See Also:
-
UNKNOWN
public static final char UNKNOWNConstantUNKNOWN=Constants.UNKNOWN
- See Also:
-
PROPOSITIONS
-
PROPOSITION_RANGE
-
PROPOSITION_ARRAY
static final char[] PROPOSITION_ARRAYList of possible proposition managed by this class.
Such list is made concatenating 2 blocks: a-z, and A-F. If such blocks are changed, please revisecheck(char)
andindex(char)
methods because it exploits the bounds of such blocks. The length of this array cannot be modified without revising all this class code andLabel
class.- See Also:
-
-
Method Details
-
areComplement
static boolean areComplement(char state1, char state2) - Parameters:
state1
- a possible state of a literal. No integrity check is donestate2
- a possible state of a literal. No integrity check is done- Returns:
- true if state1 and state2 are complement. False otherwise
- See Also:
-
charValue
public static char charValue(int i) - Parameters:
i
- a positive value smaller than 32.- Returns:
- char at position i in PROPOSITION_ARRAY.
-
valueOf
Returns the positive literal ofv
.- Parameters:
v
- a char in the rangePROPOSITION_RANGE
- Returns:
- the straight literal of proposition v
-
valueOf
Return the literal having the givenstate
ofv
. -
check
public static boolean check(char c) - Parameters:
c
- the char to check- Returns:
- true if the char represents a valid literal identifier
-
getStateOrdinal
-
hashCode
-
index
static byte index(char c) - Parameters:
c
- char for proposition- Returns:
- the index of the given proposition
c
inPROPOSITION_ARRAY
if it is a proposition, a negative integer otherwise.
-
parse
Parses the strings
returning the literal represented. -
compareTo
- Specified by:
compareTo
in interfaceComparable<Literal>
-
equals
-
valueOf
Returns a new literal having same proposition ofv
but with state given bystate
. -
getComplement
Returns the complement of this.The complement of a straight literal is the negated one.
The complement of a negated literal is the straight one.
The complement of an unknown literal is null (an empty literal is not possible).- Returns:
- a new literal that it is the negated of this. null if it is request the complement of unknown literal
-
isNegated
public boolean isNegated()- Returns:
- true if it is a negated literal
-
getNegated
Returns a literal that is the negated of this.- Returns:
- a new literal with the same name and state negated
-
getName
public char getName()- Returns:
- the propositional letter associated to this
-
getStraight
Returns a literal that is the straight literal of this.- Returns:
- a new literal with the same name and state straight
-
getUnknown
Returns a literal that is the unknown literal of this.- Returns:
- a new literal with the same name and state unknown
-
getState
public char getState()- Returns:
- the state
-
hashCode
-
isComplement
- Parameters:
l
- a object.- Returns:
- true if it is a complement literal of the given one
-
stateAsString
- Parameters:
state
- state of the literal- Returns:
- the string representation of
state
-
isStraight
public boolean isStraight()- Returns:
- true if it is a straight literal
-
toChars
static char[] toChars(int propositionIndex, char state) -
isUnknown
public boolean isUnknown()- Returns:
- true if it is a literal in the unknown state
-
toString
-