Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 180   Methods: 9
NCLOC: 74   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConstructedTermImpl.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3    Copyright (c) 2005, University of Innsbruck, Austria
 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.terms;
 17   
 18   
 19    import java.util.*;
 20   
 21    import org.deri.wsmo4j.logicalexpression.util.*;
 22   
 23    import org.omwg.logicalexpression.terms.*;
 24    import org.wsmo.common.*;
 25   
 26   
 27    /**
 28    * @author DERI Innsbruck, reto.krummenacher@deri.org, holger.lausen@deri.org
 29    * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $
 30    *
 31    * @see org.omwg.logicalexpression.terms.ConstructedTerm
 32    */
 33    public class ConstructedTermImpl
 34    implements ConstructedTerm {
 35   
 36    private IRI functionSymbol;
 37   
 38    private List <Term> args = new Vector <Term> ();
 39   
 40    /**
 41    * @param functionSymbol the name of the term, in form of an IRI
 42    * @param terms List of Terms
 43    * @throws IllegalArgumentException in case the functionSymbol is null or the arguments of
 44    * the list aren't all of Type Term
 45    * @see org.wsmo.factory.LogicalExpressionFactory#createConstructedTerm(IRI, List)
 46    */
 47  0 public ConstructedTermImpl(IRI functionSymbol, List <Term> terms)
 48    throws IllegalArgumentException {
 49  0 if (functionSymbol == null) {
 50  0 throw new IllegalArgumentException("functionSymbol may not be null!");
 51    }
 52  0 if (!SetUtil.allOfType(terms, Term.class)) {
 53  0 throw new IllegalArgumentException("Only " + Term.class +" are allowed as Arguments!");
 54    }
 55  0 this.functionSymbol = functionSymbol;
 56  0 if (terms != null) {
 57  0 this.args = Collections.unmodifiableList(terms);
 58    }
 59   
 60    }
 61   
 62    /**
 63    * @return the name of the term, in wsml only possible in form of an IRI
 64    * @see org.omwg.logicalexpression.terms.ConstructedTerm#getFunctionSymbol()
 65    */
 66  0 public IRI getFunctionSymbol() {
 67  0 return functionSymbol;
 68    }
 69   
 70    /**
 71    * @return the arity of the term, i.e. the number of parameters
 72    * @see org.omwg.logicalexpression.terms.ConstructedTerm#getArity()
 73    */
 74  0 public int getArity() {
 75  0 return args.size();
 76    }
 77   
 78    /**
 79    * @param i the position of the parameter desired, maximal getArity()-1
 80    * @return a Term, the chosen parameter
 81    * @see org.omwg.logicalexpression.terms.ConstructedTerm#getParameter(int)
 82    * @throws IndexOutOfBoundsException if the index is out of range (arity)
 83    */
 84  0 public Term getParameter(int i)
 85    throws IndexOutOfBoundsException {
 86  0 return args.get(i);
 87    }
 88   
 89    /**
 90    * @see org.omwg.logicalexpression.terms.Term#accept(org.omwg.logicalexpression.terms.Visitor)
 91    */
 92  0 public void accept(Visitor v) {
 93  0 v.visitConstructedTerm(this);
 94    }
 95   
 96    /**
 97    * @return The String representation of the constructed term
 98    * @see java.lang.Object#toString()
 99    */
 100  0 public String toString() {
 101  0 String ret = functionSymbol.toString() + "(";
 102  0 Iterator i = args.iterator();
 103  0 while (i.hasNext()) {
 104  0 ret += (Term)i.next();
 105  0 if (i.hasNext()) {
 106  0 ret += ",";
 107    }
 108    }
 109  0 ret += ")";
 110  0 return ret;
 111    }
 112   
 113    /**
 114    * <p>
 115    * The <code>equals</code> method implements an equivalence relation
 116    * on non-null object references. Two constructed terms are equal if their arity, their
 117    * functionSymbol, and all of the arguments from the list of terms are equal.
 118    * </p>
 119    * <p>
 120    * It is generally necessary to override the <code>hashCode</code> method whenever this method
 121    * is overridden.
 122    * </p>
 123    * @param o Object of Type ConstructedTerm
 124    * @return <code>true</code> if this object is the same as the obj
 125    * argument; <code>false</code> otherwise.
 126    * @see java.lang.Object#equals(java.lang.Object)
 127    * @see java.lang.Object#hashCode()
 128    */
 129  0 public boolean equals(Object o) {
 130  0 if (o instanceof ConstructedTerm) {
 131  0 ConstructedTerm c = (ConstructedTerm)o;
 132    //no need to check further if functionsymbols or
 133    //arity don't match
 134  0 if (!c.getFunctionSymbol().equals(functionSymbol)
 135    || c.getArity() != this.getArity()) {
 136  0 return false;
 137    }
 138    //check all arguments
 139  0 Iterator i = args.iterator();
 140  0 int n = 0;
 141  0 while (i.hasNext()) {
 142  0 Term t1 = (Term)i.next();
 143  0 Term t2 = c.getParameter(n++);
 144  0 if (!t1.equals(t2)) {
 145  0 return false;
 146    }
 147    }
 148  0 return true;
 149    }
 150  0 return false;
 151    }
 152   
 153    /**
 154    * <p>
 155    * If two objects are equal according to the <code>equals(Object)</code> method, then calling
 156    * the <code>hashCode</code> method on each of the two objects must produce the same integer
 157    * result. However, it is not required that if two objects are unequal according to
 158    * the <code>equals(Object)</code> method, then calling the <code>hashCode</code> method on each of the two
 159    * objects must produce distinct integer results.
 160    * </p>
 161    * <p>
 162    * This method should be overriden, when the <code>equals(Object)</code> method is overriden.
 163    * </p>
 164    * @return A hash code value for this Object.
 165    * @see java.lang.Object#hashCode()
 166    * @see java.lang.Object#equals(Object)
 167    * @see com.ontotext.wsmo4j.common.IRIImpl#hashCode()
 168    */
 169  0 public int hashCode() {
 170    //can probably be more optimized
 171  0 return functionSymbol.hashCode();
 172    }
 173   
 174    /**
 175    * @see org.omwg.logicalexpression.terms.ConstructedTerm#listParameters()
 176    */
 177  0 public List listParameters() {
 178  0 return args;
 179    }
 180    }