001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2011, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.se.dto.module;
017
018 import org.qedeq.base.utility.EqualsUtility;
019 import org.qedeq.kernel.se.base.list.Element;
020 import org.qedeq.kernel.se.base.module.SubstPred;
021
022
023 /**
024 * Usage of rule for substitute predicate variable.
025 *
026 * @author Michael Meyling
027 */
028 public class SubstPredVo implements SubstPred {
029
030 /** Reference to previously proven formula. */
031 private String reference;
032
033 /** Function variable that will be substituted. */
034 private Element predicateVariable;
035
036 /** Replacement formula. */
037 private Element substituteFormula;
038
039 /**
040 * Constructs an reason.
041 *
042 * @param reference Reference to a valid formula.
043 * @param predicateVariable Predicate variable that will be substituted.
044 * @param substituteFormula Replacement formula.
045 */
046
047 public SubstPredVo(final String reference, final Element predicateVariable,
048 final Element substituteFormula) {
049 this.reference = reference;
050 this.predicateVariable = predicateVariable;
051 this.substituteFormula = substituteFormula;
052 }
053
054 /**
055 * Default constructor.
056 */
057 public SubstPredVo() {
058 // nothing to do
059 }
060
061 public SubstPred getSubstPred() {
062 return this;
063 }
064
065 public String getReference() {
066 return reference;
067 }
068
069 /**
070 * Set formula reference.
071 *
072 * @param reference Reference to formula.
073 */
074 public void setReference(final String reference) {
075 this.reference = reference;
076 }
077
078 public String[] getReferences() {
079 if (reference == null || reference.length() == 0) {
080 return new String[] {};
081 } else {
082 return new String[] {reference };
083 }
084 }
085
086 public Element getPredicateVariable() {
087 return predicateVariable;
088 }
089
090 /**
091 * Set predicate variable that will be substituted.
092 *
093 * @param predicateVariable Function variable that will be replaced.
094 */
095 public void setPredicateVariable(final Element predicateVariable) {
096 this.predicateVariable = predicateVariable;
097 }
098
099 public Element getSubstituteFormula() {
100 return substituteFormula;
101 }
102
103 /**
104 * Set substitution formula.
105 *
106 * @param substituteFormula New formula.
107 */
108 public void setSubstituteFormula(final Element substituteFormula) {
109 this.substituteFormula = substituteFormula;
110 }
111
112 public String getName() {
113 return "SubstPred";
114 }
115
116 public boolean equals(final Object obj) {
117 if (!(obj instanceof SubstPred)) {
118 return false;
119 }
120 final SubstPred other = (SubstPred) obj;
121 return EqualsUtility.equals(getReference(), other.getReference())
122 && EqualsUtility.equals(predicateVariable, other.getPredicateVariable())
123 && EqualsUtility.equals(substituteFormula, other.getSubstituteFormula());
124 }
125
126 public int hashCode() {
127 return (getReference() != null ? getReference().hashCode() : 0)
128 ^ (getPredicateVariable() != null ? 2 ^ getPredicateVariable().hashCode() : 0)
129 ^ (getSubstituteFormula() != null ? 3 ^ getSubstituteFormula().hashCode() : 0);
130 }
131
132 public String toString() {
133 StringBuffer result = new StringBuffer();
134 result.append("SubstPred");
135 if (getReference() != null || getPredicateVariable() != null
136 || getSubstituteFormula() != null) {
137 result.append(" (");
138 boolean w = false;
139 if (getReference() != null) {
140 result.append(getReference());
141 w = true;
142 }
143 if (getPredicateVariable() != null) {
144 if (w) {
145 result.append(", ");
146 }
147 result.append(getPredicateVariable());
148 w = true;
149 }
150 if (getSubstituteFormula() != null) {
151 if (w) {
152 result.append(", ");
153 }
154 result.append("by ");
155 result.append(getSubstituteFormula());
156 w = true;
157 }
158 result.append(")");
159 }
160 return result.toString();
161 }
162
163 }
|