-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingleLongBitMaskHandler.java
59 lines (44 loc) · 1.24 KB
/
SingleLongBitMaskHandler.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
package com.nileshdeokar.healthapp.utils;
/**
* Created by niel on 27/05/18.
*/
public class SingleLongBitMaskHandler {
private long healthValue = 0L;
private static final int sizeOfIntInbits = 64;
public boolean set(int position)
{
return setValue(position,true);
}
private boolean setValue(int position,boolean value) {
int offset = position % sizeOfIntInbits;
if(!value) {
healthValue &= ~ (1L << offset);
}
else
{
healthValue |= 1L << offset;
}
System.out.println("set : "+position + " " + value);
return true;
}
public boolean get(int position) {
int offset = position % sizeOfIntInbits;
long bit = (healthValue >> offset) & 1L;
System.out.println("get : "+position + " " + (bit!=0));
return bit!=0;
}
public void clear(int position)
{
setValue(position,false);
}
public Long toLongs()
{
return this.healthValue;
}
public void setLongvalue(Long longValue){
healthValue = longValue;
}
public void toggleDisease(int diseaseToSet, boolean value) {
if(value) set(diseaseToSet); else clear(diseaseToSet);
}
}