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

org.dflib.exp.ExpScalar1 Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package org.dflib.exp;

import org.dflib.DataFrame;
import org.dflib.Exp;
import org.dflib.Series;

import java.util.Objects;

/**
 * A unary expression with a scalar argument.
 *
 * @since 0.11
 */
public abstract class ExpScalar1 implements Exp {

    private final Class type;
    protected final T value;

    public ExpScalar1(T value, Class type) {
        this.value = value;
        this.type = Objects.requireNonNull(type);
    }

    @Override
    public String toString() {
        return toQL();
    }

    @Override
    public Class getType() {
        return type;
    }

    @Override
    public String toQL() {
        boolean quotes = value != null && !(value instanceof Number);
        String unquoted = String.valueOf(value);
        return quotes ? "'" + unquoted + "'" : unquoted;
    }

    @Override
    public String toQL(DataFrame df) {
        return toQL();
    }

    @Override
    public Series eval(DataFrame df) {
        return doEval(df.height());
    }

    @Override
    public Series eval(Series s) {
        return doEval(s.size());
    }

    protected abstract Series doEval(int height);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy