/** * Returns a new (deterministic and minimal) automaton that accepts the union of the given set of * strings. The input character sequences are internally sorted in-place, so the input array is * modified. * * @see StringUnionOperations */ public static DefaultAutomaton makeStringUnion(CharSequence... strings) { if (strings.length == 0) return makeEmpty(); Arrays.sort(strings, StringUnionOperations.LEXICOGRAPHIC_ORDER); DefaultAutomaton a = new DefaultAutomaton(); a.setInitialState(StringUnionOperations.build(strings)); a.setDeterministic(true); a.reduce(); a.recomputeHashCode(); return a; }
/** Returns a new (deterministic) automaton that accepts a single character in the given set. */ public static DefaultAutomaton makeCharSet(String set) { if (set.length() == 1) return makeChar(set.charAt(0)); DefaultAutomaton a = new DefaultAutomaton(); State s1 = new State(); State s2 = new State(); a.initial = s1; s2.accept = true; for (int i = 0; i < set.length(); i++) s1.transitions.add(new Transition(set.charAt(i), s2)); a.deterministic = true; a.reduce(); return a; }