<commit_before>package ca.six.demo.statemac;

// 要求检查一串string是不是 "a[b]*" 的形式. 即正则表达式的检查
public class StateModelABStateMachine implements IABStateMachine {
    State state = State.Init;
    StringBuilder sb = new StringBuilder();

    @Override
    public void process(SmStringReader reader) {
        state.process(this, reader);
    }

    enum State {
        Init {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                char ch = reader.read();
                if (ch == 'a') {
                    machine.state = AfterA;
                    machine.sb.append(ch);
                } else {
                    throw new RuntimeException("The string does not start with 'a' ");
                }
            }
        },

        Accept {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                System.out.println("find " + machine.sb.toString());
                machine.sb = new StringBuilder();
                machine.state = Init;
                reader.unread();
            }
        },

        AfterA {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                char ch = reader.read();
                if (ch == 'b') {
                    machine.sb.append(ch);
                    machine.state = AfterB;
                } else {
                    machine.state = Accept;
                }
            }
        },

        AfterB {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                char ch = reader.read();
                if (ch == 'b') {
                    machine.sb.append(ch);
                    machine.state = AfterB;
                } else {
                    machine.state = Accept;
                }
            }
        };

        public void process(StateModelABStateMachine machine, SmStringReader reader) {
        }
    }<commit_msg>state machine<commit_after>package ca.six.demo.statemac;

// 要求检查一串string是不是 "a[b]*" 的形式. 即正则表达式的检查
public class StateModelABStateMachine implements IABStateMachine {
    State state = State.Init;
    StringBuilder sb = new StringBuilder();

    @Override
    public void process(SmStringReader reader) {
        state.process(this, reader);
    }

    enum State {
        Init {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                char ch = reader.read();
                if (ch == 'a') {
                    machine.state = AfterA;
                    machine.sb.append(ch);
                } else {
                    throw new RuntimeException("The string does not start with 'a' ");
                }
            }
        },

        Accept {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                System.out.println("find " + machine.sb.toString());
                machine.sb = new StringBuilder();
                machine.state = Init;
                reader.unread();
            }
        },

        AfterA {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                char ch = reader.read();
                if (ch == 'b') {
                    machine.sb.append(ch);
                    machine.state = AfterB;
                } else {
                    machine.state = Accept;
                }
            }
        },

        AfterB {
            @Override
            public void process(StateModelABStateMachine machine, SmStringReader reader) {
                char ch = reader.read();
                if (ch == 'b') {
                    machine.sb.append(ch);
                    machine.state = AfterB;
                } else {
                    machine.state = Accept;
                }
            }
        };

        // 各个子State都要继承这个方法
        public void process(StateModelABStateMachine machine, SmStringReader reader) { }

    }
{'fraction_non_alphanumeric': 0.08808664259927798, 'fraction_numerical': 0.0, 'mean_word_length': 1.2974018794914317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7662000', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1012, 'n_words': 234}