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.Existential;
021
022
023 /**
024 * Usage of rule for existential generalization.
025 *
026 * @author Michael Meyling
027 */
028 public class ExistentialVo implements Existential {
029
030 /** Reference to previously proven formula. Usually like A -> B. */
031 private String reference;
032
033 /** Subject variable that we will quantify about. */
034 private Element subjectVariable;
035
036 /**
037 * Constructs an reason.
038 *
039 * @param reference Reference to a valid formula.
040 * @param subjectVariable Subject variable that we will quantify about.
041 */
042
043 public ExistentialVo(final String reference, final Element subjectVariable) {
044 this.reference = reference;
045 this.subjectVariable = subjectVariable;
046 }
047
048 /**
049 * Default constructor.
050 */
051 public ExistentialVo() {
052 // nothing to do
053 }
054
055 public Existential getExistential() {
056 return this;
057 }
058
059 public String getReference() {
060 return reference;
061 }
062
063 /**
064 * Set formula reference.
065 *
066 * @param reference Reference to formula.
067 */
068 public void setReference(final String reference) {
069 this.reference = reference;
070 }
071
072 public String[] getReferences() {
073 if (reference == null || reference.length() == 0) {
074 return new String[] {};
075 } else {
076 return new String[] {reference };
077 }
078 }
079
080 public Element getSubjectVariable() {
081 return subjectVariable;
082 }
083
084 /**
085 * Set quantification subject variable.
086 *
087 * @param subjectVariable Set free subject variable.
088 */
089 public void setSubjectVariable(final Element subjectVariable) {
090 this.subjectVariable = subjectVariable;
091 }
092
093 public String getName() {
094 return "Existential";
095 }
096
097 public boolean equals(final Object obj) {
098 if (!(obj instanceof ExistentialVo)) {
099 return false;
100 }
101 final ExistentialVo other = (ExistentialVo) obj;
102 return EqualsUtility.equals(reference, other.reference)
103 && EqualsUtility.equals(subjectVariable, other.subjectVariable);
104 }
105
106 public int hashCode() {
107 return (reference != null ? reference.hashCode() : 0)
108 ^ (subjectVariable != null ? 2 ^ subjectVariable.hashCode() : 0);
109 }
110
111 public String toString() {
112 StringBuffer result = new StringBuffer();
113 result.append("SubstFree");
114 if (reference != null || subjectVariable != null) {
115 result.append(" (");
116 boolean w = false;
117 if (reference != null) {
118 result.append(reference);
119 w = true;
120 }
121 if (subjectVariable != null) {
122 if (w) {
123 result.append(", ");
124 }
125 result.append(subjectVariable);
126 w = true;
127 }
128 result.append(")");
129 }
130 return result.toString();
131 }
132
133 }
|