File: DTInteger.java

package info (click to toggle)
antlr 2.7.7%2Bdfsg-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,016 kB
  • sloc: java: 54,649; cs: 12,537; makefile: 8,854; cpp: 7,359; pascal: 5,273; sh: 4,333; python: 4,297; lisp: 1,969; xml: 220; lex: 192; ansic: 127
file content (105 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package tinybasic;

public class DTInteger extends DTDataType {

    protected int i;
	
    public DTInteger(Scope scope,DTDataType tbd){
		super(scope,INT_VAR);
		setInteger(tbd);
	}
    public DTInteger(Scope scope,int i){
		super(scope,INT_VAR);
		this.i=i;
	}
    
    public int getInteger(){
	    return i;
    }
    
    public DTInteger(Scope scope,String s){
		super(scope,INT_VAR);
		this.i=Integer.parseInt(s);
	}
    

    public void setInteger(DTDataType tbd){
	setInteger(tbd.getInteger());
    }
    
    public void setFloat(DTDataType tbd){
	setFloat(tbd.getFloat());
    }
    
    public void setInteger(int i){
	this.i=i;
    }

    public double getFloat(){
	    return i;
    }
    public void setFloat(double d){
	i=(int)d;
    }
    
    public void assign(DTDataType tbd){
	setInteger(tbd);
    }
//
    public DTDataType multiply(DTDataType other){
	    if(other instanceof DTFloat){
		DTFloat t=new DTFloat(null,this);
		return t.multiply(other);
	    }
	    return new DTInteger(null,getInteger()*other.getInteger());
	}
    public DTDataType divide(DTDataType other){
	    if(other instanceof DTFloat){
		DTFloat t=new DTFloat(null,this);
		return t.divide(other);
	    }
	    return new DTInteger(null,getInteger()/other.getInteger());
	}
    public DTDataType add(DTDataType other){ 
	    if(other instanceof DTFloat){
		DTFloat t=new DTFloat(null,this);
		return t.add(other);
	    }
	    return new DTInteger(null,getInteger()+other.getInteger());
	}
    public DTDataType subtract(DTDataType other){
	    if(other instanceof DTFloat){
		DTFloat t=new DTFloat(null,this);
		return t.subtract(other);
	    }
	    return new DTInteger(null,getInteger()-other.getInteger());
	}
    public DTDataType mod(DTDataType other){
	    if(other instanceof DTFloat){
		DTFloat t=new DTFloat(null,this);
		return t.mod(other);
	    }
	    return new DTInteger(null,getInteger() % other.getInteger());
	}
    public DTDataType round(){
	    return this;
	}
    public DTDataType truncate(){
	    return this;
	}

    public int compareTo(Object o){
	int d=0;
	if(getInteger() < ((DTDataType)o).getInteger()){
	    return -1;
	} else if ( getInteger() > ((DTDataType)o).getInteger()){
	    return 1;
	}
	return 0;
    }
    public String toString(){
	return new Integer(getInteger()).toString();
    }
    

}