View Javadoc

1   /* This file is part of the project "Hilbert II" - http://www.qedeq.org" target="alexandria_uri">http://www.qedeq.org
2    *
3    * Copyright 2000-2014,  Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU General Public License for more details.
14   */
15  
16  package org.qedeq.kernel.se.dto.module;
17  
18  import org.qedeq.base.utility.EqualsUtility;
19  import org.qedeq.kernel.se.base.module.Axiom;
20  import org.qedeq.kernel.se.base.module.Formula;
21  import org.qedeq.kernel.se.base.module.FunctionDefinition;
22  import org.qedeq.kernel.se.base.module.InitialFunctionDefinition;
23  import org.qedeq.kernel.se.base.module.InitialPredicateDefinition;
24  import org.qedeq.kernel.se.base.module.LatexList;
25  import org.qedeq.kernel.se.base.module.PredicateDefinition;
26  import org.qedeq.kernel.se.base.module.Proposition;
27  import org.qedeq.kernel.se.base.module.Rule;
28  
29  
30  /**
31   * Definition of operator. This is a predicate constant. For example the
32   * predicate "x is a set" could be defined in MK with the formula "\exists y: x \in y".
33   *
34   * @author  Michael Meyling
35   */
36  public class PredicateDefinitionVo implements PredicateDefinition {
37  
38      /** Carries information about the argument number the defined object needs.  */
39      private String argumentNumber;
40  
41      /** This name together with argumentNumber identifies a function. */
42      private String name;
43  
44      /** LaTeX pattern for definition visualisation. The replaceable arguments must are
45       * marked as <code>#1</code>, <code>#2</code> and so on. For example
46       * <code>\mathfrak{M}(#1)</code> */
47      private String latexPattern;
48  
49      /** Formula that defines the object.*/
50      private Formula formula;
51  
52      /** Further proposition description. Normally <code>null</code>. */
53      private LatexList description;
54  
55      /**
56       * Constructs a new definition.
57       */
58      public PredicateDefinitionVo() {
59          // nothing to do
60      }
61  
62      public Axiom getAxiom() {
63          return null;
64      }
65  
66      public InitialPredicateDefinition getInitialPredicateDefinition() {
67          return null;
68      }
69  
70      public PredicateDefinition getPredicateDefinition() {
71          return this;
72      }
73  
74      public InitialFunctionDefinition getInitialFunctionDefinition() {
75          return null;
76      }
77  
78      public FunctionDefinition getFunctionDefinition() {
79          return null;
80      }
81  
82      public Proposition getProposition() {
83          return null;
84      }
85  
86      public Rule getRule() {
87          return null;
88      }
89  
90      /**
91       * Set information about the argument number the defined object needs.
92       *
93       * @param   argumentNumber  Argument number information.
94       */
95      public final void setArgumentNumber(final String argumentNumber) {
96          this.argumentNumber = argumentNumber;
97      }
98  
99      public final String getArgumentNumber() {
100         return argumentNumber;
101     }
102 
103     /**
104      * Set predicate name. Together with {@link #getArgumentNumber()} this
105      * identifies a predicate.
106      *
107      * @param   name    Predicate name.
108      */
109     public void setName(final String name) {
110         this.name = name;
111     }
112 
113     public String getName() {
114         return name;
115     }
116 
117     /**
118      * Set LaTeX pattern for definition visualisation. The replaceable arguments are
119      * marked as <code>#1</code>, <code>#2</code> and so on. For example
120      * <code>\mathfrak{M}(#1)</code>.
121      *
122      * @param   latexPattern    LaTeX pattern for definition visualisation.
123      */
124     public final void setLatexPattern(final String latexPattern) {
125         this.latexPattern = latexPattern;
126     }
127 
128     public final String getLatexPattern() {
129         return latexPattern;
130     }
131 
132     /**
133      * Set defining formula or term that defines the object. Could be <code>null</code>.
134      *
135      * @param   formulaOrTerm   Formula or term that defines the new operator.
136      */
137     public final void setFormula(final FormulaVo formulaOrTerm) {
138         this.formula = formulaOrTerm;
139     }
140 
141     public final Formula getFormula() {
142         return formula;
143     }
144 
145     /**
146      * Set description. Only necessary if formula is not self-explanatory.
147      *
148      * @param   description Description.
149      */
150     public final void setDescription(final LatexListVo description) {
151         this.description = description;
152     }
153 
154     public LatexList getDescription() {
155         return description;
156     }
157 
158     public boolean equals(final Object obj) {
159         if (!(obj instanceof PredicateDefinition)) {
160             return false;
161         }
162         final PredicateDefinition other = (PredicateDefinition) obj;
163         return  EqualsUtility.equals(getArgumentNumber(), other.getArgumentNumber())
164             &&  EqualsUtility.equals(getName(), other.getName())
165             &&  EqualsUtility.equals(getLatexPattern(), other.getLatexPattern())
166             &&  EqualsUtility.equals(getFormula(), other.getFormula())
167             &&  EqualsUtility.equals(getDescription(), other.getDescription());
168     }
169 
170     public int hashCode() {
171         return (getArgumentNumber() != null ? getArgumentNumber().hashCode() : 0)
172             ^ (getName() != null ? 1 ^ getName().hashCode() : 0)
173             ^ (getLatexPattern() != null ? 2 ^ getLatexPattern().hashCode() : 0)
174             ^ (getFormula() != null ? 4 ^ getFormula().hashCode() : 0)
175             ^ (getDescription() != null ? 5 ^ getDescription().hashCode() : 0);
176     }
177 
178     public String toString() {
179         final StringBuffer buffer = new StringBuffer();
180         buffer.append("Predicate Definition arguments=" + getArgumentNumber() + "\n");
181         buffer.append("\tname=" + getName() + "\n");
182         buffer.append("\tpattern=" + getLatexPattern() + "\n");
183         buffer.append("\tformula:\n" + getFormula() + "\n");
184         buffer.append("\tdescription:\n" + getDescription() + "\n");
185         return buffer.toString();
186     }
187 
188 
189 }