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