Class RegularExpression

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Atom asAtom()
      Casts this regular expression to an Atom if this regular expression is an Atom.
      Comp asComp()
      Casts this regular expression to a Comp if this regular expression is a Comp.
      EmptySet asEmptySet()
      Casts this regular expression to an EmptySet if this regular expression is an EmptySet.
      Or asOr()
      Casts this regular expression to an Or if this regular expression is an Or.
      Star asStar()
      Casts this regular expression to a Star if this regular expression is a Star.
      RegularExpression comp​(RegularExpression other)
      Joins together two regular expression, that is, it builds a Comp recognizing this regular expression first, and than other.
      int compareTo​(RegularExpression o)  
      protected abstract int compareToAux​(RegularExpression other)
      Auxiliary compareTo(RegularExpression) that can safely assume that other is an object of the same class as this.
      abstract boolean contains​(java.lang.String s)
      Yields true if and only if this regular expression always contains the given string.
      abstract boolean endsWith​(java.lang.String s)
      Yields true if 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 boolean is​(java.lang.String str)
      Yields true if and only if this regular expression corresponds to the given string.
      boolean isAtom()
      Yields true if and only if this regular expression is an instance of Atom.
      boolean isComp()
      Yields true if and only if this regular expression is an instance of Comp.
      abstract boolean isEmpty()
      Yields true if and only if this regular expression corresponds to the empty string or to no strings at all.
      boolean isEmptySet()
      Yields true if and only if this regular expression is an instance of EmptySet.
      boolean isEpsilon()
      Yields true if and only if this symbol represents the empty string epsilon.
      boolean isOr()
      Yields true if and only if this regular expression is an instance of Or.
      boolean isStar()
      Yields true if and only if this regular expression is an instance of Star.
      abstract boolean mayContain​(java.lang.String s)
      Yields true if and only if this regular expression may contain the given string.
      abstract boolean mayEndWith​(java.lang.String s)
      Yields true if and only if this regular expression may end with the given string.
      abstract boolean mayStartWith​(java.lang.String s)
      Yields true if and only if this regular expression may start with the given string.
      RegularExpression or​(RegularExpression other)
      Builds the disjunction (Or) between this and the given regular expression.
      protected abstract boolean readsWhiteSpaceString()
      Checks whether this regular expression recognize a string made just of whitespaces.
      abstract RegularExpression repeat​(long n)
      Yields a new regular expression corresponding to the n-repetition of this.
      abstract RegularExpression simplify()
      Yields a simplified version of this regular expression.
      RegularExpression star()
      Builds the Kleene closure of this regular expression (Star), recognizing this zero or more times.
      abstract boolean startsWith​(java.lang.String s)
      Yields true if 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>>
      A
      toAutomaton​(AutomataFactory<A,​T> factory)
      Transforms this regular expression into its equivalent automaton.
      protected abstract RegularExpression topAsEmptyString()
      Yields a new regular expression where all TopAtom are assumed to have length zero.
      protected abstract RegularExpression topAsSingleChar()
      Yields a new regular expression where all TopAtom are assumed to have length one.
      abstract RegularExpression trimLeft()
      Yields a new regular expression where leading whitespaces have been removed from this.
      abstract RegularExpression trimRight()
      Yields a new regular expression where trailing whitespaces have been removed from this.
      protected abstract RegularExpression unrollStarToFixedLength​(int length)
      Yields a new regular expression where all Star have been unrolled to a sequence of their inner regular expression of length length.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RegularExpression

        public RegularExpression()
    • Method Detail

      • compareToAux

        protected abstract int compareToAux​(RegularExpression other)
        Auxiliary compareTo(RegularExpression) that can safely assume that other is an object of the same class as this.
        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
      • 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 of Automaton that this method yields
        T - the concrete type of TransitionSymbols that instances of A have 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 an Atom if this regular expression is an Atom. Returns null otherwise.
        Returns:
        this regular expression casted to Atom, or null
      • isAtom

        public final boolean isAtom()
        Yields true if and only if this regular expression is an instance of Atom.
        Returns:
        true if that condition holds
      • asComp

        public final Comp asComp()
        Casts this regular expression to a Comp if this regular expression is a Comp. Returns null otherwise.
        Returns:
        this regular expression casted to Comp, or null
      • isComp

        public final boolean isComp()
        Yields true if and only if this regular expression is an instance of Comp.
        Returns:
        true if that condition holds
      • asEmptySet

        public final EmptySet asEmptySet()
        Casts this regular expression to an EmptySet if this regular expression is an EmptySet. Returns null otherwise.
        Returns:
        this regular expression casted to EmptySet, or null
      • isEmptySet

        public final boolean isEmptySet()
        Yields true if and only if this regular expression is an instance of EmptySet.
        Returns:
        true if that condition holds
      • asOr

        public final Or asOr()
        Casts this regular expression to an Or if this regular expression is an Or. Returns null otherwise.
        Returns:
        this regular expression casted to Or, or null
      • isOr

        public final boolean isOr()
        Yields true if and only if this regular expression is an instance of Or.
        Returns:
        true if that condition holds
      • asStar

        public final Star asStar()
        Casts this regular expression to a Star if this regular expression is a Star. Returns null otherwise.
        Returns:
        this regular expression casted to Star, or null
      • isStar

        public final boolean isStar()
        Yields true if and only if this regular expression is an instance of Star.
        Returns:
        true if 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 index
        end - 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 substring
        missingChars - 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 the n-repetition of this.
        Parameters:
        n - number of repetitions
        Returns:
        a new regular expression corresponding to the n-repetition of this
      • trimLeft

        public abstract RegularExpression trimLeft()
        Yields a new regular expression where leading whitespaces have been removed from this.
        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 from this.
        Returns:
        a new regular expression where trailing whitespaces have been removed from this
      • isEmpty

        public abstract boolean isEmpty()
        Yields true if and only if this regular expression corresponds to the empty string or to no strings at all.
        Returns:
        true if that condition holds
      • is

        public abstract boolean is​(java.lang.String str)
        Yields true if and only if this regular expression corresponds to the given string.
        Parameters:
        str - the string
        Returns:
        true if that condition holds
      • mayContain

        public abstract boolean mayContain​(java.lang.String s)
        Yields true if and only if this regular expression may contain the given string.
        Parameters:
        s - the string
        Returns:
        true if that condition holds
      • contains

        public abstract boolean contains​(java.lang.String s)
        Yields true if and only if this regular expression always contains the given string.
        Parameters:
        s - the string
        Returns:
        true if that condition holds
      • mayStartWith

        public abstract boolean mayStartWith​(java.lang.String s)
        Yields true if and only if this regular expression may start with the given string.
        Parameters:
        s - the string
        Returns:
        true if that condition holds
      • startsWith

        public abstract boolean startsWith​(java.lang.String s)
        Yields true if and only if this regular expression always starts with the given string.
        Parameters:
        s - the string
        Returns:
        true if that condition holds
      • mayEndWith

        public abstract boolean mayEndWith​(java.lang.String s)
        Yields true if and only if this regular expression may end with the given string.
        Parameters:
        s - the string
        Returns:
        true if that condition holds
      • endsWith

        public abstract boolean endsWith​(java.lang.String s)
        Yields true if and only if this regular expression always ends with the given string.
        Parameters:
        s - the string
        Returns:
        true if that condition holds
      • unrollStarToFixedLength

        protected abstract RegularExpression unrollStarToFixedLength​(int length)
        Yields a new regular expression where all Star have been unrolled to a sequence of their inner regular expression of length length.
        Parameters:
        length - the length
        Returns:
        the regular expression with unrolled stars
      • topAsSingleChar

        protected abstract RegularExpression topAsSingleChar()
        Yields a new regular expression where all TopAtom are 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 all TopAtom are 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:
        true if this regular expression recognize a string made just of whitespaces, false otherwise.
      • star

        public final RegularExpression star()
        Builds the Kleene closure of this regular expression (Star), recognizing this zero 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 a Comp recognizing this regular expression first, and than other.
        Parameters:
        other - the other regular expression
        Returns:
        the joined regular expression
      • or

        public final RegularExpression or​(RegularExpression other)
        Builds the disjunction (Or) between this and the given regular expression.
        Parameters:
        other - the other regular expression
        Returns:
        the disjunction