ConditionVisitor.java
Go to the documentation of this file.
00001 /*
00002  * (c) copyright 2008, Technische Universitaet Graz and Technische Universitaet Wien
00003  *
00004  * This file is part of jdiagengine.
00005  *
00006  * jdiagengine is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * jdiagengine is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * You should have received a copy of the GNU General Public License
00016  * along with jdiagengine. If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * Authors: Joerg Weber, Franz Wotawa
00019  * Contact: jweber@ist.tugraz.at (preferred), or fwotawa@ist.tugraz.at
00020  *
00021  */
00022 
00023 
00024 package utils;
00025 
00026 import java.util.*;
00027 
00028 /*
00029  * Checks if a certain condition holds for a node.
00030  *
00031  * The condition is an object which implements the Condition interface.
00032  *
00033  * If the type of the visitor, which is passed to the constructor, 
00034  * is TYPE_CONJUNCTION, then the result of the evaluation is "true" iff
00035  * the cond. holds for all nodes. Furthermore, the initial value is "true".
00036 
00037  * For TYPE_DISJUNCTION, it is sufficient that the condition holds for
00038  * at least one node, but the initial value is "false".
00039  */
00040 public class ConditionVisitor extends DoubleLinkedDAGVisitor {
00041 
00042     public final static int TYPE_CONJUNCTION = 0;
00043     public final static int TYPE_DISJUNCTION = 0;
00044 
00045     protected Condition cond;
00046 
00047     protected boolean holds = false;
00048 
00049     /*
00050      * One of TYPE_x.
00051      */
00052     protected int type;
00053 
00054     
00055     public ConditionVisitor(int type, Condition cond) {
00056         this.type = type;
00057         this.cond = cond;
00058 
00059         if (type == TYPE_CONJUNCTION) holds = true;
00060         else if (type == TYPE_DISJUNCTION) holds = false;
00061         else assert(false);
00062     }
00063 
00064     public boolean wantMoreNodes() {
00065         if (type == TYPE_CONJUNCTION) return holds;
00066         else return !holds;
00067     }
00068 
00069     public void visit(DoubleLinkedDAGNode node) {
00070         boolean b = cond.holds(node);
00071 
00072         if (type == TYPE_CONJUNCTION) holds = holds && b;
00073         else holds = holds || b;
00074     }
00075 
00076     public boolean conditionHolds() {
00077         return holds;
00078     }
00079 
00080 }


tug_ist_diagnosis_engine
Author(s): Safdar Zaman, Gerald Steinbauer
autogenerated on Mon Jan 6 2014 11:51:16