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
ARegularExpressionrepresenting 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 intcompareToAux(RegularExpression other)AuxiliaryRegularExpression.compareTo(RegularExpression)that can safely assume thatotheris an object of the same class asthis.booleancontains(java.lang.String s)Yieldstrueif and only if this regular expression always contains the given string.booleanendsWith(java.lang.String s)Yieldstrueif and only if this regular expression always ends with the given string.booleanequals(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.RegularExpressiongetFirst()Yields the first regular expression.RegularExpressiongetSecond()Yields the second regular expression.inthashCode()booleanis(java.lang.String str)Yieldstrueif and only if this regular expression corresponds to the given string.booleanisEmpty()Yieldstrueif and only if this regular expression corresponds to the empty string or to no strings at all.intmaxLength()Yields the maximum length of this symbol.booleanmayContain(java.lang.String s)Yieldstrueif and only if this regular expression may contain the given string.booleanmayEndWith(java.lang.String s)Yieldstrueif and only if this regular expression may end with the given string.booleanmayStartWith(java.lang.String s)Yieldstrueif and only if this regular expression may start with the given string.intminLength()Yields the minimum length of this symbol.protected booleanreadsWhiteSpaceString()Checks whether this regular expression recognize a string made just of whitespaces.RegularExpressionrepeat(long n)Yields a new regular expression corresponding to then-repetition ofthis.RegularExpressionreverse()Yields a new symbol that corresponds to this one, but read back-to-front.RegularExpressionsimplify()Yields a simplified version of this regular expression.booleanstartsWith(java.lang.String s)Yieldstrueif 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 RegularExpressiontopAsEmptyString()Yields a new regular expression where allTopAtomare assumed to have length zero.protected RegularExpressiontopAsSingleChar()Yields a new regular expression where allTopAtomare assumed to have length one.java.lang.StringtoString()RegularExpressiontrimLeft()Yields a new regular expression where leading whitespaces have been removed fromthis.RegularExpressiontrimRight()Yields a new regular expression where trailing whitespaces have been removed fromthis.protected RegularExpressionunrollStarToFixedLength(int length)Yields a new regular expression where allStarhave 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:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
simplify
public RegularExpression simplify()
Description copied from class:RegularExpressionYields a simplified version of this regular expression. Simplification happens through heuristics.- Specified by:
simplifyin 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:RegularExpressionTransforms this regular expression into its equivalent automaton.- Specified by:
toAutomatonin classRegularExpression- Type Parameters:
A- the concrete type ofAutomatonthat this method yieldsT- the concrete type ofTransitionSymbols that instances ofAhave 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:RegularExpressionReturns 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:
substringAuxin 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:RegularExpressionYieldstrueif and only if this regular expression corresponds to the empty string or to no strings at all.- Specified by:
isEmptyin classRegularExpression- Returns:
trueif that condition holds
-
is
public boolean is(java.lang.String str)
Description copied from class:RegularExpressionYieldstrueif and only if this regular expression corresponds to the given string.- Specified by:
isin classRegularExpression- Parameters:
str- the string- Returns:
trueif that condition holds
-
maxLength
public int maxLength()
Description copied from interface:TransitionSymbolYields the maximum length of this symbol.- Returns:
- the maximum length
-
minLength
public int minLength()
Description copied from interface:TransitionSymbolYields the minimum length of this symbol.- Returns:
- the minimum length
-
mayContain
public boolean mayContain(java.lang.String s)
Description copied from class:RegularExpressionYieldstrueif and only if this regular expression may contain the given string.- Specified by:
mayContainin classRegularExpression- Parameters:
s- the string- Returns:
trueif that condition holds
-
contains
public boolean contains(java.lang.String s)
Description copied from class:RegularExpressionYieldstrueif and only if this regular expression always contains the given string.- Specified by:
containsin classRegularExpression- Parameters:
s- the string- Returns:
trueif that condition holds
-
mayStartWith
public boolean mayStartWith(java.lang.String s)
Description copied from class:RegularExpressionYieldstrueif and only if this regular expression may start with the given string.- Specified by:
mayStartWithin classRegularExpression- Parameters:
s- the string- Returns:
trueif that condition holds
-
startsWith
public boolean startsWith(java.lang.String s)
Description copied from class:RegularExpressionYieldstrueif and only if this regular expression always starts with the given string.- Specified by:
startsWithin classRegularExpression- Parameters:
s- the string- Returns:
trueif that condition holds
-
mayEndWith
public boolean mayEndWith(java.lang.String s)
Description copied from class:RegularExpressionYieldstrueif and only if this regular expression may end with the given string.- Specified by:
mayEndWithin classRegularExpression- Parameters:
s- the string- Returns:
trueif that condition holds
-
endsWith
public boolean endsWith(java.lang.String s)
Description copied from class:RegularExpressionYieldstrueif and only if this regular expression always ends with the given string.- Specified by:
endsWithin classRegularExpression- Parameters:
s- the string- Returns:
trueif that condition holds
-
unrollStarToFixedLength
protected RegularExpression unrollStarToFixedLength(int length)
Description copied from class:RegularExpressionYields a new regular expression where allStarhave been unrolled to a sequence of their inner regular expression of lengthlength.- Specified by:
unrollStarToFixedLengthin classRegularExpression- Parameters:
length- the length- Returns:
- the regular expression with unrolled stars
-
reverse
public RegularExpression reverse()
Description copied from interface:TransitionSymbolYields 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:RegularExpressionYields a new regular expression where allTopAtomare assumed to have length zero.- Specified by:
topAsEmptyStringin classRegularExpression- Returns:
- the regular expression with empty top regular expressions
-
topAsSingleChar
protected RegularExpression topAsSingleChar()
Description copied from class:RegularExpressionYields a new regular expression where allTopAtomare assumed to have length one.- Specified by:
topAsSingleCharin classRegularExpression- Returns:
- the regular expression with shrinked top regular expressions
-
explode
public RegularExpression[] explode()
Description copied from class:RegularExpressionYields 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:
explodein classRegularExpression- Returns:
- the exploded regular expression
-
compareToAux
protected int compareToAux(RegularExpression other)
Description copied from class:RegularExpressionAuxiliaryRegularExpression.compareTo(RegularExpression)that can safely assume thatotheris an object of the same class asthis.- Specified by:
compareToAuxin 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:RegularExpressionYields a new regular expression corresponding to then-repetition ofthis.- Specified by:
repeatin 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:RegularExpressionYields a new regular expression where leading whitespaces have been removed fromthis.- Specified by:
trimLeftin classRegularExpression- Returns:
- a new regular expression where leading whitespaces have been
removed from
this
-
trimRight
public RegularExpression trimRight()
Description copied from class:RegularExpressionYields a new regular expression where trailing whitespaces have been removed fromthis.- Specified by:
trimRightin classRegularExpression- Returns:
- a new regular expression where trailing whitespaces have been
removed from
this
-
readsWhiteSpaceString
protected boolean readsWhiteSpaceString()
Description copied from class:RegularExpressionChecks whether this regular expression recognize a string made just of whitespaces.- Specified by:
readsWhiteSpaceStringin classRegularExpression- Returns:
trueif this regular expression recognize a string made just of whitespaces,falseotherwise.
-
-