Search in sources :

Example 1 with Index

use of io.github.ihongs.dh.search.StatisGather.Index in project HongsCORE by ihongs.

the class StatisHelper method getGatherFields.

private Fields getGatherFields(Set<String> names, Map rd) {
    if (names == null) {
        return null;
    }
    List<Diman> dimans = new ArrayList();
    List<Index> indics = new ArrayList();
    Map<String, Map> items = that.getFields();
    Map<String, String> types;
    try {
        types = FormSet.getInstance().getEnum("__types__");
    } catch (HongsException e) {
        throw e.toExemption();
    }
    for (String n : names) {
        TYPE g;
        String f = n;
        String m = null;
        // 拆出统计方法
        int j = n.indexOf('!');
        if (j > -1) {
            m = n.substring(1 + j);
            f = n.substring(0, j);
            // 统计行数
            if (m.equals("count") && f.equals("*")) {
                f = Cnst.ID_KEY;
            }
        }
        Map c = items.get(f);
        if (c == null) {
            continue;
        }
        String t = (String) c.get("__type__");
        Object k = (Object) c.get("type");
        // 使用基准类型
        if (types.containsKey(t)) {
            t = types.get(t);
        }
        if (Synt.declare(c.get("__repeated__"), false) == false) {
            f = "#" + f;
            if (null != t)
                switch(t) {
                    case "number":
                        if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
                            g = TYPE.INT;
                        } else if ("long".equals(k)) {
                            g = TYPE.LONG;
                        } else if ("float".equals(k)) {
                            g = TYPE.FLOAT;
                        } else {
                            g = TYPE.DOUBLE;
                        }
                        break;
                    case "hidden":
                    case "enum":
                        if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
                            g = TYPE.INT;
                        } else if ("long".equals(k)) {
                            g = TYPE.LONG;
                        } else if ("float".equals(k)) {
                            g = TYPE.FLOAT;
                        } else if ("double".equals(k) || "number".equals(k)) {
                            g = TYPE.DOUBLE;
                        } else {
                            g = TYPE.STRING;
                        }
                        break;
                    case "date":
                        g = TYPE.LONG;
                        break;
                    default:
                        g = TYPE.STRING;
                }
            else {
                g = TYPE.STRING;
            }
        } else {
            f = "%" + f;
            if (null != t)
                switch(t) {
                    case "number":
                        if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
                            g = TYPE.INTS;
                        } else if ("long".equals(k)) {
                            g = TYPE.LONGS;
                        } else if ("float".equals(k)) {
                            g = TYPE.FLOATS;
                        } else {
                            g = TYPE.DOUBLES;
                        }
                        break;
                    case "hidden":
                    case "enum":
                        if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
                            g = TYPE.INTS;
                        } else if ("long".equals(k)) {
                            g = TYPE.LONGS;
                        } else if ("float".equals(k)) {
                            g = TYPE.FLOATS;
                        } else if ("double".equals(k) || "number".equals(k)) {
                            g = TYPE.DOUBLES;
                        } else {
                            g = TYPE.STRINGS;
                        }
                        break;
                    case "date":
                        g = TYPE.LONGS;
                        break;
                    default:
                        g = TYPE.STRINGS;
                }
            else {
                g = TYPE.STRINGS;
            }
        }
        Object o = getGatherField(g, f, n, m, rd);
        if (o instanceof Index) {
            indics.add((Index) o);
        } else {
            dimans.add((Diman) o);
        }
    }
    return new Fields(dimans.toArray(new Diman[dimans.size()]), indics.toArray(new Index[indics.size()]));
}
Also used : ArrayList(java.util.ArrayList) Index(io.github.ihongs.dh.search.StatisGather.Index) HongsException(io.github.ihongs.HongsException) Diman(io.github.ihongs.dh.search.StatisGather.Diman) HashMap(java.util.HashMap) Map(java.util.Map) TYPE(io.github.ihongs.dh.search.StatisHandle.TYPE)

Aggregations

HongsException (io.github.ihongs.HongsException)1 Diman (io.github.ihongs.dh.search.StatisGather.Diman)1 Index (io.github.ihongs.dh.search.StatisGather.Index)1 TYPE (io.github.ihongs.dh.search.StatisHandle.TYPE)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1