forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.java
More file actions
132 lines (111 loc) · 2.36 KB
/
Type.java
File metadata and controls
132 lines (111 loc) · 2.36 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
123
124
125
126
127
128
129
130
131
132
package org.tron.common.storage;
public class Type {
/**
* Default Mode : VALUE_TYPE_NORMAL
*/
public static int VALUE_TYPE_NORMAL = 0;
public static int VALUE_TYPE_DIRTY = 1 << 0;
public static int VALUE_TYPE_CREATE = 1 << 1;
public static int VALUE_TYPE_UNKNOWN = 0xFFFFFFFC;
protected int type = VALUE_TYPE_NORMAL;
/**
* @param type
*/
public Type(int type) {
this.type |= type;
}
/**
* default constructor
*/
public Type() {}
/**
* @param T
*/
private Type(Type T) {
this.type = T.getType();
}
/**
* @return
*/
public Type clone() {
return new Type(this);
}
/**
* @return
*/
public boolean isDirty() {
return (this.type & VALUE_TYPE_DIRTY) == VALUE_TYPE_DIRTY;
}
/**
* @return
*/
public boolean isNormal() {
return this.type == VALUE_TYPE_NORMAL;
}
/**
* @return
*/
public boolean isCreate() {
return (this.type & VALUE_TYPE_CREATE) == VALUE_TYPE_CREATE;
}
/**
* @return
*/
public boolean shouldCommit() {
return this.type != VALUE_TYPE_NORMAL;
}
/**
* @return
*/
public int getType() {
return type;
}
/**
* @param type
* @return
*/
public boolean isValidType(int type) {
if ((type & VALUE_TYPE_UNKNOWN) != VALUE_TYPE_NORMAL) return false;
return true;
}
/**
* @param type
*/
public void setType(int type) {
if (isValidType(type)) {
this.type = type;
}
}
/**
* @param type
*/
public void addType(int type) {
if (isValidType(type)) {
this.type |= type;
}
}
/**
* @param T
*/
public void addType(Type T) {
addType(T.getType());
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || obj.getClass() != getClass()) return false;
Type T = (Type)obj;
if (this.type != T.getType()) return false;
return true;
}
@Override
public int hashCode() {
return new Integer(type).hashCode();
}
@Override
public String toString() {
return "Type{" +
"type=" + type +
'}';
}
}