Package it.univr.di.labeledvalue
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 (
A label without letters is called empty label and it is represented graphically as '\u25c7'.
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 oneint
for representing the state of ALetters composing an ALabel: present/absent.- Version:
- $Rev: 993 $
- Author:
- Roberto Posenato
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
An unmodifiable empty label.static enum
Possible state of aALabelAlphabet.ALetter
in an alphabetic label. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Regular expression representing an ALabel.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 a graphical interfacestatic final byte
Maximum size for the alphabet.protected int
The number of times this ALabel has been structurally modified. -
Constructor Summary
ConstructorsConstructorDescriptionALabel
(ALabelAlphabet alphabet1) Default constructor using a given alphabet.ALabel
(ALabelAlphabet.ALetter l, ALabelAlphabet alphabet1) Builds an ALabel using the ALetter 'l' and 'alphabet'.ALabel
(String s, ALabelAlphabet alphabet1) Helper constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Makes the label empty.static ALabel
To have a correct copy of an ALabel.int
To speed up this method, and considering that theALabelAlphabet
order may not be the expected alphabetic one (the first letter in anALabelAlphabet
can be 'nodeZ' and the last one 'aNode'), the order of labels is given with respect to their indexes in theirALabelAlphabet
.boolean
conjoin
(ALabelAlphabet.ALetter aLetter) ConjoinsALetter
to this.conjunction
(ALabel label) ConjoinsALabel
tothis
and returns the result without modifyingthis
.boolean
L1 contains L2 if L1 contains all ALetters of L2.boolean
boolean
equals
(ALabelAlphabet.ALetter name) Compare the letter with an ALetter 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 ALabel and return an equivalent ALabel object if no errors are found, or if it is null otherwise.boolean
(package private) final void
remove
(byte index) void
It removes all ALetters in ALabel from the current label.void
remove
(ALabelAlphabet.ALetter letter) It removes the ALetter if it is present.void
remove
(ALabelAlphabet.ALetter[] inputSet) It removes all ALetters 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
-
ALABEL_SEPARATOR
public static final char ALABEL_SEPARATORALabel separator '∙'.- See Also:
-
ALABEL_SEPARATORstring
ALabel separator '∙'. -
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_SIZEMaximum size for the alphabet. The ALabel class implementation dictates such a limitation.- See Also:
-
labelValidator
Validator for a graphical interface -
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 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
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
Default constructor using a given alphabet.- Parameters:
alphabet1
- the input alphabet. It cannot be null.
-
-
Method Details
-
clone
To have a correct copy of an ALabel.- Parameters:
label
- the input value- Returns:
- a distinct equal copy of the label
-
parse
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 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.
-
clear
public void clear()Makes the label empty. -
compareTo
To speed up this method, and considering that theALabelAlphabet
order may not be the expected alphabetic one (the first letter in anALabelAlphabet
can be 'nodeZ' and the last one 'aNode'), the order of labels is given with respect to their indexes in theirALabelAlphabet
.- Specified by:
compareTo
in interfaceComparable<ALabel>
-
conjoin
ConjoinsALetter
to this.- Parameters:
aLetter
- the ALetter to conjoin.- Returns:
- true if ALetter is added, false otherwise.
-
conjunction
ConjoinsALabel
tothis
and returns the result without modifyingthis
.- 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
L1 contains L2 if L1 contains all ALetters of L2.- Parameters:
label
- the label to check- Returns:
- true if this contains the label.
-
contains
- Parameters:
name
- the proposition to check.- Returns:
- true if this contains the proposition in any state: straight, negated, or unknown.
-
equals
Compare the letter with an ALetter name.- Parameters:
name
- the input ALetter- Returns:
- true if the label is equal to the ALetter name.
-
equals
-
getALetter
- Returns:
- the ALetter format of this ALabel if its size is == 1; null otherwise.
-
getAlphabet
- Returns:
- the alphabet
-
hashCode
public int hashCode() -
intersect
- 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
- Specified by:
iterator
in interfaceIterable<ALabelAlphabet.ALetter>
-
put
- Parameters:
l
- the letter to add- Returns:
- true if ALetter is added, false otherwise.
-
remove
It removes all ALetters in ALabel from the current label.- Parameters:
aLabel
- ALabel to remove.
-
remove
It removes the ALetter if it is present. Otherwise, it does nothing.- Parameters:
letter
- the letter to remove.
-
remove
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
- Returns:
- lower case version
-
toString
-
toUpperCase
- Returns:
- upper case version
-
getLetter
- 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
- 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
, otherwiseALabel.State.present
.
-
remove
final void remove(byte index) - Parameters:
index
- the index of the letter to remove.
-