Class ALabel

java.lang.Object
it.univr.di.labeledvalue.ALabel
All Implemented Interfaces:
Serializable, Comparable<ALabel>, Iterable<ALabelAlphabet.ALetter>
Direct Known Subclasses:
ALabel.EmptyLabel

public class ALabel extends Object implements Comparable<ALabel>, Iterable<ALabelAlphabet.ALetter>, Serializable
Simple class to represent a A-label in the CSTNU framework.
Scope of an A-label is to represent the conjunction of zero o more (upper-case) contingent node names.
Therefore, An A-label is a conjunction of zero or more A-Letters in the alphabet (ALabelAlphabet).
A label without letters is called empty label and it is represented graphically as '\u25c7'.

Design assumptions

Since in CSTNU project the memory footprint of a label is an important aspect, after some experiments, I have found that the best way to represent an A-label is to limit the possible A-letters to 64 distinct strings and to use one int for representing the state of A-letters composing an A-label: present/absent.
Version:
$Rev: 887 $
Author:
Roberto Posenato
See Also:
  • Field Details

    • labelValidator

      public static final org.netbeans.validation.api.Validator<String> labelValidator
      Validator for graphical interface
    • ALABEL_SEPARATOR

      public static final char ALABEL_SEPARATOR
      ALabel separator '∙'.
      See Also:
    • ALABEL_SEPARATORstring

      public static final String ALABEL_SEPARATORstring
      ALabel separator '∙'.
    • ALABEL_RE

      public static final String ALABEL_RE
      Regular expression representing an A-Label. The re checks only that label chars are allowed.
    • MAX_ALABELALPHABET_SIZE

      public static final byte MAX_ALABELALPHABET_SIZE
      Maximum size for the alphabet. Such limitation is dictated by the ALabel class implementation.
      See Also:
    • emptyLabel

      public static final ALabel emptyLabel
      A constant empty label to represent an empty label that cannot be modified.
    • modCount

      protected transient int modCount
      The number of times this ALabel has been structurally modified. Structural modifications are those that change the size, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.
  • Constructor Details

    • ALabel

      public ALabel(ALabelAlphabet.ALetter l, ALabelAlphabet alphabet1)
      Builds an a-label using the a-letter 'l' and 'alphabet'. Be aware that if 'l' is not present into alphabet, it will be added.
      Parameters:
      l - first a-letter of label
      alphabet1 - alphabet of a-letters. It may be empty!
    • ALabel

      public ALabel(String s, ALabelAlphabet alphabet1)
      Helper constructor. It calls ALabel(ALetter, ALabelAlphabet). Be aware that if 's' is not present into alphabet as a-letter, it will be added as a-letter.
      Parameters:
      s - the string to add.
      alphabet1 - alphabet of a-letters. It may be empty!
    • ALabel

      public ALabel(ALabelAlphabet alphabet1)
      Default constructor using a given alphabet.
      Parameters:
      alphabet1 - the input alphabet. It cannot be null.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns:
      true if the label contains no literal.
    • conjoin

      public boolean conjoin(ALabelAlphabet.ALetter aLetter)
      Conjoins a-letter to this.
      Parameters:
      aLetter - the a-letter to conjoin.
      Returns:
      true if a-letter is added, false otherwise.
    • clear

      public void clear()
      Makes the label empty.
    • clone

      public static ALabel clone(ALabel label)
      In order to have a correct copy of an a-label.
      Parameters:
      label - the input value
      Returns:
      a distinct equal copy of label
    • parse

      @Nullable public static ALabel parse(String s, ALabelAlphabet alphabet)
      Parse a string representing an A-label and return an equivalent A-Label object if no errors are found, null otherwise.
      The regular expression syntax for a label is specified in Label.LABEL_RE.
      Parameters:
      s - a String object.
      alphabet - A ALabelAlphabet to use. If null, it will be generated and added to the return label.
      Returns:
      a Label object corresponding to the label string representation.
    • compareTo

      public int compareTo(@Nonnull ALabel label)
      In order to speed up this method and considering that the ALabelAlphabet order may be not the expected alphabetic one, (first letter in an ALabelAlphabet can be 'nodeZ' and the last one 'aNode'), the order of labels is given w.r.t. their indexes in their ALabelAlphabet.
      Specified by:
      compareTo in interface Comparable<ALabel>
    • conjunction

      @Nullable public ALabel conjunction(ALabel label)
      Conjoins a-label to this and returns the result without modifying this.
      Parameters:
      label - the label to conjoin
      Returns:
      a new label with the conjunction of 'this' and 'label'. Regurns null if this cannot conjuncted with label.
    • contains

      public boolean contains(ALabel label)
      L1 contains L2 if L1 contains all a-letters of L2.
      Parameters:
      label - the label to check
      Returns:
      true if this contains label.
    • contains

      public boolean contains(ALabelAlphabet.ALetter name)
      Parameters:
      name - the proposition to check.
      Returns:
      true if this contains proposition in any state: straight, negated or unknown.
    • getState

      final ALabel.State getState(byte letterIndex)
      Parameters:
      letterIndex - the index of the literal to retrieve.
      Returns:
      the status of literal with index literalIndex. If the literal is not present or the index is not in the range of present ALetters, it returns ALabel.State.absent, otherwise ALabel.State.present.
    • equals

      public boolean equals(ALabelAlphabet.ALetter name)
      Compare the letter with an a-letter name.
      Parameters:
      name - the input aletter
      Returns:
      true if the label is equal to the a-letter name.
    • size

      public int size()
      Returns:
      Return the number of literals of the label
    • equals

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

      public ALabelAlphabet getAlphabet()
      Returns:
      the alphabet
    • hashCode

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

      public ALabel intersect(ALabel label)
      Parameters:
      label - the input label
      Returns:
      the label containing common ALetter between this and label.
    • toLowerCase

      public String toLowerCase()
      Returns:
      lower case version
    • iterator

      @Nonnull public Iterator<ALabelAlphabet.ALetter> iterator()
      Specified by:
      iterator in interface Iterable<ALabelAlphabet.ALetter>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getALetter

      public ALabelAlphabet.ALetter getALetter()
      Returns:
      the ALetter format of this ALabel if its size is == 1; null otherwise.
    • put

      public boolean put(ALabelAlphabet.ALetter l)
      Parameters:
      l - the letter to add
      Returns:
      true if a-letter is added, false otherwise.
    • remove

      public void remove(ALabel aLabel)
      It removes all a-letters in aLabel from the current label.
      Parameters:
      aLabel - a-Label to remove.
    • remove

      public void remove(ALabelAlphabet.ALetter letter)
      It removes a-letter if it is present, otherwise it does nothing.
      Parameters:
      letter - the letter to remove.
    • remove

      public void remove(ALabelAlphabet.ALetter[] inputSet)
      It removes all a-letters in inputSet from the current label.
      Parameters:
      inputSet - a-letters to remove.
    • remove

      final void remove(byte index)
      Parameters:
      index - the index of the letter to remove.
    • getLetter

      final ALabelAlphabet.ALetter getLetter(byte letterIndex)
      Parameters:
      letterIndex - the index of the literal to retrieve.
      Returns:
      the letter with index literalIndex if index is in the range of present ALetter, ALabelAlphabet.DEFAULT_ALETTER_RET_VALUE otherwise.
    • toUpperCase

      public String toUpperCase()
      Returns:
      upper case version