void add()

in HSQL/src/org/hsqldb1/SetFunction.java [89:206]


    void add(Session session, Object item) throws HsqlException {

        if (item == null) {
            hasNull = true;

            return;
        }

        if (isDistinct && !distinctValues.add(item)) {
            return;
        }

        count++;

        switch (setType) {

            case Expression.COUNT :
                return;

            case Expression.AVG :
            case Expression.SUM : {
                switch (type) {

                    case Types.TINYINT :
                    case Types.SMALLINT :
                    case Types.INTEGER :
                        currentLong += ((Number) item).intValue();

                        return;

                    case Types.BIGINT :
                        addLong(((Number) item).longValue());

                        return;

                    case Types.REAL :
                    case Types.FLOAT :
                    case Types.DOUBLE :
                        currentDouble += ((Number) item).doubleValue();

                        return;

                    case Types.NUMERIC :
                    case Types.DECIMAL :
                        if (currentBigDecimal == null) {
                            currentBigDecimal = (BigDecimal) item;
                        } else {
                            currentBigDecimal =
                                currentBigDecimal.add((BigDecimal) item);
                        }

                        return;

                    default :
                        throw Trace.error(Trace.SUM_OF_NON_NUMERIC);
                }
            }
            case Expression.MIN : {
                if (currentValue == null) {
                    currentValue = item;

                    return;
                }

                if (Column.compare(
                        session.database.collation, currentValue, item,
                        type) > 0) {
                    currentValue = item;
                }

                return;
            }
            case Expression.MAX : {
                if (currentValue == null) {
                    currentValue = item;

                    return;
                }

                if (Column.compare(
                        session.database.collation, currentValue, item,
                        type) < 0) {
                    currentValue = item;
                }

                return;
            }
            case Expression.EVERY :
                if (!(item instanceof Boolean)) {
                    throw Trace.error(Trace.WRONG_DATA_TYPE);
                }

                every &= ((Boolean) item).booleanValue();

                return;

            case Expression.SOME :
                if (!(item instanceof Boolean)) {
                    throw Trace.error(Trace.WRONG_DATA_TYPE);
                }

                some |= ((Boolean) item).booleanValue();

                return;

            case Expression.STDDEV_POP :
            case Expression.STDDEV_SAMP :
            case Expression.VAR_POP :
            case Expression.VAR_SAMP :
                if (!(item instanceof Number)) {
                    throw Trace.error(Trace.WRONG_DATA_TYPE);
                }

                addDataPoint((Number) item);

                return;
        }
    }