Class RegularExpression
- java.lang.Object
-
- it.unive.lisa.util.datastructures.regex.RegularExpression
-
- All Implemented Interfaces:
TransitionSymbol<RegularExpression>,java.lang.Comparable<RegularExpression>
public abstract class RegularExpression extends java.lang.Object implements TransitionSymbol<RegularExpression>
A regular expression that can be recognized by anAutomaton, or that can be used to represent the language recognized by an automaton.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRegularExpression.PartialSubstringA class that represents an intermediate result of the computation ofsubstring(int, int).
-
Field Summary
-
Fields inherited from interface it.unive.lisa.util.datastructures.automaton.TransitionSymbol
EPSILON, UNKNOWN_SYMBOL
-
-
Constructor Summary
Constructors Constructor Description RegularExpression()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AtomasAtom()CompasComp()EmptySetasEmptySet()OrasOr()StarasStar()RegularExpressioncomp(RegularExpression other)Joins together two regular expression, that is, it builds aComprecognizing this regular expression first, and thanother.intcompareTo(RegularExpression o)protected abstract intcompareToAux(RegularExpression other)AuxiliarycompareTo(RegularExpression)that can safely assume thatotheris an object of the same class asthis.abstract booleancontains(java.lang.String s)Yieldstrueif and only if this regular expression always contains the given string.abstract booleanendsWith(java.lang.String s)Yieldstrueif and only if this regular expression always ends with the given string.abstract 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.abstract booleanis(java.lang.String str)Yieldstrueif and only if this regular expression corresponds to the given string.booleanisAtom()Yieldstrueif and only if this regular expression is an instance ofAtom.booleanisComp()Yieldstrueif and only if this regular expression is an instance ofComp.abstract booleanisEmpty()Yieldstrueif and only if this regular expression corresponds to the empty string or to no strings at all.booleanisEmptySet()Yieldstrueif and only if this regular expression is an instance ofEmptySet.booleanisEpsilon()Yieldstrueif and only if this symbol represents the empty string epsilon.booleanisOr()Yieldstrueif and only if this regular expression is an instance ofOr.booleanisStar()Yieldstrueif and only if this regular expression is an instance ofStar.abstract booleanmayContain(java.lang.String s)Yieldstrueif and only if this regular expression may contain the given string.abstract booleanmayEndWith(java.lang.String s)Yieldstrueif and only if this regular expression may end with the given string.abstract booleanmayStartWith(java.lang.String s)Yieldstrueif and only if this regular expression may start with the given string.RegularExpressionor(RegularExpression other)Builds the disjunction (Or) betweenthisand the given regular expression.protected abstract booleanreadsWhiteSpaceString()Checks whether this regular expression recognize a string made just of whitespaces.abstract RegularExpressionrepeat(long n)Yields a new regular expression corresponding to then-repetition ofthis.abstract RegularExpressionsimplify()Yields a simplified version of this regular expression.RegularExpressionstar()Builds the Kleene closure of this regular expression (Star), recognizingthiszero or more times.abstract booleanstartsWith(java.lang.String s)Yieldstrueif and only if this regular expression always starts with the given string.java.util.Set<SymbolicString>substring(int start, int end)Returns the set of all possible substrings of this regular expression, starting at the given index (inclusive) and ending at the given index (exclusive).protected abstract 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).abstract <A extends Automaton<A,T>,T extends TransitionSymbol<T>>
AtoAutomaton(AutomataFactory<A,T> factory)Transforms this regular expression into its equivalent automaton.protected abstract RegularExpressiontopAsEmptyString()Yields a new regular expression where allTopAtomare assumed to have length zero.protected abstract RegularExpressiontopAsSingleChar()Yields a new regular expression where allTopAtomare assumed to have length one.abstract RegularExpressiontrimLeft()Yields a new regular expression where leading whitespaces have been removed fromthis.abstract RegularExpressiontrimRight()Yields a new regular expression where trailing whitespaces have been removed fromthis.protected abstract RegularExpressionunrollStarToFixedLength(int length)Yields a new regular expression where allStarhave been unrolled to a sequence of their inner regular expression of lengthlength.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface it.unive.lisa.util.datastructures.automaton.TransitionSymbol
maxLength, minLength, reverse
-
-
-
-
Method Detail
-
compareTo
public final int compareTo(RegularExpression o)
- Specified by:
compareToin interfacejava.lang.Comparable<RegularExpression>
-
compareToAux
protected abstract int compareToAux(RegularExpression other)
AuxiliarycompareTo(RegularExpression)that can safely assume thatotheris an object of the same class asthis.- 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
-
isEpsilon
public boolean isEpsilon()
Description copied from interface:TransitionSymbolYieldstrueif and only if this symbol represents the empty string epsilon.- Specified by:
isEpsilonin interfaceTransitionSymbol<RegularExpression>- Returns:
trueif that condition holds.
-
simplify
public abstract RegularExpression simplify()
Yields a simplified version of this regular expression. Simplification happens through heuristics.- Returns:
- a simplified regular expression equivalent to this
-
toAutomaton
public abstract <A extends Automaton<A,T>,T extends TransitionSymbol<T>> A toAutomaton(AutomataFactory<A,T> factory)
Transforms this regular expression into its equivalent automaton.- 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
-
asAtom
public final Atom asAtom()
Casts this regular expression to anAtomif this regular expression is anAtom. Returnsnullotherwise.- Returns:
- this regular expression casted to
Atom, ornull
-
isAtom
public final boolean isAtom()
Yieldstrueif and only if this regular expression is an instance ofAtom.- Returns:
trueif that condition holds
-
asComp
public final Comp asComp()
Casts this regular expression to aCompif this regular expression is aComp. Returnsnullotherwise.- Returns:
- this regular expression casted to
Comp, ornull
-
isComp
public final boolean isComp()
Yieldstrueif and only if this regular expression is an instance ofComp.- Returns:
trueif that condition holds
-
asEmptySet
public final EmptySet asEmptySet()
Casts this regular expression to anEmptySetif this regular expression is anEmptySet. Returnsnullotherwise.- Returns:
- this regular expression casted to
EmptySet, ornull
-
isEmptySet
public final boolean isEmptySet()
Yieldstrueif and only if this regular expression is an instance ofEmptySet.- Returns:
trueif that condition holds
-
isOr
public final boolean isOr()
Yieldstrueif and only if this regular expression is an instance ofOr.- Returns:
trueif that condition holds
-
asStar
public final Star asStar()
Casts this regular expression to aStarif this regular expression is aStar. Returnsnullotherwise.- Returns:
- this regular expression casted to
Star, ornull
-
isStar
public final boolean isStar()
Yieldstrueif and only if this regular expression is an instance ofStar.- Returns:
trueif that condition holds
-
substring
public final java.util.Set<SymbolicString> substring(int start, int end)
Returns the set of all possible substrings of this regular expression, starting at the given index (inclusive) and ending at the given index (exclusive).- Parameters:
start- the start indexend- the end index- Returns:
- the set of all substrings
-
substringAux
protected abstract 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). 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.- 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
-
repeat
public abstract RegularExpression repeat(long n)
Yields a new regular expression corresponding to then-repetition ofthis.- Parameters:
n- number of repetitions- Returns:
- a new regular expression corresponding to the
n-repetition ofthis
-
trimLeft
public abstract RegularExpression trimLeft()
Yields a new regular expression where leading whitespaces have been removed fromthis.- Returns:
- a new regular expression where leading whitespaces have been
removed from
this
-
trimRight
public abstract RegularExpression trimRight()
Yields a new regular expression where trailing whitespaces have been removed fromthis.- Returns:
- a new regular expression where trailing whitespaces have been
removed from
this
-
isEmpty
public abstract boolean isEmpty()
Yieldstrueif and only if this regular expression corresponds to the empty string or to no strings at all.- Returns:
trueif that condition holds
-
is
public abstract boolean is(java.lang.String str)
Yieldstrueif and only if this regular expression corresponds to the given string.- Parameters:
str- the string- Returns:
trueif that condition holds
-
mayContain
public abstract boolean mayContain(java.lang.String s)
Yieldstrueif and only if this regular expression may contain the given string.- Parameters:
s- the string- Returns:
trueif that condition holds
-
contains
public abstract boolean contains(java.lang.String s)
Yieldstrueif and only if this regular expression always contains the given string.- Parameters:
s- the string- Returns:
trueif that condition holds
-
mayStartWith
public abstract boolean mayStartWith(java.lang.String s)
Yieldstrueif and only if this regular expression may start with the given string.- Parameters:
s- the string- Returns:
trueif that condition holds
-
startsWith
public abstract boolean startsWith(java.lang.String s)
Yieldstrueif and only if this regular expression always starts with the given string.- Parameters:
s- the string- Returns:
trueif that condition holds
-
mayEndWith
public abstract boolean mayEndWith(java.lang.String s)
Yieldstrueif and only if this regular expression may end with the given string.- Parameters:
s- the string- Returns:
trueif that condition holds
-
endsWith
public abstract boolean endsWith(java.lang.String s)
Yieldstrueif and only if this regular expression always ends with the given string.- Parameters:
s- the string- Returns:
trueif that condition holds
-
unrollStarToFixedLength
protected abstract RegularExpression unrollStarToFixedLength(int length)
Yields a new regular expression where allStarhave been unrolled to a sequence of their inner regular expression of lengthlength.- Parameters:
length- the length- Returns:
- the regular expression with unrolled stars
-
topAsSingleChar
protected abstract RegularExpression topAsSingleChar()
Yields a new regular expression where allTopAtomare assumed to have length one.- Returns:
- the regular expression with shrinked top regular expressions
-
topAsEmptyString
protected abstract RegularExpression topAsEmptyString()
Yields a new regular expression where allTopAtomare assumed to have length zero.- Returns:
- the regular expression with empty top regular expressions
-
explode
public abstract 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.- Returns:
- the exploded regular expression
-
readsWhiteSpaceString
protected abstract boolean readsWhiteSpaceString()
Checks whether this regular expression recognize a string made just of whitespaces.- Returns:
trueif this regular expression recognize a string made just of whitespaces,falseotherwise.
-
star
public final RegularExpression star()
Builds the Kleene closure of this regular expression (Star), recognizingthiszero or more times.- Returns:
- the closure of this regular expression
-
comp
public final RegularExpression comp(RegularExpression other)
Joins together two regular expression, that is, it builds aComprecognizing this regular expression first, and thanother.- Parameters:
other- the other regular expression- Returns:
- the joined regular expression
-
or
public final RegularExpression or(RegularExpression other)
Builds the disjunction (Or) betweenthisand the given regular expression.- Parameters:
other- the other regular expression- Returns:
- the disjunction
-
-