-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
69 lines (62 loc) · 1.66 KB
/
Block.java
File metadata and controls
69 lines (62 loc) · 1.66 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
package end_sem3;
import java.util.Arrays;
import java.util.Date;
public class Block {
private int prevBlockHash = 0;
private Date Timestamp;
private int hash;
private int previousHash;
private String table_name;
public Block() { // Constructor for Block
}
public Block(Date timestamp, String data) { // Parameterized Constructor for Block1
this.Timestamp = timestamp;
this.table_name = data;
this.hash = computeHash();
}
public int computeHash() { // Computes the Hash using the values of the Time Stamp, previous hash and data.
String dataToHash = "" + this.Timestamp + this.previousHash + this.table_name;
int encoded = 0;
encoded = Arrays.hashCode(new int[] { dataToHash.hashCode(), this.prevBlockHash });
this.hash = encoded;
return encoded;
}
public Block(String table_name) {
super();
this.table_name = table_name;
}
public byte[] getBytes() {
// TODO Auto-generated method stub
return this.table_name.getBytes();
}
public int getPrevBlockHash() {
return prevBlockHash;
}
public void setPrevBlockHash(int prevBlockHash) {
this.prevBlockHash = prevBlockHash;
}
public Date getTimestamp() {
return Timestamp;
}
public void setTimestamp(Date timestamp) {
Timestamp = timestamp;
}
public int getHash() {
return hash;
}
public void setHash(int hash) {
this.hash = hash;
}
public int getPreviousHash() {
return previousHash;
}
public void setPreviousHash(int previousHash) {
this.previousHash = previousHash;
}
public String getTable_name() {
return table_name;
}
public void setTable_name(String table_name) {
this.table_name = table_name;
}
}