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

org.nutz.el.opt.AbstractOpt 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;

import org.nutz.el.ElException;
import org.nutz.el.Operator;
import org.nutz.el.obj.Elobj;

/**
 * 操作符抽象类
 * @author juqkai([email protected])
 *
 */
public abstract class AbstractOpt implements Operator{
    /**
     * 操作符对象自身的符号
     */
    public abstract String fetchSelf();
    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if(obj.equals(fetchSelf())){
            return true;
        }
        return super.equals(obj);
    }
    public String toString() {
        return String.valueOf(fetchSelf());
    }
    
    /**
     * 计算子项
     */
    protected Object calculateItem(Object obj){
        if(obj == null){
            return null;
        }
        if(obj instanceof Number){
            return obj;
        }
        if(obj instanceof Boolean){
            return obj;
        }
        if(obj instanceof String){
            return obj;
        }
        if(obj instanceof Elobj){
            return ((Elobj) obj).fetchVal();
        }
        if(obj instanceof Operator){
            return ((Operator) obj).calculate();
        }
        throw new ElException("未知计算类型!" + obj);
        
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy