Class Literal

java.lang.Object
it.univr.di.labeledvalue.Literal
All Implemented Interfaces:
Comparable<Literal>

public final class Literal extends Object implements Comparable<Literal>
An immutable 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 Details

    • ABSENT

      public static final char ABSENT
      On 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, and UNKNOWN. 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 STRAIGHT
      Constant STRAIGHT=''
      See Also:
    • NEGATED

      public static final char NEGATED
      Constant NEGATED=Constants.NOT
      See Also:
    • UNKNOWN

      public static final char UNKNOWN
      Constant UNKNOWN=Constants.UNKNOWN
      See Also:
    • PROPOSITIONS

      public static final String PROPOSITIONS
      R.E. representation of allowed propositions.
      See Also:
    • PROPOSITION_RANGE

      public static final String PROPOSITION_RANGE
      R.E. representation of PROPOSITION_ARRAY
      See Also:
    • PROPOSITION_ARRAY

      static final char[] PROPOSITION_ARRAY
      List 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 revise check(char) and index(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 Label 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 done
      state2 - 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

      public static Literal valueOf(char v)
      Returns the positive literal of v.
      Parameters:
      v - a char in the range PROPOSITION_RANGE
      Returns:
      the straight literal of proposition v
    • valueOf

      @Nullable public static Literal valueOf(char v, char state)
      Return the literal having the given state of v.
      Parameters:
      v - the proposition letter
      state - one of possible state of a literal NEGATED or STRAIGHT o UNKNOWN
      Returns:
      a literal with name v and state state, null if the char is not valid or state if ABSENT.
    • 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 to state.
      Parameters:
      state - One of the following value: '\u00ac', '\u0001', '\u00bf'
      Returns:
      the ordinal associated to a proper state, a negative integer if the state is not recognized
    • hashCode

      static int hashCode(char c, char state)
      Hash code for a literal given as char c and state state.
      Parameters:
      c - char for proposition
      state - one of possible state of a literal NEGATED or STRAIGHT o UNKNOWN. No integrity check is done.
      Returns:
      an integer that is surely unique when 'a' ≤ c ≤ 'z'.
    • index

      static byte index(char c)
      Parameters:
      c - char for proposition
      Returns:
      the index of the given proposition c in PROPOSITION_ARRAY if it is a proposition, a negative integer otherwise.
    • parse

      @Nullable public static Literal parse(String s)
      Parses the string s returning the literal represented.
      Parameters:
      s - It can be a single char (PROPOSITION_ARRAY) or one of characters ['\u00ac' '\u00bf'] followed by a char of PROPOSITION_ARRAY. No spaces are allowed
      Returns:
      the literal represented by s if s is a valid representation of a literal, null otherwise
    • compareTo

      public int compareTo(Literal o)
      Specified by:
      compareTo in interface Comparable<Literal>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • valueOf

      public static Literal valueOf(Literal v, char state)
      Returns a new literal having same proposition of v but with state given by state.
      Parameters:
      v - a non null literal v
      state - one of possible state of a literal: NEGATED or STRAIGHT o UNKNOWN
      Returns:
      a new literal having same proposition of v but with state given by state.
    • getComplement

      @Nullable public Literal 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

      public 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

      public Literal getStraight()
      Returns a literal that is the straight literal of this.
      Returns:
      a new literal with the same name and state straight
    • getUnknown

      public Literal 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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isComplement

      public boolean isComplement(Literal l)
      Parameters:
      l - a object.
      Returns:
      true if it is a complement literal of the given one
    • stateAsString

      static String stateAsString(char state)
      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)
      Parameters:
      propositionIndex - index of proposition
      state - one of possible state of a literal NEGATED or STRAIGHT o UNKNOWN
      Returns:
      the char-array representation of a literal identified by its index and state parameter. If state is not correct, an empty array is returned
    • isUnknown

      public boolean isUnknown()
      Returns:
      true if it is a literal in the unknown state
    • toString

      public String toString()
      Overrides:
      toString in class Object