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.module.ModusPonens;
020
021
022 /**
023 * Modes Ponens usage.
024 *
025 * @author Michael Meyling
026 */
027 public class ModusPonensBo implements ModusPonens {
028
029 /** Reference to a formula like A -> B. */
030 private int n1;
031
032 /** Usually reference to a formula like A. */
033 private int n2;
034
035 /**
036 * Constructs a Modus Ponens argument.
037 *
038 * @param n1 Usually reference to a formula like A -> B.
039 * @param n2 Usually reference to a formula like A.
040 */
041 public ModusPonensBo(final int n1, final int n2) {
042 this.n1 = n1;
043 this.n2 = n2;
044 }
045
046 public String getReference1() {
047 return "" + n1;
048 }
049
050 /**
051 * Set first formula reference.
052 *
053 * @param n1 Reference to formula.
054 */
055 public void setN1(final int n1) {
056 this.n1 = n1;
057 }
058
059 /**
060 * Get first formula reference.
061 *
062 * @return Reference to formula.
063 */
064 public int getN1() {
065 return n1;
066 }
067
068 public String getReference2() {
069 return "" + n2;
070 }
071
072 /**
073 * Set second formula reference.
074 *
075 * @param n2 Reference to formula.
076 */
077 public void setN2(final int n2) {
078 this.n2 = n2;
079 }
080
081 /**
082 * Get second formula reference.
083 *
084 * @return Reference to formula.
085 */
086 public int getN2() {
087 return n2;
088 }
089
090 public String[] getReferences() {
091 return new String[] {getReference1(), getReference2()};
092 }
093
094 /**
095 * Get references to previous lines.
096 *
097 * @return List of references.
098 */
099 public int[] getLines() {
100 return new int[] {getN1(), getN2()};
101 }
102
103 public boolean equals(final Object obj) {
104 if (!(obj instanceof ModusPonens)) {
105 return false;
106 }
107 final ModusPonens other = (ModusPonens) obj;
108 return EqualsUtility.equals(getReference1(), other.getReference1())
109 && EqualsUtility.equals(getReference2(), other.getReference2());
110 }
111
112 public int hashCode() {
113 return (getReference1() != null ? getReference1().hashCode() : 0)
114 + (getReference2() != null ? 1 ^ getReference2().hashCode() : 0);
115 }
116
117 public String toString() {
118 StringBuffer result = new StringBuffer();
119 result.append("MP");
120 if (getReference1() != null || getReference2() != null) {
121 result.append(" (");
122 if (getReference1() != null) {
123 result.append(getReference1());
124 }
125 if (getReference2() != null) {
126 if (getReference1() != null) {
127 result.append(", ");
128 }
129 result.append(getReference2());
130 }
131 result.append(")");
132 }
133 return result.toString();
134 }
135
136 public String getName() {
137 return "MP";
138 }
139
140 }
|