⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functionexpression.java

📁 用applet实现很多应用小程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.ceil(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
    public int getInt(Tuple t) {
        return (int)getDouble(t);
    }
}
//COS(X)
class CosFunction extends DoubleFunction {
    public CosFunction() { super(1); }
    public String getName() { return "COS"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.cos(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//COT(X)
class CotFunction extends DoubleFunction {
    public CotFunction() { super(1); }
    public String getName() { return "COT"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return 1/Math.tan(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//DEGREES(X)
class DegreesFunction extends DoubleFunction {
    public DegreesFunction() { super(1); }
    public String getName() { return "DEGREES"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.toDegrees(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//E()
class EFunction extends DoubleFunction {
    public EFunction() { super(0); }
    public String getName() { return "E"; }
    public double getDouble(Tuple t) {
        return Math.E;
    }
}
//EXP(X)
class ExpFunction extends DoubleFunction {
    public ExpFunction() { super(1); }
    public String getName() { return "EXP"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.exp(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//FLOOR(X)
class FloorFunction extends DoubleFunction {
    public FloorFunction() { super(1); }
    public String getName() { return "FLOOR"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.floor(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
    public int getInt(Tuple t) {
        return (int)getDouble(t);
    }
}
//LOG(X), LOG(B,X)
class LogFunction extends DoubleFunction {
    public LogFunction() { super(2); }
    public String getName() { return "LOG"; }
    public double getDouble(Tuple t) {
        int pc = paramCount();
        if ( pc == 2 ) {
            double b = param(0).getDouble(t);
            double x = param(1).getDouble(t);
            return Math.log(x)/Math.log(b);
        } else if ( pc == 1 ) {
            return Math.log(param(0).getDouble(t));
        } else {
            missingParams();
            return Double.NaN;
        }
    }
}
//LOG2(X)
class Log2Function extends DoubleFunction {
    public Log2Function() { super(1); }
    public String getName() { return "LOG2"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return MathLib.log2(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//LOG10(X)
class Log10Function extends DoubleFunction {
    public Log10Function() { super(1); }
    public String getName() { return "LOG10"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return MathLib.log10(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//SAFELOG10(X)
class SafeLog10Function extends DoubleFunction {
    public SafeLog10Function() { super(2); }
    public String getName() { return "SAFELOG10"; }
    public double getDouble(Tuple t) {
        int pc = paramCount();
        if ( pc == 1 ) {
            double x = param(0).getDouble(t);
            return MathLib.safeLog10(x);
        } else {
            missingParams();
            return Double.NaN;
        }
    }
}
//MAX(X1,X2,...)
class MaxFunction extends DoubleFunction {
    public MaxFunction() { super(Function.VARARGS); }
    public String getName() { return "MAX"; }
    public double getDouble(Tuple t) {
        double x, v = param(0).getDouble(t);
        for ( int i=1; i<paramCount(); ++i ) {
            x = param(i).getDouble(t);
            if ( x > v ) v = x;
        }
        return v;
    }
}
//MIN(X1,X2,...)
class MinFunction extends DoubleFunction {
    public MinFunction() { super(Function.VARARGS); }
    public String getName() { return "MIN"; }
    public double getDouble(Tuple t) {
        double x, v = param(0).getDouble(t);
        for ( int i=1; i<paramCount(); ++i ) {
            x = param(i).getDouble(t);
            if ( x < v ) v = x;
        }
        return v;
    }
}
//MOD(N,M)
class ModFunction extends DoubleFunction {
    public ModFunction() { super(2); }
    public String getName() { return "MOD"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 2 ) {
            double x = param(0).getDouble(t);
            double y = param(1).getDouble(t);
            return x % y;
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//PI()
class PiFunction extends DoubleFunction {
    public PiFunction() { super(0); }
    public String getName() { return "PI"; }
    public double getDouble(Tuple t) {
        return Math.PI;
    }
}
//POW(X,Y), POWER(X,Y)
class PowFunction extends DoubleFunction {
    public PowFunction() { super(1); }
    public String getName() { return "POW"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 2 ) {
            return Math.pow(param(0).getDouble(t), param(1).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//RADIANS(X)
class RadiansFunction extends DoubleFunction {
    public RadiansFunction() { super(1); }
    public String getName() { return "RADIANS"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.toRadians(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//RAND(), RAND(N)
class RandFunction extends DoubleFunction {
    public RandFunction() { super(0); }
    public String getName() { return "RAND"; }
    public double getDouble(Tuple t) {
        return Math.random();
    }
}
//ROUND(X) // --> ROUND(X,D) TODO
class RoundFunction extends DoubleFunction {
    public RoundFunction() { super(1); }
    public String getName() { return "ROUND"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.round(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
    public int getInt(Tuple t) {
        return (int)getDouble(t);
    }
}
//SIGN(X)
class SignFunction extends DoubleFunction {
    public SignFunction() { super(1); }
    public String getName() { return "SIGN"; }
    public Class getType(Schema s) {
        return int.class;
    }
    public double getDouble(Tuple t) {
        return getInt(t);
    }
    public int getInt(Tuple t) {
        if ( paramCount() == 1 ) {
            double d = param(0).getDouble(t);
            return d<0 ? -1 : d==0 ? 0 : 1;
        } else {
            missingParams(); return Integer.MIN_VALUE;
        }
    }
}
//SIN(X)
class SinFunction extends DoubleFunction {
    public SinFunction() { super(1); }
    public String getName() { return "SIN"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.sin(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//SQRT(X)
class SqrtFunction extends DoubleFunction {
    public SqrtFunction() { super(1); }
    public String getName() { return "SQRT"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.sqrt(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//SUM(X1,X2,...)
class SumFunction extends DoubleFunction {
    public SumFunction() { super(Function.VARARGS); }
    public String getName() { return "SUM"; }
    public double getDouble(Tuple t) {
        double v = param(0).getDouble(t);
        for ( int i=1; i<paramCount(); ++i )
            v += param(i).getDouble(t);
        return v;
    }
}
//SAFESQRT(X)
class SafeSqrtFunction extends DoubleFunction {
    public SafeSqrtFunction() { super(2); }
    public String getName() { return "SAFESQRT"; }
    public double getDouble(Tuple t) {
        int pc = paramCount();
        if ( pc == 1 ) {
            double x = param(0).getDouble(t);
            return MathLib.safeSqrt(x);
        } else {
            missingParams();
            return Double.NaN;
        }
    }
}
//TAN(X)
class TanFunction extends DoubleFunction {
    public TanFunction() { super(1); }
    public String getName() { return "TAN"; }
    public double getDouble(Tuple t) {
        if ( paramCount() == 1 ) {
            return Math.tan(param(0).getDouble(t));
        } else {
            missingParams(); return Double.NaN;
        }
    }
}
//TRUNCATE(X,D)
// TODO

//----------------------------------------------------------------------------
// String Functions

abstract class StringFunction extends FunctionExpression {
    protected StringFunction(int parameterCount) {
        super(parameterCount);
    }
    public Class getType(Schema s) {
        return String.class;
    }
    protected StringBuffer getBuffer() {
        return new StringBuffer();
    }
}
//CAP(str1)
class CapFunction extends StringFunction {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -