-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.java
65 lines (54 loc) · 1.88 KB
/
block.java
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
public class block {
private int lenandwid;
private int rowandcol;
private short widlen;
private short collen;
private int ID; // ID is the identification number of block which help to distinguish two different block even though it have same shape.
public block(int length, int width, int row, int col){
Integer myint = new Integer(col);
collen = (short)myint.toString().length();
rowandcol =col +((int)Math.pow(10, collen)) * row;
myint = new Integer(width);
widlen = (short)myint.toString().length();
lenandwid =width +((int)Math.pow(10, widlen)) * length;
}
public block(int length, int width, int row, int col, int IDnum){
Integer myint = new Integer(col);
collen = (short)myint.toString().length();
rowandcol =col +((int)Math.pow(10, collen)) * row;
myint = new Integer(width);
widlen = (short)myint.toString().length();
lenandwid =width +((int)Math.pow(10, widlen)) * length;
ID = IDnum;
}
public int compare(block o1, block o2){
if (o1.getrow() < o2.getrow() || ((o1.getrow() == o2.getrow() && o1.getcol() < o2.getcol())))
return -1;
else if (o1.getrow() == o2.getrow() && o1.getcol() == o2.getcol())
return 0;
else
return 1;
}
public boolean equals(Object o){
if (this.getcol() == ((block) o).getcol() && this.getrow() == ((block) o).getrow() && this.getlength() == ((block) o).getlength() &&
this.getID() == ((block) o).getID() && this.getwidth() == ((block) o).getwidth())
return true;
else
return false;
}
public int getID(){
return ID;
}
public int getlength(){
return lenandwid/(int)(Math.pow(10, widlen));
}
public int getwidth(){
return lenandwid%(int)(Math.pow(10, widlen));
}
public int getrow(){
return rowandcol/(int)(Math.pow(10, collen));
}
public int getcol(){
return rowandcol%(int)(Math.pow(10, collen));
}
}