001: package org.zilonis.network;
002:
003: /**
004: * Copyright (c) 2005 Elie Levy <elie.levy@zilonis.org>
005: * All rights reserved
006: *
007: * This License governs use of the accompanying Software, and your use of the
008: * Software constitutes acceptance of this license.
009: *
010: * You may use this Software for any non-commercial purpose, subject to the
011: * restrictions in this license. Some purposes which can be non-commercial are
012: * teaching, academic research, and personal experimentation. You may also
013: * distribute this Software with books or other teaching materials, or publish
014: * the Software on websites, that are intended to teach the use of the
015: * Software.
016: *
017: *
018: * You may not use or distribute this Software or any derivative works in any
019: * form for commercial purposes. Examples of commercial purposes would be
020: * running business operations, licensing, leasing, or selling the Software, or
021: * distributing the Software for use with commercial products.
022: *
023: * You may modify this Software and distribute the modified Software for
024: * non-commercial purposes, however, you may not grant rights to the Software
025: * or derivative works that are broader than those provided by this License.
026: * For example, you may not distribute modifications of the Software under
027: * terms that would permit commercial use, or under terms that purport to
028: * require the Software or derivative works to be sublicensed to others.
029: *
030: * You may use any information in intangible form that you remember after
031: * accessing the Software. However, this right does not grant you a license to
032: * any of the copyrights or patents for anything you might create using such
033: * information.
034: *
035: * In return, we simply require that you agree:
036: *
037: * Not to remove any copyright or other notices from the Software.
038: *
039: *
040: * That if you distribute the Software in source or object form, you will
041: * include a verbatim copy of this license.
042: *
043: *
044: * That if you distribute derivative works of the Software in source code form
045: * you do so only under a license that includes all of the provisions of this
046: * License, and if you distribute derivative works of the Software solely in
047: * object form you do so only under a license that complies with this License.
048: *
049: *
050: * That if you have modified the Software or created derivative works, and
051: * distribute such modifications or derivative works, you will cause the
052: * modified files to carry prominent notices so that recipients know that they
053: * are not receiving the original Software. Such notices must state: (i) that
054: * you have changed the Software; and (ii) the date of any changes.
055: *
056: *
057: * THAT THE SOFTWARE COMES "AS IS", WITH NO WARRANTIES. THIS MEANS NO EXPRESS,
058: * IMPLIED OR STATUTORY WARRANTY, INCLUDING WITHOUT LIMITATION, WARRANTIES OF
059: * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR ANY WARRANTY OF TITLE
060: * OR NON-INFRINGEMENT. ALSO, YOU MUST PASS THIS DISCLAIMER ON WHENEVER YOU
061: * DISTRIBUTE THE SOFTWARE OR DERIVATIVE WORKS.
062: *
063: *
064: * THAT NEITHER ZILONIS NOR THE AUTHOR WILL BE LIABLE FOR ANY DAMAGES RELATED
065: * TO THE SOFTWARE OR THIS LICENSE, INCLUDING DIRECT, INDIRECT, SPECIAL,
066: * CONSEQUENTIAL OR INCIDENTAL DAMAGES, TO THE MAXIMUM EXTENT THE LAW PERMITS,
067: * NO MATTER WHAT LEGAL THEORY IT IS BASED ON. ALSO, YOU MUST PASS THIS
068: * LIMITATION OF LIABILITY ON WHENEVER YOU DISTRIBUTE THE SOFTWARE OR
069: * DERIVATIVE WORKS.
070: *
071: *
072: * That if you sue anyone over patents that you think may apply to the Software
073: * or anyone's use of the Software, your license to the Software ends
074: * automatically.
075: *
076: *
077: * That your rights under the License end automatically if you breach it in any
078: * way.
079: *
080: *
081: * Elie Levy reserves all rights not expressly granted to you in this
082: * license.
083: *
084: */
085:
086: import org.zilonis.network.beta.BetaMemory;
087: import org.zilonis.network.beta.IndexedBetaMemory;
088: import org.zilonis.network.negative.NCCNode;
089: import org.zilonis.network.negative.NCCPartnerNode;
090: import org.zilonis.network.negative.NegativeNode;
091: import org.zilonis.symbol.Triplet;
092:
093: import java.util.logging.Logger;
094:
095: public class Condition {
096:
097: public final static int POSITIVE_CONDITION = 0;
098:
099: public final static int NEGATIVE_CONDITION = 1;
100:
101: public final static int CONJUNCTIVE_NEGATION_CONDITION = 2;
102:
103: public final static int BOOLEAN_EXPRESSION = 3;
104:
105: private final static Logger logger = Logger
106: .getLogger("org.zilonis.network.Condition");
107:
108: private BetaMemory betaMemory;
109:
110: private IndexedBetaMemory indexedBetaMemory;
111:
112: private NegativeNode negativeNode;
113:
114: private NCCNode nccNode;
115:
116: private NCCPartnerNode nccPartnerNode;
117:
118: private int type;
119:
120: private Condition prev, next;
121:
122: // used only in the positive and negative conditions
123: private Triplet triplet;
124:
125: // used only in the conjunctive negation conditions
126: private Condition top;
127:
128: private Condition bottom;
129:
130: private int numberOfSubConditions;
131:
132: // used only on boolean expression conditions
133: private String expression;
134:
135: private String variables[];
136:
137: public Condition(int type, Condition top) {
138: this .type = type;
139: this .top = top;
140: for (numberOfSubConditions = 1; top != null; top = top
141: .getNext()) {
142: ++numberOfSubConditions;
143: bottom = top;
144: }
145: }
146:
147: public Condition(String expression, String variables[]) {
148: this .type = BOOLEAN_EXPRESSION;
149: this .variables = variables;
150: this .expression = expression;
151: }
152:
153: public Condition(int type, Condition top, Condition bottom) {
154: this .type = type;
155: this .top = top;
156: this .bottom = bottom;
157: for (numberOfSubConditions = 1; bottom != top; bottom = bottom
158: .getPrev())
159: ++numberOfSubConditions;
160: logger.finest("number of conditions:" + numberOfSubConditions);
161: logger.finest("subconditions:" + top);
162: }
163:
164: public Condition(int type, Triplet triplet) {
165: this .triplet = triplet;
166: this .type = type;
167: }
168:
169: public NCCNode getNccNode() {
170: return nccNode;
171: }
172:
173: public void setNccNode(NCCNode nccNode) {
174: this .nccNode = nccNode;
175: }
176:
177: public NCCPartnerNode getNccPartnerNode() {
178: return nccPartnerNode;
179: }
180:
181: public void setNccPartnerNode(NCCPartnerNode nccPartnerNode) {
182: this .nccPartnerNode = nccPartnerNode;
183: }
184:
185: public void setNegativeNode(NegativeNode negativeNode) {
186: this .negativeNode = negativeNode;
187: }
188:
189: public NegativeNode getNegativeNode() {
190: return negativeNode;
191: }
192:
193: public void setBetaMemory(BetaMemory betaMemory) {
194: this .betaMemory = betaMemory;
195: }
196:
197: public void setIndexedBetaMemory(IndexedBetaMemory betaMemory) {
198: this .indexedBetaMemory = betaMemory;
199: }
200:
201: public IndexedBetaMemory getIndexedBetaMemory() {
202: return indexedBetaMemory;
203: }
204:
205: public BetaMemory getBetaMemory() {
206: return betaMemory;
207: }
208:
209: public String getExpression() {
210: return expression;
211: }
212:
213: public String[] getVariables() {
214: return variables;
215: }
216:
217: public Triplet getTriplet() {
218: return triplet;
219: }
220:
221: public boolean isType(int type) {
222: return (type == this .type);
223: }
224:
225: public int getType() {
226: return type;
227: }
228:
229: public void setNext(Condition next) {
230: this .next = next;
231: }
232:
233: public void setPrev(Condition prev) {
234: this .prev = prev;
235: if (top != null)
236: top.setPrev(prev);
237: }
238:
239: public void setTop(Condition top) {
240: this .top = top;
241: }
242:
243: public void setBottom(Condition bottom) {
244: this .bottom = bottom;
245: }
246:
247: public Condition getNext() {
248: return next;
249: }
250:
251: public Condition getPrev() {
252: return prev;
253: }
254:
255: public Condition getTop() {
256: return top;
257: }
258:
259: public Condition getBottom() {
260: return bottom;
261: }
262:
263: public int getNumberOfSubConditions() {
264: return numberOfSubConditions;
265: }
266:
267: public String toString() {
268: String value = (triplet != null) ? triplet.toString()
269: : (type == BOOLEAN_EXPRESSION) ? expression : "";
270: String result = "Condition type:" + type + " => " + value;
271: return result;
272: }
273: }
|