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 are the standard ones, the semantics for an unknown literal are particular to the CSTN/CSTNU application.
An unknown literal, as '¿p' for example, is true if the value of the 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 the proposition letter 'p' is unknown. In the instant the value of 'p' is set, '¿p' becomes false, and the associated state is no longer valid.
A literal object is immutable and must have a propositional letter.
Lastly, for efficiency reasons, this class allows for representing literals 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 an integer (32 bits), so labels with at most 32 different propositions.
- Version:
- $Rev: 993 $
- Author:
- Roberto Posenato
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
On 2017-10-27, using VisualVM, it was shown that representing the state values of a literal using an enum consumes a lot of memory in this kind of application.static final char
ConstantNEGATED=Constants.NOT
(package private) static final char[]
List of possible propositions managed by this class.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 negation 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 2017-10-27, using VisualVM, it was 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 four constant values: ABSENT,
STRAIGHT
,NEGATED
, andUNKNOWN
. The char corresponding to each such constant is exploited in the class (to make them more efficient). So, don't change them without revising the whole class.ABSENT is useful only for internal methods. It is not admitted for defining a literal.
- See Also:
-
NEGATED
public static final char NEGATEDConstantNEGATED=Constants.NOT
- See Also:
-
PROPOSITIONS
R.E. representation of allowed propositions.- See Also:
-
PROPOSITION_RANGE
R.E. representation of PROPOSITION_ARRAY- See Also:
-
STRAIGHT
public static final char STRAIGHTConstantSTRAIGHT=''
- See Also:
-
UNKNOWN
public static final char UNKNOWNConstantUNKNOWN=Constants.UNKNOWN
- See Also:
-
PROPOSITION_ARRAY
static final char[] PROPOSITION_ARRAYList of possible propositions managed by this class.Such a list is made by concatenating two blocks: a-z, and A-F.
If such blocks are changed, please revise
check(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 and theLabel
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.
-
check
public static boolean check(char c) - Parameters:
c
- the char to check- Returns:
- true if the char represents a valid literal identifier
-
getStateOrdinal
static byte getStateOrdinal(char state) Returns the ordinal associate tostate
. -
hashCode
static int hashCode(char c, char state) Hash code for a literal given as charc
and statestate
. -
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. -
stateAsString
- Parameters:
state
- state of the literal- Returns:
- the string representation of
state
-
toChars
static char[] toChars(int propositionIndex, char state) -
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
. -
valueOf
Returns a new literal having same proposition ofv
but with state given bystate
. -
compareTo
- Specified by:
compareTo
in interfaceComparable<Literal>
-
equals
-
getComplement
Returns the complement of this.The complement of a straight literal is the negated one.
- Returns:
- a new literal that is the complement of an unknown literal, which is null (an empty literal is not possible).
-
getName
public char getName()- Returns:
- the propositional letter associated with this
-
getNegated
Returns a literal that is the negation of this.- Returns:
- a new literal with the same name and state negated
-
getState
public char getState()- Returns:
- the state
-
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
-
hashCode
public int hashCode() -
isComplement
- Parameters:
l
- an object.- Returns:
- true if it is a complement literal of the given one
-
isNegated
public boolean isNegated()- Returns:
- true if it is a negated literal
-
isStraight
public boolean isStraight()- Returns:
- true if it is a straight literal
-
isUnknown
public boolean isUnknown()- Returns:
- true if it is a literal in the unknown state
-
toString
-