1 | package com.algomagic.atn; |
---|
2 | |
---|
3 | public class NodeState implements VisualizationConstants { |
---|
4 | private String _satisfied; |
---|
5 | private boolean _opponentProcessed; |
---|
6 | private boolean _verifierProcessed; |
---|
7 | private boolean _hidden; |
---|
8 | private boolean _bolded; |
---|
9 | |
---|
10 | private String _name; |
---|
11 | private String _type; |
---|
12 | |
---|
13 | public NodeState( NodeState ns ) { |
---|
14 | _name = ns.getName( ); |
---|
15 | _satisfied = ns.getSatisfied( ); |
---|
16 | _type = ns.getType( ); |
---|
17 | _hidden = ns.getHidden( ); |
---|
18 | _bolded = ns.getBolded( ); |
---|
19 | } |
---|
20 | |
---|
21 | |
---|
22 | public NodeState( String name, String type ) { |
---|
23 | _name = name; |
---|
24 | _type = type; |
---|
25 | |
---|
26 | _satisfied = UNKNOWN; |
---|
27 | _opponentProcessed = false; |
---|
28 | _verifierProcessed = false; |
---|
29 | _hidden = true; |
---|
30 | _bolded = false; |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | public int updateState( NodeUpdate update ) { |
---|
35 | _hidden = false; |
---|
36 | |
---|
37 | // if( _satisfied.equals( update.getSatisfied( ) ) ) { |
---|
38 | // return false; |
---|
39 | // } |
---|
40 | |
---|
41 | int s = setSatisfied( update.getSatisfied( ) ); |
---|
42 | int p = setProcessed( update.getProcessed( ) ); |
---|
43 | |
---|
44 | return s+p; |
---|
45 | } |
---|
46 | |
---|
47 | public int setSatisfied( String state ) { |
---|
48 | int ret = 0; |
---|
49 | |
---|
50 | if( _satisfied.equals( SATISFIED ) || _satisfied.equals( NOT_SATISFIED) ) { |
---|
51 | return 0; |
---|
52 | } |
---|
53 | |
---|
54 | if( state == null ) { |
---|
55 | _satisfied = UNKNOWN; |
---|
56 | } |
---|
57 | |
---|
58 | if( _satisfied.toLowerCase( ).equals( state.toLowerCase( ) ) ) { |
---|
59 | return ret; |
---|
60 | } |
---|
61 | |
---|
62 | _satisfied = state; |
---|
63 | return 2; |
---|
64 | } |
---|
65 | |
---|
66 | public int setProcessed( String state ) { |
---|
67 | int ret = 0; |
---|
68 | |
---|
69 | if( state.toLowerCase( ).equals( VERIFIER_PROC.toLowerCase( ) ) ) { |
---|
70 | if( _verifierProcessed == false ) { |
---|
71 | ret = 1; |
---|
72 | } |
---|
73 | |
---|
74 | _verifierProcessed = true; |
---|
75 | } else if ( state.toLowerCase( ).equals( OPPONENT_PROC.toLowerCase( ) ) ) { |
---|
76 | if( _opponentProcessed == false ) { |
---|
77 | ret = 1; |
---|
78 | } |
---|
79 | |
---|
80 | _opponentProcessed = true; |
---|
81 | } else if ( state.toLowerCase( ).equals( FULLY_PROC.toLowerCase( ) ) ) { |
---|
82 | if( _opponentProcessed == false || _verifierProcessed == false ) { |
---|
83 | ret = 1; |
---|
84 | } |
---|
85 | |
---|
86 | _opponentProcessed = true; |
---|
87 | _verifierProcessed = true; |
---|
88 | } |
---|
89 | |
---|
90 | return ret; |
---|
91 | } |
---|
92 | |
---|
93 | public String getSatisfied( ) { |
---|
94 | return _satisfied; |
---|
95 | } |
---|
96 | |
---|
97 | public String getProcessed( ) { |
---|
98 | if( _opponentProcessed && _verifierProcessed ) { |
---|
99 | return FULLY_PROC; |
---|
100 | } |
---|
101 | |
---|
102 | if( _opponentProcessed ) { |
---|
103 | return OPPONENT_PROC; |
---|
104 | } |
---|
105 | |
---|
106 | if( _verifierProcessed ) { |
---|
107 | return VERIFIER_PROC; |
---|
108 | } |
---|
109 | |
---|
110 | return NOT_PROC; |
---|
111 | } |
---|
112 | |
---|
113 | public void setHidden( boolean state ) { |
---|
114 | _hidden = state; |
---|
115 | } |
---|
116 | |
---|
117 | public boolean getHidden( ) { |
---|
118 | return _hidden; |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | public String getType( ) { |
---|
123 | return _type; |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | public String getName( ) { |
---|
128 | return _name; |
---|
129 | } |
---|
130 | |
---|
131 | public void setBolded( boolean state ) { |
---|
132 | _bolded = state; |
---|
133 | } |
---|
134 | |
---|
135 | public boolean getBolded( ) { |
---|
136 | return _bolded; |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | public void clearState( ) { |
---|
141 | if( _satisfied.equals( SATISFIED ) || _satisfied.equals( NOT_SATISFIED) ) { |
---|
142 | _satisfied = UNKNOWN; |
---|
143 | } |
---|
144 | _opponentProcessed = false; |
---|
145 | _verifierProcessed = false; |
---|
146 | _hidden = true; |
---|
147 | _bolded = false; |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | } |
---|
152 | |
---|