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 (
A label without letters is called empty label and it is represented graphically as '\u25c7'.
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 oneint
for representing the state of A-letters composing an A-label: present/absent.- Version:
- $Rev: 887 $
- Author:
- Roberto Posenato
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
An unmodifiable empty label.static enum
Possible state of aALabelAlphabet.ALetter
in an alphabetic label. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Regular expression representing an A-Label.static final char
ALabel separator '∙'.static final String
ALabel separator '∙'.static final ALabel
A constant empty label to represent an empty label that cannot be modified.static final org.netbeans.validation.api.Validator
<String> Validator for graphical interfacestatic final byte
Maximum size for the alphabet.protected int
The number of times this ALabel has been structurally modified. -
Constructor Summary
ConstructorDescriptionALabel
(ALabelAlphabet alphabet1) Default constructor using a given alphabet.ALabel
(ALabelAlphabet.ALetter l, ALabelAlphabet alphabet1) Builds an a-label using the a-letter 'l' and 'alphabet'.ALabel
(String s, ALabelAlphabet alphabet1) Helper constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Makes the label empty.static ALabel
In order to have a correct copy of an a-label.int
In order to speed up this method and considering that theALabelAlphabet
order may be not the expected alphabetic one, (first letter in anALabelAlphabet
can be 'nodeZ' and the last one 'aNode'), the order of labels is given w.r.t. their indexes in theirALabelAlphabet
.boolean
conjoin
(ALabelAlphabet.ALetter aLetter) Conjoinsa-letter
to this.conjunction
(ALabel label) Conjoinsa-label
tothis
and returns the result without modifyingthis
.boolean
L1 contains L2 if L1 contains all a-letters of L2.boolean
boolean
equals
(ALabelAlphabet.ALetter name) Compare the letter with an a-letter name.boolean
(package private) final ALabelAlphabet.ALetter
getLetter
(byte letterIndex) (package private) final ALabel.State
getState
(byte letterIndex) int
hashCode()
boolean
isEmpty()
iterator()
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.boolean
(package private) final void
remove
(byte index) void
It removes all a-letters in aLabel from the current label.void
remove
(ALabelAlphabet.ALetter letter) It removes a-letter if it is present, otherwise it does nothing.void
remove
(ALabelAlphabet.ALetter[] inputSet) It removes all a-letters in inputSet from the current label.int
size()
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
labelValidator
Validator for graphical interface -
ALABEL_SEPARATOR
public static final char ALABEL_SEPARATORALabel separator '∙'.- See Also:
-
ALABEL_SEPARATORstring
ALabel separator '∙'. -
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_SIZEMaximum size for the alphabet. Such limitation is dictated by the ALabel class implementation.- See Also:
-
emptyLabel
A constant empty label to represent an empty label that cannot be modified. -
modCount
protected transient int modCountThe 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
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 labelalphabet1
- alphabet of a-letters. It may be empty!
-
ALabel
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
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
Conjoinsa-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
-
parse
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 inLabel.LABEL_RE
.- Parameters:
s
- aString
object.alphabet
- AALabelAlphabet
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
In order to speed up this method and considering that theALabelAlphabet
order may be not the expected alphabetic one, (first letter in anALabelAlphabet
can be 'nodeZ' and the last one 'aNode'), the order of labels is given w.r.t. their indexes in theirALabelAlphabet
.- Specified by:
compareTo
in interfaceComparable<ALabel>
-
conjunction
-
contains
L1 contains L2 if L1 contains all a-letters of L2.- Parameters:
label
- the label to check- Returns:
- true if this contains label.
-
contains
- Parameters:
name
- the proposition to check.- Returns:
- true if this contains proposition in any state: straight, negated or unknown.
-
getState
- 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
, otherwiseALabel.State.present
.
-
equals
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
-
getAlphabet
- Returns:
- the alphabet
-
hashCode
-
intersect
-
toLowerCase
- Returns:
- lower case version
-
iterator
- Specified by:
iterator
in interfaceIterable<ALabelAlphabet.ALetter>
-
toString
-
getALetter
- Returns:
- the ALetter format of this ALabel if its size is == 1; null otherwise.
-
put
- Parameters:
l
- the letter to add- Returns:
- true if a-letter is added, false otherwise.
-
remove
It removes all a-letters in aLabel from the current label.- Parameters:
aLabel
- a-Label to remove.
-
remove
It removes a-letter if it is present, otherwise it does nothing.- Parameters:
letter
- the letter to remove.
-
remove
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
- 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
- Returns:
- upper case version
-