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

org.nutz.el.opt.arithmetic.PlusOpt Maven / Gradle / Ivy

Go to download

Nutz, which is a collections of lightweight frameworks, each of them can be used independently

There is a newer version: 1.r.72
Show newest version
package org.nutz.el.opt.arithmetic;

import org.nutz.el.opt.TwoTernary;

/**
 * "+"
 * @author juqkai([email protected])
 *
 */
public class PlusOpt extends TwoTernary {
    public int fetchPriority() {
        return 4;
    }

    public String fetchSelf() {
        return "+";
    }
    public Object calculate() {
        Object lval = calculateItem(this.left);
        Object rval = calculateItem(this.right);
        
        if(lval instanceof String || rval instanceof String){
            return lval.toString() + rval.toString();
        }
        
        Number nlval = (Number) lval;
        Number nrval = (Number) rval;
        
        if(nrval instanceof Double || nlval instanceof Double){
            return nlval.doubleValue() + nrval.doubleValue();
        }
        if(nrval instanceof Float || nlval instanceof Float){
            return nlval.floatValue() + nrval.floatValue();
        }
        if(nrval instanceof Long || nlval instanceof Long){
            return nlval.longValue() + nrval.longValue();
        }
        return nlval.intValue() + nrval.intValue();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy