📄 sp_rununit.java
字号:
import java.util.*;
import java.text.*;
/**
* 变量实体描述
* 属于语法分析包
* @author 林玉东.烟台
* @version 1.0 11/01 2003
*/
public class SP_RunUnit implements SP_Const
{
//
public double value1; //保存(所有)数字量
public String value2; //保存字符串 null
public int type; //类型 :整数/浮点/字符串
public SP_RunUnit()
{
value1=0;
value2=null;
type=WT_NULL;
}
//赋值
public void set(String value,int type)
{
this.type=type;
value2=value;
try{
value1=Double.parseDouble(value); //无论字符串/数字
}
catch(Exception e){
value1=0.0;
}
}
//取值
public String getValue()
{
String rs="";
if(type==WT_IntegerConst)
rs= String.valueOf((int)value1);
else if(type==WT_FloatConst)
rs= numf.format(value1);
else if(type==WT_StringConst)
rs= value2;
return rs;
}
/*********/
//
public void plus(SP_RunUnit another)
{
//处理字符串的+操作
if(type==WT_StringConst || another.type==WT_StringConst ){ //字符串只有+操作
value2=getValue()+another.getValue();
type=WT_StringConst;
}
//处理数字型的+操作
else{
//System.out.println("plus======="+value1+":"+another.value1);
value1=value1+another.value1;
type=Math.max(type,another.type); //类型向上造型
}
}
//
public void minus(SP_RunUnit another)
{
value1=value1-another.value1;
type=Math.max(type,another.type);
}
//
public void times(SP_RunUnit another)
{
value1=value1*another.value1;
type=Math.max(type,another.type);
}
//
public void divide(SP_RunUnit another)
{
value1=value1/another.value1;
type=Math.max(type,another.type);
}
//
public void mod(SP_RunUnit another)
{
value1=((int)value1)%((int)another.value1);
type=WT_IntegerConst;
}
//
public void band(SP_RunUnit another)
{
value1=((int)value1)&((int)another.value1);
type=WT_IntegerConst;
}
//
public void bor(SP_RunUnit another)
{
value1=((int)value1)|((int)another.value1);
type=WT_IntegerConst;
}
//
public void and(SP_RunUnit another)
{
value1=(((int)value1)==1 && ((int)another.value1)==1) ? 1:0;
type=WT_IntegerConst;
}
//
public void or(SP_RunUnit another)
{
value1=(((int)value1)==1 || ((int)another.value1)==1) ? 1:0;
type=WT_IntegerConst;
}
//
public void eql(SP_RunUnit another)
{
value1=(value1==another.value1)?1:0;
type=WT_IntegerConst;
}
//
public void neq(SP_RunUnit another)
{
value1=(value1!=another.value1)?1:0;
type=WT_IntegerConst;
}
//
public void grt(SP_RunUnit another)
{
value1=(value1>another.value1)?1:0;
type=WT_IntegerConst;
}
//
public void geq(SP_RunUnit another)
{
value1=(value1>=another.value1)?1:0;
type=WT_IntegerConst;
}
//
public void lss(SP_RunUnit another)
{
value1=(value1<another.value1)?1:0;
type=WT_IntegerConst;
}
//
public void leq(SP_RunUnit another)
{
value1=(value1<=another.value1)?1:0;
type=WT_IntegerConst;
}
public void set(SP_RunUnit another)
{
value1=another.value1;
value2=another.value2;
type=another.type;
}
/*********/
//
static NumberFormat numf=NumberFormat.getNumberInstance();
static {
numf.setMaximumFractionDigits(3);
numf.setMinimumFractionDigits(3);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -