ExistentialVo.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2013,  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.apache.commons.lang.ArrayUtils;
019 import org.qedeq.base.utility.EqualsUtility;
020 import org.qedeq.kernel.se.base.list.Element;
021 import org.qedeq.kernel.se.base.module.Existential;
022 
023 
024 /**
025  * Usage of rule for existential generalization.
026  *
027  @author  Michael Meyling
028  */
029 public class ExistentialVo implements Existential {
030 
031     /** Reference to previously proven formula. Usually like A -&gt; B. */
032     private String reference;
033 
034     /** Subject variable that we will quantify about. */
035     private Element subjectVariable;
036 
037     /**
038      * Constructs an reason.
039      *
040      @param   reference                   Reference to a valid formula.
041      @param   subjectVariable             Subject variable that we will quantify about.
042      */
043 
044     public ExistentialVo(final String reference, final Element subjectVariable) {
045         this.reference = reference;
046         this.subjectVariable = subjectVariable;
047     }
048 
049     /**
050      * Default constructor.
051      */
052     public ExistentialVo() {
053         // nothing to do
054     }
055 
056     public Existential getExistential() {
057         return this;
058     }
059 
060     public String getReference() {
061         return reference;
062     }
063 
064     /**
065      * Set formula reference.
066      *
067      @param   reference   Reference to formula.
068      */
069     public void setReference(final String reference) {
070         this.reference = reference;
071     }
072 
073     public String[] getReferences() {
074         if (reference == null) {
075             return ArrayUtils.EMPTY_STRING_ARRAY;
076         }
077         return new String[] {reference };
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 = (ExistentialVoobj;
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 ^ subjectVariable.hashCode() 0);
109     }
110 
111     public String toString() {
112         StringBuffer result = new StringBuffer();
113         result.append(getName());
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 }