Language.java

package ch.hslu.exercises.sw12.ex7;

public final class Language {

    public static boolean isWordLanguage(final String string) {
        char[] chars = string.toCharArray();

        State state = State.Z0;
        for (char c : chars) {
            state = state.next(c);
            if (state == null) {
                return false;
            }
        }
        return state == State.Z4 | state == State.Z1;
    }

    public static boolean isWordLanguageRegex(final String string) {
        return string.matches("^0(1(11)*0)*");
    }

}