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.bo.logic.proof.finder;
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 SubstPredBo implements SubstPred {
029
030 /** Reference to previously proven formula. */
031 private int n;
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 n Reference to a valid formula.
043 * @param predicateVariable Predicate variable that will be substituted.
044 * @param substituteFormula Replacement formula.
045 */
046
047 public SubstPredBo(final int n, final Element predicateVariable,
048 final Element substituteFormula) {
049 this.n = n;
050 this.predicateVariable = predicateVariable;
051 this.substituteFormula = substituteFormula;
052 }
053
054 public String getReference() {
055 return "" + n;
056 }
057
058 /**
059 * Set formula reference.
060 *
061 * @param n Reference to formula.
062 */
063 public void setN(final int n) {
064 this.n = n;
065 }
066
067 /**
068 * Get formula reference.
069 *
070 * @return Reference to formula.
071 */
072 public int getN() {
073 return n;
074 }
075
076 public String[] getReferences() {
077 return new String[] {getReference()};
078 }
079
080 public Element getPredicateVariable() {
081 return predicateVariable;
082 }
083
084 public Element getSubstituteFormula() {
085 return substituteFormula;
086 }
087
088 public String getName() {
089 return "SubstPred";
090 }
091
092 public boolean equals(final Object obj) {
093 if (!(obj instanceof SubstPred)) {
094 return false;
095 }
096 final SubstPred other = (SubstPred) obj;
097 return EqualsUtility.equals(getReference(), other.getReference())
098 && EqualsUtility.equals(predicateVariable, other.getPredicateVariable())
099 && EqualsUtility.equals(substituteFormula, other.getSubstituteFormula());
100 }
101
102 public int hashCode() {
103 return (getReference() != null ? getReference().hashCode() : 0)
104 ^ (getPredicateVariable() != null ? 2 ^ getPredicateVariable().hashCode() : 0)
105 ^ (getSubstituteFormula() != null ? 3 ^ getSubstituteFormula().hashCode() : 0);
106 }
107
108 public String toString() {
109 StringBuffer result = new StringBuffer();
110 result.append("SubstPred");
111 if (getReference() != null || getPredicateVariable() != null
112 || getSubstituteFormula() != null) {
113 result.append(" (");
114 boolean w = false;
115 if (getReference() != null) {
116 result.append(getReference());
117 w = true;
118 }
119 if (getPredicateVariable() != null) {
120 if (w) {
121 result.append(", ");
122 }
123 result.append(getPredicateVariable());
124 w = true;
125 }
126 if (getSubstituteFormula() != null) {
127 if (w) {
128 result.append(", ");
129 }
130 result.append("by ");
131 result.append(getSubstituteFormula());
132 w = true;
133 }
134 result.append(")");
135 }
136 return result.toString();
137 }
138
139 }
|