TestApp2.java
1 |
|
---|---|
2 |
class P2JLogical { |
3 |
private boolean is_Null; |
4 |
private com.goldencode.p2j.util.logical bool_value;
|
5 |
|
6 |
// 2. --------------------------- handling null values ----------------------------------------
|
7 |
public boolean IsNull() { |
8 |
return is_Null;
|
9 |
} |
10 |
|
11 |
public static P2JLogical Null() { |
12 |
P2JLogical logical = new P2JLogical();
|
13 |
logical.is_Null = true;
|
14 |
return logical;
|
15 |
} |
16 |
|
17 |
// 3. --------------------------- handling conversion to/from string --------------------------
|
18 |
public String toString() { |
19 |
if (this.IsNull()) { |
20 |
return "NULL"; |
21 |
} else {
|
22 |
// return bool_value.ToString(); -- this will return Yes / No, we rather prefer 0 / 1
|
23 |
return bool_value.booleanValue() ? "1" : "0"; |
24 |
} |
25 |
} |
26 |
|
27 |
public static P2JLogical Parse(String str) { |
28 |
if (str == null || str.isEmpty()) { |
29 |
return Null();
|
30 |
} |
31 |
|
32 |
// Parse input string here
|
33 |
str = str.trim().toLowerCase(); |
34 |
|
35 |
P2JLogical logical = new P2JLogical();
|
36 |
logical.is_Null = false;
|
37 |
|
38 |
if (str.equals("0")) { |
39 |
logical.bool_value = new com.goldencode.p2j.util.logical(false); |
40 |
} else if (str.equals("1")) { |
41 |
logical.bool_value = new com.goldencode.p2j.util.logical(true); |
42 |
} else {
|
43 |
logical.bool_value = new com.goldencode.p2j.util.logical(str);
|
44 |
} |
45 |
|
46 |
return logical;
|
47 |
} |
48 |
|
49 |
// 4. --------------------------- UDT Method example ------------------------------------------
|
50 |
public P2JLogical P2J_And(P2JLogical other) {
|
51 |
P2JLogical ret = new P2JLogical();
|
52 |
ret.is_Null = false;
|
53 |
ret.bool_value = new com.goldencode.p2j.util.logical(
|
54 |
bool_value.booleanValue() & other.bool_value.booleanValue()); |
55 |
return ret;
|
56 |
} |
57 |
|
58 |
public boolean value() { |
59 |
return bool_value.booleanValue();
|
60 |
} |
61 |
} |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
public class TestApp2 { |
67 |
private com.goldencode.p2j.util.logical bool_value;
|
68 |
|
69 |
|
70 |
public static void main(String[] args) { |
71 |
P2JLogical l1 = P2JLogical.Parse("true");
|
72 |
System.out.println("Parsing 'true' = " + l1); |
73 |
P2JLogical l2 = l1.P2J_And(P2JLogical.Parse("falsE "));
|
74 |
System.out.println("'true' And 'falsE ' = " + l2); |
75 |
} |
76 |
} |