class TermsHandler {

    public static Set<TermGroup> groupTerms(List<Term> terms) {<FILL_FUNCTION_BODY>}

    @Getter
    @Setter
    public static class TermGroup {
        public TermGroup(Term.Type type) {
            this.type = type;
            this.terms = new ArrayList<>();
        }

        List<Term> terms;

        Term.Type type;
        public void addTerm(Term term) {
            terms.add(term);
        }
    }

}

        Set<TermGroup> groups = new HashSet<>();
        TermGroup currentGroup = null;

        for (int i = 0; i < terms.size(); i++) {
            Term currentTerm = terms.get(i);
            Term nextTerm = (i + 1 < terms.size()) ? terms.get(i + 1) : null;

            if (currentTerm.getType() == Term.Type.or){
                if (currentGroup == null || currentGroup.type == Term.Type.and){
                    currentGroup = new TermGroup(Term.Type.or);
                }
                // 如果下一个Term为"AND"，创建一个新分组
                if (nextTerm != null && nextTerm.getType() == Term.Type.and){
                    currentGroup = new TermGroup(Term.Type.and);
                }
            }else {
                if (currentGroup == null){
                    currentGroup = new TermGroup(Term.Type.and);
                }
            }
            currentGroup.addTerm(currentTerm);
            groups.add(currentGroup);
        }
        return groups;
    
<no_super_class>