All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cool.scx.data.query.parser.OrderByParser Maven / Gradle / Ivy

There is a newer version: 2.7.4
Show newest version
package cool.scx.data.query.parser;

import cool.scx.data.query.OrderBy;
import cool.scx.data.query.OrderByBody;
import cool.scx.data.query.OrderByBodySet;

import java.util.ArrayList;

import static java.util.Collections.addAll;

public abstract class OrderByParser {

    public final String[] parseOrderBy(OrderBy orderBy) {
        return parseAll(orderBy.clauses());
    }

    public final String[] parseAll(Object[] objs) {
        var list = new ArrayList();
        for (var obj : objs) {
            var s = parse(obj);
            addAll(list, s);
        }
        return list.toArray(String[]::new);
    }

    public String[] parse(Object obj) {
        if (obj instanceof OrderByBody o) {
            return new String[]{parseOrderByBody(o)};
        } else if (obj instanceof String s) {
            return new String[]{s};
        } else if (obj instanceof OrderByBodySet s) {
            return parseAll(s.clauses());
        } else if (obj instanceof OrderBy s) {
            return parseAll(s.clauses());
        } else {
            return null;
        }
    }

    protected abstract String parseOrderByBody(OrderByBody body);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy