Class Comp
- java.lang.Object
-
- it.unive.lisa.util.datastructures.regex.RegularExpression
-
- it.unive.lisa.util.datastructures.regex.Comp
-
- All Implemented Interfaces:
TransitionSymbol<RegularExpression>
,java.lang.Comparable<RegularExpression>
public final class Comp extends RegularExpression
ARegularExpression
representing the sequential composition of two regular expressions.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class it.unive.lisa.util.datastructures.regex.RegularExpression
RegularExpression.PartialSubstring
-
-
Field Summary
-
Fields inherited from interface it.unive.lisa.util.datastructures.automaton.TransitionSymbol
EPSILON, UNKNOWN_SYMBOL
-
-
Constructor Summary
Constructors Constructor Description Comp(RegularExpression first, RegularExpression second)
Builds the comp.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
compareToAux(RegularExpression other)
AuxiliaryRegularExpression.compareTo(RegularExpression)
that can safely assume thatother
is an object of the same class asthis
.boolean
contains(java.lang.String s)
Yieldstrue
if and only if this regular expression always contains the given string.boolean
endsWith(java.lang.String s)
Yieldstrue
if and only if this regular expression always ends with the given string.boolean
equals(java.lang.Object obj)
RegularExpression[]
explode()
Yields a new regular expression that is the exploded version of this one, that is, where all atoms have been broken down to the composition of the characters that compose their inner strings.RegularExpression
getFirst()
Yields the first regular expression.RegularExpression
getSecond()
Yields the second regular expression.int
hashCode()
boolean
is(java.lang.String str)
Yieldstrue
if and only if this regular expression corresponds to the given string.boolean
isEmpty()
Yieldstrue
if and only if this regular expression corresponds to the empty string or to no strings at all.int
maxLength()
Yields the maximum length of this symbol.boolean
mayContain(java.lang.String s)
Yieldstrue
if and only if this regular expression may contain the given string.boolean
mayEndWith(java.lang.String s)
Yieldstrue
if and only if this regular expression may end with the given string.boolean
mayStartWith(java.lang.String s)
Yieldstrue
if and only if this regular expression may start with the given string.int
minLength()
Yields the minimum length of this symbol.protected boolean
readsWhiteSpaceString()
Checks whether this regular expression recognize a string made just of whitespaces.RegularExpression
repeat(long n)
Yields a new regular expression corresponding to then
-repetition ofthis
.RegularExpression
reverse()
Yields a new symbol that corresponds to this one, but read back-to-front.RegularExpression
simplify()
Yields a simplified version of this regular expression.boolean
startsWith(java.lang.String s)
Yieldstrue
if and only if this regular expression always starts with the given string.protected java.util.Set<RegularExpression.PartialSubstring>
substringAux(int charsToSkip, int missingChars)
Returns the set of all possible substrings of this regular expression, starting at the given index (inclusive) and ending at the given index (exclusive).<A extends Automaton<A,T>,T extends TransitionSymbol<T>>
AtoAutomaton(AutomataFactory<A,T> factory)
Transforms this regular expression into its equivalent automaton.protected RegularExpression
topAsEmptyString()
Yields a new regular expression where allTopAtom
are assumed to have length zero.protected RegularExpression
topAsSingleChar()
Yields a new regular expression where allTopAtom
are assumed to have length one.java.lang.String
toString()
RegularExpression
trimLeft()
Yields a new regular expression where leading whitespaces have been removed fromthis
.RegularExpression
trimRight()
Yields a new regular expression where trailing whitespaces have been removed fromthis
.protected RegularExpression
unrollStarToFixedLength(int length)
Yields a new regular expression where allStar
have been unrolled to a sequence of their inner regular expression of lengthlength
.
-
-
-
Constructor Detail
-
Comp
public Comp(RegularExpression first, RegularExpression second)
Builds the comp.- Parameters:
first
- the first regular expressionsecond
- the second regular expression
-
-
Method Detail
-
getFirst
public RegularExpression getFirst()
Yields the first regular expression.- Returns:
- the first regular expression
-
getSecond
public RegularExpression getSecond()
Yields the second regular expression.- Returns:
- the second regular expression
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
simplify
public RegularExpression simplify()
Description copied from class:RegularExpression
Yields a simplified version of this regular expression. Simplification happens through heuristics.- Specified by:
simplify
in classRegularExpression
- Returns:
- a simplified regular expression equivalent to this
-
toAutomaton
public <A extends Automaton<A,T>,T extends TransitionSymbol<T>> A toAutomaton(AutomataFactory<A,T> factory)
Description copied from class:RegularExpression
Transforms this regular expression into its equivalent automaton.- Specified by:
toAutomaton
in classRegularExpression
- Type Parameters:
A
- the concrete type ofAutomaton
that this method yieldsT
- the concrete type ofTransitionSymbol
s that instances ofA
have on their transitions- Parameters:
factory
- the factory that can be used to create the automaton- Returns:
- the automaton
-
substringAux
protected java.util.Set<RegularExpression.PartialSubstring> substringAux(int charsToSkip, int missingChars)
Description copied from class:RegularExpression
Returns the set of all possible substrings of this regular expression, starting at the given index (inclusive) and ending at the given index (exclusive). Each substring is decorated with the number of characters that are still missing to reach the beginning of the substring, and the number of characters that still need to be added to the string to reach the desired length.- Specified by:
substringAux
in classRegularExpression
- Parameters:
charsToSkip
- the number of characters to skip before starting to collect the substringmissingChars
- the number of missing characters to complete the substring- Returns:
- the set of partial substrings
-
isEmpty
public boolean isEmpty()
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression corresponds to the empty string or to no strings at all.- Specified by:
isEmpty
in classRegularExpression
- Returns:
true
if that condition holds
-
is
public boolean is(java.lang.String str)
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression corresponds to the given string.- Specified by:
is
in classRegularExpression
- Parameters:
str
- the string- Returns:
true
if that condition holds
-
maxLength
public int maxLength()
Description copied from interface:TransitionSymbol
Yields the maximum length of this symbol.- Returns:
- the maximum length
-
minLength
public int minLength()
Description copied from interface:TransitionSymbol
Yields the minimum length of this symbol.- Returns:
- the minimum length
-
mayContain
public boolean mayContain(java.lang.String s)
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression may contain the given string.- Specified by:
mayContain
in classRegularExpression
- Parameters:
s
- the string- Returns:
true
if that condition holds
-
contains
public boolean contains(java.lang.String s)
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression always contains the given string.- Specified by:
contains
in classRegularExpression
- Parameters:
s
- the string- Returns:
true
if that condition holds
-
mayStartWith
public boolean mayStartWith(java.lang.String s)
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression may start with the given string.- Specified by:
mayStartWith
in classRegularExpression
- Parameters:
s
- the string- Returns:
true
if that condition holds
-
startsWith
public boolean startsWith(java.lang.String s)
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression always starts with the given string.- Specified by:
startsWith
in classRegularExpression
- Parameters:
s
- the string- Returns:
true
if that condition holds
-
mayEndWith
public boolean mayEndWith(java.lang.String s)
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression may end with the given string.- Specified by:
mayEndWith
in classRegularExpression
- Parameters:
s
- the string- Returns:
true
if that condition holds
-
endsWith
public boolean endsWith(java.lang.String s)
Description copied from class:RegularExpression
Yieldstrue
if and only if this regular expression always ends with the given string.- Specified by:
endsWith
in classRegularExpression
- Parameters:
s
- the string- Returns:
true
if that condition holds
-
unrollStarToFixedLength
protected RegularExpression unrollStarToFixedLength(int length)
Description copied from class:RegularExpression
Yields a new regular expression where allStar
have been unrolled to a sequence of their inner regular expression of lengthlength
.- Specified by:
unrollStarToFixedLength
in classRegularExpression
- Parameters:
length
- the length- Returns:
- the regular expression with unrolled stars
-
reverse
public RegularExpression reverse()
Description copied from interface:TransitionSymbol
Yields a new symbol that corresponds to this one, but read back-to-front.- Returns:
- the reversed symbol
-
topAsEmptyString
protected RegularExpression topAsEmptyString()
Description copied from class:RegularExpression
Yields a new regular expression where allTopAtom
are assumed to have length zero.- Specified by:
topAsEmptyString
in classRegularExpression
- Returns:
- the regular expression with empty top regular expressions
-
topAsSingleChar
protected RegularExpression topAsSingleChar()
Description copied from class:RegularExpression
Yields a new regular expression where allTopAtom
are assumed to have length one.- Specified by:
topAsSingleChar
in classRegularExpression
- Returns:
- the regular expression with shrinked top regular expressions
-
explode
public RegularExpression[] explode()
Description copied from class:RegularExpression
Yields a new regular expression that is the exploded version of this one, that is, where all atoms have been broken down to the composition of the characters that compose their inner strings.- Specified by:
explode
in classRegularExpression
- Returns:
- the exploded regular expression
-
compareToAux
protected int compareToAux(RegularExpression other)
Description copied from class:RegularExpression
AuxiliaryRegularExpression.compareTo(RegularExpression)
that can safely assume thatother
is an object of the same class asthis
.- Specified by:
compareToAux
in classRegularExpression
- Parameters:
other
- the other regular expression- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
-
repeat
public RegularExpression repeat(long n)
Description copied from class:RegularExpression
Yields a new regular expression corresponding to then
-repetition ofthis
.- Specified by:
repeat
in classRegularExpression
- Parameters:
n
- number of repetitions- Returns:
- a new regular expression corresponding to the
n
-repetition ofthis
-
trimLeft
public RegularExpression trimLeft()
Description copied from class:RegularExpression
Yields a new regular expression where leading whitespaces have been removed fromthis
.- Specified by:
trimLeft
in classRegularExpression
- Returns:
- a new regular expression where leading whitespaces have been
removed from
this
-
trimRight
public RegularExpression trimRight()
Description copied from class:RegularExpression
Yields a new regular expression where trailing whitespaces have been removed fromthis
.- Specified by:
trimRight
in classRegularExpression
- Returns:
- a new regular expression where trailing whitespaces have been
removed from
this
-
readsWhiteSpaceString
protected boolean readsWhiteSpaceString()
Description copied from class:RegularExpression
Checks whether this regular expression recognize a string made just of whitespaces.- Specified by:
readsWhiteSpaceString
in classRegularExpression
- Returns:
true
if this regular expression recognize a string made just of whitespaces,false
otherwise.
-
-