-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBool3.java
More file actions
102 lines (81 loc) · 1.74 KB
/
Copy pathBool3.java
File metadata and controls
102 lines (81 loc) · 1.74 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
public class Bool3 {
public static final int TRUE = 1;
public static final int UNKNOWN = 0;
public static final int FALSE = -1;
public static final int FUTURE = 2; // determined to one of 3 values on the future, maybe.
int value;
public Bool3(int b)
{
value = b;
}
public Bool3(boolean b)
{
if (b)
value = TRUE;
else
value = FALSE;
}
public boolean proceed()
{
return value == TRUE || value == FUTURE;
}
public static Bool3 and(Bool3 a, Bool3 b)
{
if (a.value == FUTURE && b.value == FUTURE ||
a.value == FUTURE && b.value == TRUE ||
a.value == TRUE && b.value == FUTURE)
return new Bool3(FUTURE);
if (a.value == TRUE && b.value == TRUE)
return new Bool3(TRUE);
if (a.value == FALSE || b.value == FALSE)
return new Bool3(FALSE);
return new Bool3(UNKNOWN);
}
public static Bool3 or(Bool3 a, Bool3 b)
{
if (a.value == FUTURE && b.value == FUTURE ||
a.value == FUTURE && b.value == FALSE ||
a.value == FALSE && b.value == FUTURE)
return new Bool3(FUTURE);
if (a.value == TRUE || b.value == TRUE)
return new Bool3(TRUE);
if (a.value == FALSE && a.value == FALSE)
return new Bool3(FALSE);
return new Bool3(UNKNOWN);
}
public static Bool3 not(Bool3 a)
{
if (a.value == TRUE)
return new Bool3(FALSE);
if (a.value == FALSE)
return new Bool3(TRUE);
return a;
}
public void and(Bool3 b)
{
value = and(this, b).value;
}
public void or(Bool3 b)
{
value = or(this, b).value;
}
public void not()
{
value = not(this).value;
}
public String toString()
{
switch(value)
{
case FALSE:
return "false";
case UNKNOWN:
return "unknown";
case TRUE:
return "true";
case FUTURE:
return "future";
}
return "???";
}
}