View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2004, DERI Innsbruck
4    This library is free software; you can redistribute it and/or modify it under
5    the terms of the GNU Lesser General Public License as published by the Free
6    Software Foundation; either version 2.1 of the License, or (at your option)
7    any later version.
8    This library is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11   details.
12   You should have received a copy of the GNU Lesser General Public License along
13   with this library; if not, write to the Free Software Foundation, Inc.,
14   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15   */
16  package org.deri.wsmo4j.logicalexpression;
17  
18  
19  import org.omwg.logicalexpression.Molecule;
20  import org.omwg.logicalexpression.terms.Term;
21  
22  
23  /**
24   * This class reunites all molecular simple logical expressions
25   *
26   * @author DERI Innsbruck, reto.krummenacher@deri.org
27   * @version $Revision: 1885 $ $Date: 2006-11-17 17:07:59 +0200 (Fri, 17 Nov 2006) $
28   * @see org.omwg.logicalexpression.AtomicExpression
29   */
30  public abstract class MoleculeImpl extends LogicalExpressionImpl
31          implements Molecule {
32  
33      private Term leftTerm;
34      
35      private Term rightTerm;
36      
37      public MoleculeImpl(Term leftTerm, Term rightTerm)
38              throws IllegalArgumentException {
39          setLeftOperand(leftTerm);
40          setRightOperand(rightTerm);
41      }
42      
43     /**
44       * <p>
45       * The <code>equals</code> method implements an equivalence relation
46       * on non-null object references. Molecules are equal if their term is equal and
47       * if their set of AttributeSpecifications (if any), set of MemberOfs (if any) or set of
48       * subConceptOfs (if any) is equal.
49       * </p>
50       * <p>
51       * It is generally necessary to override the <code>hashCode</code> method whenever this method
52       * is overridden.
53       * </p>
54       * @param o the reference object with which to compare.
55       * @return <code>true</code> if this object is the same as the obj
56       *          argument; <code>false</code> otherwise.
57       * @see java.lang.Object#equals(java.lang.Object)
58       * @see java.lang.Object#hashCode()
59       */
60      public boolean equals(Object o) {
61          if (o instanceof Molecule) {
62              Molecule m = (Molecule)o;
63              if (m.getLeftParameter().equals(leftTerm) &&
64                      m.getRightParameter().equals(rightTerm)){
65              return true;
66              }
67          }
68          return false;
69      }
70      
71      public int hashCode() {
72          return leftTerm.hashCode() + rightTerm.hashCode();
73      }
74  
75      public Term getLeftParameter() {
76          return leftTerm;
77      }
78  
79      public Term getRightParameter() {
80          return rightTerm;
81      }
82  
83      /* (non-Javadoc)
84       * @see org.omwg.logicalexpression.Molecule#setLeftOperand(org.omwg.logicalexpression.terms.Term)
85       */
86      public void setLeftOperand(Term t) throws IllegalArgumentException{
87          if (t == null) {
88              throw new IllegalArgumentException(
89                      "No Term in Molecule Spec may be null");
90          }
91          leftTerm = t;
92      }
93  
94      /* (non-Javadoc)
95       * @see org.omwg.logicalexpression.Molecule#setRightOperand(org.omwg.logicalexpression.terms.Term)
96       */
97      public void setRightOperand(Term t) throws IllegalArgumentException{
98          if (t == null) {
99              throw new IllegalArgumentException(
100                     "No Term in Molecule Spec may be null");
101         }
102         rightTerm = t;
103     }
104 }