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 ALabel in the CSTNU framework.
The scope of an ALabel is to represent the conjunction of zero or more (upper-case) contingent node names.
Therefore, an ALabel is a conjunction of zero or more ALetters in the alphabet (ALabelAlphabet).
A label without letters is called empty label and it is represented graphically as '\u25c7'.

Design assumptions

Since in the 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 ALabel is to limit the possible ALetters to 64 distinct strings and to use one int for representing the state of ALetters composing an ALabel: present/absent.
Version:
$Rev: 993 $
Author:
Roberto Posenato
See Also:
  • Field Details

    • 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 ALabel. The re-checks only show that label chars are allowed.
    • MAX_ALABELALPHABET_SIZE

      public static final byte MAX_ALABELALPHABET_SIZE
      Maximum size for the alphabet. The ALabel class implementation dictates such a limitation.
      See Also:
    • labelValidator

      public static final org.netbeans.validation.api.Validator<String> labelValidator
      Validator for a graphical interface
    • 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 ALabel using the ALetter 'l' and 'alphabet'. Be aware that if 'l' is not present in the alphabet, it will be added.
      Parameters:
      l - the first ALetter of the label.
      alphabet1 - alphabet of ALetter. 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 in the alphabet as an ALetter, it will be added as an ALetter.
      Parameters:
      s - the string to add.
      alphabet1 - alphabet of ALetter. 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

    • clone

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

      @Nullable public static ALabel parse(String s, ALabelAlphabet alphabet)
      Parse a string representing an ALabel and return an equivalent ALabel object if no errors are found, or if it is 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.
    • clear

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

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

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

      @Nullable public ALabel conjunction(ALabel label)
      Conjoins ALabel 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'. Returns null if this cannot be combined with the given label.
    • contains

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

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

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

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

      public ALabelAlphabet.ALetter getALetter()
      Returns:
      the ALetter format of this ALabel if its size is == 1; null otherwise.
    • 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 the common ALetter between this and the label.
    • isEmpty

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

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

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

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

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

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

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

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

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

      public String toUpperCase()
      Returns:
      upper case version
    • 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 the present ALetter, ALabelAlphabet.DEFAULT_ALETTER_RET_VALUE otherwise.
    • getState

      final ALabel.State getState(byte letterIndex)
      Parameters:
      letterIndex - the index of the literal to retrieve.
      Returns:
      the status of the 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.
    • remove

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