Package reportgen.math.agregate.agregate

Examples of reportgen.math.agregate.agregate.AggregateFunction


    private void initGroup(List<AggregateFunction> cols, boolean clearAsis) throws ReportException {
        //init normalizer
        normalizeScaler = new HashMap<Integer, Integer>();
        //init columns
        for(int i=0; i<cols.size(); i ++) {
            AggregateFunction col = cols.get(i);

            if(col.equals(AggregateFunction.COUNT)) {
                if(values[i] != null) {
                    values[i] = new Long(1);
                } else {
                    values[i] = new Long(0);
                }

            } else if(col.equals(AggregateFunction.COUNT_DISTINCT)) {
                if(distinct == null) {
                    distinct = new HashMap<Integer, Set>();
                }
                Set set = new HashSet();
                if(values[i] != null) {
                    set.add(values[i]);
                    values[i] = new Long(1);
                } else {
                    values[i] = new Long(0);
                }
                distinct.put(i, set);

            } else if(col.equals(AggregateFunction.AVG)) {
                Object value = values[i]; //always be Long or Double
               
                if(value instanceof Long) {
                    values[i] = new Double(((Long)value).doubleValue());
               
                } else if (value instanceof Double) {
                    //fit, do nothing
               
                } else {
                    throw new ReportException("Невозможно инициализировать группу при рассчете среднего значения для класса "
                            + value.getClass().getSimpleName());
                }
                normalizeScaler.put(i, 1);

            } else if(clearAsis
                    && col.equals(AggregateFunction.ASIS)) {
                values[i] = new String("-");
            }
        }
    }
View Full Code Here


                    || !canGroupWith(newRow, groupIndicies))) {
            return false;
        }

        for(int i=0; i< cols.size(); i++) {
            AggregateFunction col = cols.get(i);
            Object value = newRow.values[i];
            //null values not take apart in group merging
            if(value == null) {
                continue;
            }

            if(col.equals(AggregateFunction.SUM)) {
                values[i] = sum(values[i], value);

            } else if(col.equals(AggregateFunction.AVG)) {
                Double dval = null;
                if(value instanceof Long) {
                    dval = new Double(((Long) value).doubleValue());
                } else if(value instanceof Double) {
                    dval = (Double) value;
                } else {
                    throw new ReportException("Невозможно рассчитать среднее значение для класса "
                            + value.getClass().getSimpleName());
                }
                values[i] = (Double) sum(values[i], dval);

                //update scaler
                Integer scaler = normalizeScaler.get(i);
                normalizeScaler.put(i, scaler+1);

            } else if(col.equals(AggregateFunction.COUNT)) {
                values[i] = (Long) values[i] + 1;

            } else if(col.equals(AggregateFunction.COUNT_DISTINCT)) {
                Set set = distinct.get(i);
                if(!set.contains(value)) {
                    set.add(value);
                    values[i] = (Long) values[i] + 1;
                }

            } else if(col.equals(AggregateFunction.MAX)) {
                if(compare(values[i], value) < 0) {
                    values[i] = value;
                }

            } else if(col.equals(AggregateFunction.MIN)) {
                if(compare(values[i], value) > 0) {
                    values[i] = value;
                }
            }
        }     
View Full Code Here

     * @param value
     * @return
     * @throws ReportException
     */
    public static AggregateFunction fromName(String value) throws ReportException {
        AggregateFunction func = mnemonics.get(value);
        if (func == null) {
            throw new ReportException("Неизвестный тип агрегатной функции: " + value);
        }
        return func;
    }
View Full Code Here

        //header
        if (showHeader) {
            String head = "<tr>";
            for (int columnIndex : visible) {
                String colTitle = data.getColumnTitle(columnIndex);
                AggregateFunction mode = data.getModes().get(columnIndex);
                if (includeFunc && !mode.equals(AggregateFunction.ASIS)) {
                    colTitle = mode.toString() + "(" + colTitle + ")";
                }
                head += "<th>" + colTitle + "</th>";
            }
            stream.print(head + "</tr>");
        }
View Full Code Here

            aValue = new MathExpressionGeneric(child, context);
        } else {
            aValue = new MathExpressionGeneric(context);
        }

        AggregateFunction aFunction = null;
        String mnemonic = getStringAttribute(element, ATTR_FUNC, null, false);
        if(mnemonic == null) {
            aFunction = AggregateFunction.ASIS;
        } else {
            aFunction = context.getAggregFunction(mnemonic, aValue.getCls());
View Full Code Here

            if(expression == null) {
                mainCombo.setSelectedItem(null);
                subCombo.setEnabled(false);
            } else {
                mainCombo.setSelectedItem(expression.getRef());
                AggregateFunction function = expression.getFunction();
                Class cls = null;
                try {
                    cls = expression.getCls();
                } catch (ReportException ex) {
                    Message.warning(this, ex);
                    function = AggregateFunction.ASIS;
                }
                fillFunctions(cls, function);
            }
        }

        mainCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ReportResultColumn selection = (ReportResultColumn) mainCombo.getSelectedItem();
                AggregateFunction function = (AggregateFunction) subCombo.getSelectedItem();
                if(selection != null) {
                    MathExpressionReportResultAgreg sample = new MathExpressionReportResultAgreg(
                            selection, AggregateFunction.ASIS, context);
                    Class cls = null;
                    try {
                        cls = sample.getCls();
                    } catch (ReportException ex) {
                        Message.warning(MathExpressionReportResultAgregPanel.this, ex);
                        function = null;
                    }
                    fillFunctions(cls, function);
                }
                subCombo.setEnabled(selection != null);
            }
        });

        subCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ReportResultColumn selection = (ReportResultColumn) mainCombo.getSelectedItem();
                AggregateFunction function = (AggregateFunction) subCombo.getSelectedItem();
                if(selection != null
                        && function != null) {
                    if(me == null) {
                        me = new MathExpressionReportResultAgreg(selection, function, context);
                    } else {
View Full Code Here

TOP

Related Classes of reportgen.math.agregate.agregate.AggregateFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.