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 dfengine; 00025 00026 import java.util.*; 00027 00028 import theoremprover.Assumption; 00029 00030 /* 00031 * Note that Mode objects are immutable: once they are created, they cannot be changed. 00032 */ 00033 public class Mode implements Cloneable, Comparable { 00034 00035 public final static int MODE_NAB = 0; 00036 public final static int MODE_AB = 1; 00037 public final static int MODE_IF = 2; 00038 public final static int MODE_DF = 3; 00039 00043 protected int type; 00044 00045 protected Component component; 00046 00050 protected Component parent; 00051 00052 /* 00053 * The TP assumption which corresponds to this mode. 00054 * 00055 * Can be "null". 00056 */ 00057 protected Assumption assumption; 00058 00059 00065 public Mode(int type, Component component, Assumption ass) { 00066 assert(type != MODE_DF); 00067 00068 this.type = type; 00069 this.component = component; 00070 this.parent = null; 00071 this.assumption = ass; 00072 } 00073 00079 public Mode(int type, Component component, Component parent, Assumption ass) { 00080 assert(type == MODE_DF); 00081 00082 this.type = type; 00083 this.component = component; 00084 this.parent = parent; 00085 this.assumption = ass; 00086 } 00087 00088 public boolean equals(Object o) { 00089 Mode other = (Mode)o; 00090 return ((this == other) 00091 || ((type == other.type) && (component == other.component) && (parent == other.parent))); 00092 } 00093 00094 public int compareTo(Object o) { 00095 if (equals(o)) return 0; 00096 else { 00097 Mode other = (Mode)o; 00098 int compareComp = component.compareTo(other.component); 00099 if (compareComp != 0) return compareComp; 00100 else { 00101 if (type < other.type) return -1; 00102 else if (type > other.type) return +1; 00103 else { 00104 assert(type == MODE_DF); 00105 int compareParent = parent.compareTo(other.parent); 00106 assert(compareParent != 0); 00107 return compareParent; 00108 } 00109 } 00110 } 00111 00112 } 00113 00114 public String toString() { 00115 00116 StringBuffer res = new StringBuffer(); 00117 if (type != MODE_DF) res.append("mode " + typeAsString(type) 00118 + "(" + component.getName() + ")"); 00119 else res.append("mode " + typeAsString(type) + "(" + parent.getName() 00120 + ", " + component.getName() + ")"); 00121 res.append(": "); 00122 if (assumption == null) res.append("[no assumption]"); 00123 else res.append((String)assumption.getIdentifier()); 00124 00125 return res.toString(); 00126 } 00127 00128 /* 00129 * For debugging. 00130 */ 00131 public String toStringShort() { 00132 if (type != MODE_DF) { 00133 return typeAsString(type) + "(" + component.getName() + ")"; 00134 } else { 00135 return typeAsString(type) + "(" + parent.getName() 00136 + ", " + component.getName() + ")"; 00137 } 00138 } 00139 00140 static public String typeAsString(int type) { 00141 switch(type) { 00142 case MODE_NAB: 00143 return "NAB"; 00144 case MODE_AB: 00145 return "AB"; 00146 case MODE_IF: 00147 return "IF"; 00148 case MODE_DF: 00149 return "DF"; 00150 default: assert(false); 00151 } 00152 return null; 00153 } 00154 00155 public final int getType() { 00156 return type; 00157 } 00158 00159 public final Component getComponent() { 00160 return component; 00161 } 00162 00163 public final Component getParent() { 00164 return parent; 00165 } 00166 00167 public final Assumption getAssumption() { 00168 return assumption; 00169 } 00170 }