Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 211   Methods: 18
NCLOC: 116   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CompoundMoleculeImpl.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2005, University of Innsbruck, Austria
 5   
 6    This library is free software; you can redistribute it and/or modify it under
 7    the terms of the GNU Lesser General Public License as published by the Free
 8    Software Foundation; either version 2.1 of the License, or (at your option)
 9    any later version.
 10    This library is distributed in the hope that it will be useful, but WITHOUT
 11    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 12    FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 13    details.
 14    You should have received a copy of the GNU Lesser General Public License along
 15    with this library; if not, write to the Free Software Foundation, Inc.,
 16    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17    */
 18    package org.deri.wsmo4j.logicalexpression;
 19   
 20    import java.util.*;
 21   
 22    import org.deri.wsmo4j.io.serializer.wsml.*;
 23    import org.deri.wsmo4j.logicalexpression.util.*;
 24    import org.omwg.logicalexpression.*;
 25    import org.omwg.logicalexpression.Visitor;
 26    import org.omwg.logicalexpression.terms.*;
 27    import org.wsmo.common.*;
 28   
 29    /**
 30    * Represents a Compount Molecule
 31    *
 32    * <pre>
 33    * Created on Sep 19, 2005
 34    * Committed by $Author$
 35    * $Source$,
 36    * </pre>
 37    *
 38    * @author Holger Lausen (holger.lausen@deri.org)
 39    *
 40    * @version $Revision$ $Date$
 41    */
 42    public class CompoundMoleculeImpl implements CompoundMolecule {
 43   
 44    List <Molecule> molecules;
 45   
 46  0 public CompoundMoleculeImpl(List <Molecule> molecules){
 47  0 setOperands(new ArrayList <LogicalExpression> (molecules));
 48    }
 49   
 50  0 public List <AttributeConstraintMolecule> listAttributeConstraintMolecules() {
 51  0 return filter(AttributeConstraintMolecule.class, null);
 52    }
 53   
 54  0 public List <AttributeInferenceMolecule> listAttributeInferenceMolecules() {
 55  0 return filter(AttributeInferenceMolecule.class, null);
 56    }
 57   
 58  0 public List <AttributeValueMolecule> listAttributeValueMolecules() {
 59  0 return filter(AttributeValueMolecule.class, null);
 60    }
 61   
 62  0 public List <AttributeConstraintMolecule> listAttributeConstraintMolecules(Term t) {
 63  0 return filter(AttributeConstraintMolecule.class, t);
 64    }
 65   
 66  0 public List <AttributeInferenceMolecule> listAttributeInferenceMolecules(Term t) {
 67  0 return filter(AttributeInferenceMolecule.class, t);
 68    }
 69   
 70  0 public List <AttributeValueMolecule> listAttributeValueMolecules(Term t) {
 71  0 return filter(AttributeValueMolecule.class, t);
 72    }
 73   
 74  0 public List <MembershipMolecule> listMemberShipMolecules() {
 75  0 return filter(MembershipMolecule.class, null);
 76    }
 77   
 78  0 public List <SubConceptMolecule> listSubConceptMolecules() {
 79  0 return filter(SubConceptMolecule.class, null);
 80    }
 81   
 82  0 public List <LogicalExpression> listOperands() {
 83  0 return new ArrayList <LogicalExpression> (Collections.unmodifiableList(molecules));
 84    }
 85   
 86  0 private List filter(Class clazz, Term attributeName){
 87  0 List ret = new Vector();
 88  0 Iterator i = molecules.iterator();
 89  0 while (i.hasNext()){
 90  0 Object o = i.next();
 91  0 if (clazz.isInstance(o) && //classfilter
 92    (attributeName == null || //if attributeName given check as well
 93    attributeName.equals(((AttributeMolecule)o).getAttribute()))){
 94  0 ret.add(o);
 95    }
 96    }
 97  0 return Collections.unmodifiableList(ret);
 98    }
 99   
 100  0 public void accept(Visitor v) {
 101  0 v.visitCompoundMolecule(this);
 102    }
 103   
 104    /**
 105    *
 106    */
 107  0 public CompoundMoleculeImpl() {
 108  0 super();
 109    // TODO Auto-generated constructor stub
 110    }
 111   
 112   
 113  0 public boolean equals(Object o){
 114  0 if (!(o instanceof CompoundMolecule)){
 115  0 return false;
 116    }
 117  0 if (o==this){
 118  0 return true;
 119    }
 120  0 CompoundMolecule cm = (CompoundMolecule)o;
 121  0 if (cm.listOperands().size()!=molecules.size()){
 122  0 return false;
 123    }
 124  0 Iterator i = cm.listOperands().iterator();
 125  0 while (i.hasNext()){
 126  0 Object molecule = i.next();
 127  0 if (!molecules.contains(molecule)){
 128  0 return false;
 129    }
 130    }
 131  0 return true;
 132    }
 133   
 134  0 public String toString(){
 135  0 return new LogExprSerializerWSML(null).serialize(this);
 136    }
 137   
 138    /* (non-Javadoc)
 139    * @see org.omwg.logicalexpression.CompoundExpression#setOperands(java.util.List)
 140    */
 141  0 public void setOperands(List <LogicalExpression> operands) {
 142  0 if (operands.size() < 2){
 143  0 throw new IllegalArgumentException("Compound Molecules have to consist of at least 2 Molecules");
 144    }
 145  0 if (!SetUtil.allOfType(operands, Molecule.class)){
 146  0 throw new IllegalArgumentException("Compound Molecule can only consist of Molecules");
 147    }
 148  0 Iterator i = operands.iterator();
 149  0 Term t = ((Molecule)i.next()).getLeftParameter();
 150  0 while (i.hasNext()){
 151  0 Term tNext = ((Molecule)i.next()).getLeftParameter();
 152  0 if (!tNext.equals(t)){
 153  0 throw new IllegalArgumentException("Only Molecules with the same ID can be grouped to a Compound Molecule");
 154    }
 155    }
 156   
 157  0 List <Molecule> temp = new ArrayList <Molecule> ();
 158  0 for(LogicalExpression le : operands){
 159  0 if (le instanceof Molecule){
 160  0 temp.add((Molecule) le);
 161    }
 162    }
 163   
 164  0 this.molecules = temp;
 165  0 if (this.listMemberShipMolecules().size() !=0 &&
 166    this.listSubConceptMolecules().size() != 0){
 167  0 throw new IllegalArgumentException("Compound Molecules can have either memberOf or subConceptOf Satement not both!");
 168    }
 169    }
 170   
 171    /**
 172    * Returns String representation of a logical expression.
 173    * @return the string representation of the Logical expression
 174    * @param nsHolder namespace container used to abbreviate IRIs to
 175    * sQNames.
 176    */
 177  0 public String toString(TopEntity nsHolder) {
 178  0 return new LogExprSerializerWSML(nsHolder).serialize(this);
 179    }
 180   
 181  0 public int hashCode() {
 182  0 return CompoundMoleculeImpl.class.hashCode()+molecules.size();
 183    }
 184    }
 185   
 186   
 187    /*
 188    *$Log$
 189    *Revision 1.7 2007/04/02 12:13:20 morcen
 190    *Generics support added to wsmo-api, wsmo4j and wsmo-test
 191    *
 192    *Revision 1.6 2006/05/04 15:16:45 holgerlausen
 193    *fixed bug 1481907 -
 194    *for logicalexpression hashCode() and equals where not correctly implemented
 195    *
 196    *Revision 1.5 2005/11/28 15:46:02 holgerlausen
 197    *added support for using a TopEntity with namespace information to shorten string representation of logical expressions (RFE 1363559)
 198    *
 199    *Revision 1.4 2005/09/21 08:15:38 holgerlausen
 200    *fixing java doc, removing asString()
 201    *
 202    *Revision 1.3 2005/09/21 06:31:55 holgerlausen
 203    *allowing to set arguments rfe 1290049
 204    *
 205    *Revision 1.2 2005/09/20 19:41:01 holgerlausen
 206    *removed superflouis interfaces for IO in logical expression (since intgeration not necessary)
 207    *
 208    *Revision 1.1 2005/09/20 13:21:31 holgerlausen
 209    *refactored logical expression API to have simple molecules and compound molecules (RFE 1290043)
 210    *
 211    */