Class NAutomaton<V>
- Type Parameters:
V- the label value type
- All Implemented Interfaces:
FormatClient,Traceable<Set<V>>,Serializable
Automaton states are labeled with sets of values. This is a generalization of accepting automata: Roughly, an accepting state corresponds to a state labeled with a non-empty set of values.
This class has no public constructor. Instances can be obtained from factory methods, and by conversion from other types of automata.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassIterator-like mutable API for tracking the consumption of an input sequence of code points by an automaton.protected classSpecialization in type parameters.Nested classes/interfaces inherited from class eu.bandm.tools.lexic.Automaton
Automaton.State -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionNAutomaton(Automaton.State initial, Map<Automaton.State, Behavior<Set<V>, Set<Automaton.State>>> table) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescription(package private) Multimap<Automaton.State, Automaton.State> Returns a multimap of all state transitions, regardless of the consumed code point.complement(V negValue) Returns an automaton that differs from this automaton by switching accepted and rejected inputs.static <V> NAutomaton<V> consume(int codePoint, NAutomaton<V> next) Returns an automaton that accepts only a given input code point and then behaves like a given automaton.static <V> NAutomaton<V> consume(String text, NAutomaton<V> next) Returns an automaton that accepts only a given sequence of input code point and then behaves like a given automaton.static <V> NAutomaton<V> consumeAnyOf(int[] codePoints, NAutomaton<V> next) Returns an automaton that accepts any one of some given input code points and then behaves like a given automaton.static <V> NAutomaton<V> consumeAnyOf(Collection<Integer> codePoints, NAutomaton<V> next) Returns an automaton that accepts any one of some given input code points and then behaves like a given automaton.static <V> NAutomaton<V> consumeAnyOfRange(int first, int last, NAutomaton<V> next) Returns an automaton that accepts any one of the given interval of input code points and then behaves like a given automaton.static <V> NAutomaton<V> consumeAnyOfRange(int first, int last, IntPredicate cond, NAutomaton<V> next) Returns an automaton that accepts some of the given interval of input code points and then behaves like a given automaton.static <V> NAutomaton<V> consumeExcept(int[] codePoints, NAutomaton<V> next) Returns an automaton that accepts any one except some given input code points and then behaves like a given automaton.copy()Returns an automaton that is equivalent to this automaton, but uses a set of fresh states.(package private) NAutomaton<V> copyPartial(Predicate<? super Automaton.State> mustCopy) Returns an automaton that is equivalent to this automaton, but uses fresh states as required.Returns a deterministic automaton that is equivalent to this automaton.<W> NAutomaton<W> disjoin(NAutomaton<W> aut) Returns an automaton that equivalent to the given one, and does not share states with this automaton.static <V> NAutomaton<V> empty()Returns an automaton that accepts no input.<W> NAutomaton<W> flatMap(Function<? super V, NAutomaton<W>> fun) Returns an automaton that differs from this automaton by having each label value expanded into a subautomaton.<F> Fformat(FormatServer<F> server) Represent this or the underlying object in a human-readable, pretty-printable way.<F> Fformat(FormatServer<F> server, Function<? super V, ? extends F> onValue) Returns a pretty-printable representation of this automaton.booleanisClosed()Checks whether the behavior of this automaton is closed.(package private) Multimap<Automaton.State, V> labeling()Returns a multimap of all states and their associated label values.loop()Returns an automaton that differs from this automaton by restarting from every accepting state.Returns an automaton that differs from this automaton by restarting every state with a selected value.<W> NAutomaton<W> Returns an automaton that differs from this automaton by having a function applied to all values.static <V> NAutomaton<V> of(V value) Returns an automaton that accepts an input of length zero with the given value.(package private) NAutomaton<V> orElse(NAutomaton<V> other) Returns an automaton that combines the successful transitions and value sets of this and another automaton.prune()Returns an equivalent automaton that has no unreachable states.reverse()Returns an automaton that differs from this automaton by accepting input sequences in reverse.toString()trace()Returns a fresh trace.Returns an automaton where all accepted input sequences of this automaton have been translated code-point-wise according to a relational image.static <V> NAutomaton<V> union(NAutomaton<V>... parts) Returns an automaton that combines the successful transitions and value sets of the given automata.static <V> NAutomaton<V> union(Collection<? extends NAutomaton<V>> parts) Returns an automaton that combines the successful transitions and value sets of the given automata.Methods inherited from class eu.bandm.tools.lexic.Automaton
countStates, countTransitions
-
Constructor Details
-
NAutomaton
NAutomaton(Automaton.State initial, Map<Automaton.State, Behavior<Set<V>, Set<Automaton.State>>> table) Creates a new instance.- Parameters:
initial- the initial state of the automatontable- the behavioral table of the automaton- See Also:
-
-
Method Details
-
of
Returns an automaton that accepts an input of length zero with the given value.- Type Parameters:
V- the label value type- Parameters:
value- the label value- Returns:
- an automaton that accepts an input of length zero with the given value (in a singleton set)
-
empty
Returns an automaton that accepts no input.- Type Parameters:
V- the label value type- Returns:
- an automaton that accepts no input
-
consume
Returns an automaton that accepts only a given input code point and then behaves like a given automaton.- Type Parameters:
V- the label value type- Parameters:
codePoint- the code point to consume firstnext- the automaton to emulate next- Returns:
- an automaton that accepts the given input code point and then behaves like the given automaton
-
consume
Returns an automaton that accepts only a given sequence of input code point and then behaves like a given automaton.- Type Parameters:
V- the label value type- Parameters:
text- the code point sequence to consume firstnext- the automaton to emulate next- Returns:
- an automaton that accepts the given input code points and then behaves like the given automaton
-
consumeAnyOf
Returns an automaton that accepts any one of some given input code points and then behaves like a given automaton.- Type Parameters:
V- the label value type- Parameters:
codePoints- the choice of code points to consume firstnext- the automaton to emulate next- Returns:
- an automaton that accepts any one of the given input code points and then behaves like the given automaton
-
consumeAnyOfRange
Returns an automaton that accepts any one of the given interval of input code points and then behaves like a given automaton.- Type Parameters:
V- the label value type- Parameters:
first- the lowest code point to acceptlast- the highest code point to acceptnext- the automaton to emulate next- Returns:
- an automaton that accepts any input code points greater or equal to
firstand less or equal tolast, and then behaves like the given automaton
-
consumeAnyOfRange
public static <V> NAutomaton<V> consumeAnyOfRange(int first, int last, IntPredicate cond, NAutomaton<V> next) Returns an automaton that accepts some of the given interval of input code points and then behaves like a given automaton.- Type Parameters:
V- the label value type- Parameters:
first- the lowest code point to acceptlast- the highest code point to acceptcond- an additional predicate that code points must satisfynext- the automaton to emulate next- Returns:
- an automaton that accepts any input code points greater or equal to
firstand less or equal tolast, and for whichcondreturnstrue, and then behaves like the given automaton
-
consumeAnyOf
Returns an automaton that accepts any one of some given input code points and then behaves like a given automaton.- Type Parameters:
V- the label value type- Parameters:
codePoints- the choice of code points to consume firstnext- the automaton to emulate next- Returns:
- an automaton that accepts any one of the given input code points and then behaves like the given automaton
-
consumeExcept
Returns an automaton that accepts any one except some given input code points and then behaves like a given automaton.- Type Parameters:
V- the label value type- Parameters:
codePoints- the choice of code points not to consume firstnext- the automaton to emulate next- Returns:
- an automaton that accepts any one except the given input code points and then behaves like the given automaton
-
map
Returns an automaton that differs from this automaton by having a function applied to all values.Since values are transformed one to one in the value sets associated with states, the accepting behavior of the automaton is unchanged.
- Type Parameters:
W- the target value type- Parameters:
fun- the function to apply to values- Returns:
- an automaton that differs from this automaton by having a function applied to all values
-
copy
Returns an automaton that is equivalent to this automaton, but uses a set of fresh states.- Returns:
- an automaton that is equivalent to this automaton, but uses a set of fresh states
-
copyPartial
Returns an automaton that is equivalent to this automaton, but uses fresh states as required.- Parameters:
mustCopy- a predicate that indicates whether to make a fresh copy of a state (true) or to retain the old one (false)- Returns:
- an automaton that is equivalent to this automaton, but uses fresh states as required
-
disjoin
Returns an automaton that equivalent to the given one, and does not share states with this automaton.- Type Parameters:
W- the target value type- Parameters:
aut- an automaton- Returns:
- an automaton that has the same observable behavior as
aut, and shares no state withthis
-
prune
Returns an equivalent automaton that has no unreachable states.- Returns:
- an automaton that has the same observable behavior as
thisand also the same reachable states, but no unreachable ones
-
orElse
Returns an automaton that combines the successful transitions and value sets of this and another automaton.- Parameters:
other- the other automaton- Returns:
- an automaton that combines the successful transitions and value sets of this and the other automaton
- See Also:
-
flatMap
Returns an automaton that differs from this automaton by having each label value expanded into a subautomaton.- Type Parameters:
W- the target value type- Parameters:
fun- the function for expanding values to subautomata- Returns:
- an automaton that differs from this automaton by having each label value expanded into a subautomaton by the given function
-
union
Returns an automaton that combines the successful transitions and value sets of the given automata.- Type Parameters:
V- the value type- Parameters:
parts- the automata to combine- Returns:
- an automaton that combines the successful transitions and value sets of the given automata
- See Also:
-
union
Returns an automaton that combines the successful transitions and value sets of the given automata.- Type Parameters:
V- the value type- Parameters:
parts- the automata to combine- Returns:
- an automaton that combines the successful transitions and value sets of the given automata
- See Also:
-
loop
Returns an automaton that differs from this automaton by restarting from every accepting state.The resulting automaton behaves as if nondeterministically jumping to the initial state whenever a non-empty label value set is reached.
- Returns:
- an automaton that differs from this automaton by restarting from every accepting state
-
loop
Returns an automaton that differs from this automaton by restarting every state with a selected value.The resulting automaton behaves as if nondeterministically jumping to the initial state whenever a label value set is reached that contains some value selected by the given predicate.
- Parameters:
pred- the predicate used to select values- Returns:
- an automaton that differs from this automaton by restarting from every state with a selected value
-
determinate
Returns a deterministic automaton that is equivalent to this automaton.In the worst case, the number of states can increase exponentially. However, this appears to be rare in practice.
- Returns:
- a deterministic automaton that is equivalent to this automaton
- See Also:
-
complement
Returns an automaton that differs from this automaton by switching accepted and rejected inputs.This transformation involves temporary conversion to a deterministic automaton. In the worst case, the number of states can increase exponentially. However, this appears to be rare in practice.
- Parameters:
negValue- the value to associated with each previously rejecting state- Returns:
- an automaton that rejects inputs accepted by this automaton, and vice versa
-
toString
-
format
Represent this or the underlying object in a human-readable, pretty-printable way.- Specified by:
formatin interfaceFormatClient- Type Parameters:
F- the type of format objects to produce- Parameters:
server- a factory object that can produce format objects- Returns:
- a format object produced by the server
-
format
Returns a pretty-printable representation of this automaton.- Type Parameters:
F- the type of format objects to produce- Parameters:
server- a factory object that can produce format objectsonValue- the operation to compute a representation of a value- Returns:
- a pretty-printable representation of this automaton
-
trace
Description copied from interface:TraceableReturns a fresh trace.Objects obtained as return values from multiple calls to this method do not share mutable state with each other, and can be used safely in concurrency.
-
isClosed
public boolean isClosed()Checks whether the behavior of this automaton is closed.This method is mostly useful for debugging; all automata obtained from public factory methods should satisfy this property by construction.
- Returns:
trueif all states referenced in behavior of reachable states also have entries in the table;falseotherwise}
-
reverse
Returns an automaton that differs from this automaton by accepting input sequences in reverse.- Returns:
- an automaton that accepts the reverse of inputs accepted by this automaton
-
adjacency
Multimap<Automaton.State,Automaton.State> adjacency()Returns a multimap of all state transitions, regardless of the consumed code point.The result does not contain information about state labels.
- Returns:
- a multimap that relates each pair of states that has a transition for some input code point
- See Also:
-
labeling
Multimap<Automaton.State,V> labeling()Returns a multimap of all states and their associated label values.The result does not contain information about transitions.
- Returns:
- a multimap that relates each state to the values contained in its associated label set
- See Also:
-
translate
Returns an automaton where all accepted input sequences of this automaton have been translated code-point-wise according to a relational image.The resulting automaton accepts a sequence of code points y1...yn with the label set of the final state containing a label l, if and only if there is a corresponding sequence of code points x1...xn accepted by this automaton with the same label l, such that
trans(xi, yi)returnstruefor all i.- Parameters:
trans- the translating relation- Returns:
- a behavior where all transition keys of this behavior have been
translated according to
trans - Throws:
NullPointerException- iftransis null- Since:
- 1.1
-