-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVariable.java
More file actions
122 lines (102 loc) · 2.42 KB
/
Variable.java
File metadata and controls
122 lines (102 loc) · 2.42 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
public class Variable implements FormulaBlock{
private double[][] value;
private String name;
public Variable(String name, double value){
this.value = new double[1][1];
this.value[0][0] = value;
this.name = name;
}
public Variable(String name, double[][] value){
this.value = value;
this.name = name;
}
public Variable copy(){
Variable copy = new Variable(this.name,0);
copy.value = new double[this.value.length][this.value[0].length];
for(int i=0; i<this.value.length; i++){
for(int j=0; j<this.value[0].length; j++){
copy.value[i][j] = this.value[i][j];
}
}
return copy;
}
public int getHeight(){
return this.value.length;
}
public int getWidth(){
return this.value[0].length;
}
public double[][] getMatrixValue(){
return this.value;
}
public double getValue(){
return this.value[0][0];
}
public double getValue(int i1, int i2){
if(i1 >= 0 && i1 < this.value.length){
if(i2 >= 0 && i2 < this.value[i1].length){
return this.value[i1][i2];
}
}
return 0.0;
}
public int getIntValue(){
return (int)(this.value[0][0]+0.0000001);
}
public void setValue(double newv){
this.value[0][0] = newv;
}
public void setValue(int newv){
this.value[0][0] = (double)newv;
}
public String getName(){
return this.name;
}
public String toString(){
//return this.name;
//return Double.toString(this.value);
String info = "";
if(this.value.length > 1 || this.value[0].length > 1){
info += "[ ";
}
for(int i=0; i<this.value.length; i++){
if(this.value.length > 1){
info += "[ ";
}
for(int j=0; j<this.value[i].length; j++){
info += FileHandler.formattedDouble(this.value[i][j],12,6);
if(j < this.value[i].length-1){
info += ",";
}
info += " ";
}
if(this.value.length > 1){
info += "] ";
}
}
if(this.value.length > 1 || this.value[0].length > 1){
info += "]";
}
return info;
}
public String getMatrixString(){
//return this.name;
//return Double.toString(this.value);
String info = "";
for(int i=0; i<this.value.length; i++){
for(int j=0; j<this.value[i].length; j++){
info += FileHandler.formattedDouble(this.value[i][j],12,8)+" ";
}
if(this.value.length > 1){
info += "\n";
}
}
return info;
}
public boolean isOperator(){
return false;
}
public boolean isCustomFunction(){
return false;
}
}