Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 203   Methods: 7
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ObjectTypeNode.java 90% 92.9% 85.7% 90.3%
coverage coverage
 1    package org.drools.reteoo;
 2   
 3    /*
 4    * $Id: ObjectTypeNode.java,v 1.29 2005/02/02 00:23:22 mproctor Exp $
 5    *
 6    * Copyright 2001-2003 (C) The Werken Company. All Rights Reserved.
 7    *
 8    * Redistribution and use of this software and associated documentation
 9    * ("Software"), with or without modification, are permitted provided that the
 10    * following conditions are met:
 11    *
 12    * 1. Redistributions of source code must retain copyright statements and
 13    * notices. Redistributions must also contain a copy of this document.
 14    *
 15    * 2. Redistributions in binary form must reproduce the above copyright notice,
 16    * this list of conditions and the following disclaimer in the documentation
 17    * and/or other materials provided with the distribution.
 18    *
 19    * 3. The name "drools" must not be used to endorse or promote products derived
 20    * from this Software without prior written permission of The Werken Company.
 21    * For written permission, please contact bob@werken.com.
 22    *
 23    * 4. Products derived from this Software may not be called "drools" nor may
 24    * "drools" appear in their names without prior written permission of The Werken
 25    * Company. "drools" is a trademark of The Werken Company.
 26    *
 27    * 5. Due credit should be given to The Werken Company. (http://werken.com/)
 28    *
 29    * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
 30    * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 31    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 32    * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
 33    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 34    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 35    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 36    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 37    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 38    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 39    * POSSIBILITY OF SUCH DAMAGE.
 40    *
 41    */
 42   
 43    import java.io.Serializable;
 44    import java.util.ArrayList;
 45    import java.util.Collection;
 46    import java.util.Collections;
 47    import java.util.Iterator;
 48    import java.util.List;
 49   
 50    import org.drools.FactException;
 51    import org.drools.FactHandle;
 52    import org.drools.spi.ObjectType;
 53   
 54    /**
 55    * Filters <code>Objects</code> coming from the <code>Rete</code> using a
 56    * <code>ObjectType</code> semantic module.
 57    *
 58    * <p>
 59    * It receives <code>Objects</code> from the <code>Rete</code>, uses a
 60    * <code>ObjectType</code> instance to determine membership, and propagates
 61    * matching <code>Objects</code> further to all matching
 62    * <code>ParameterNode</code>s.
 63    * </p>
 64    *
 65    * @see ObjectType
 66    * @see ParameterNode
 67    * @see Rete
 68    *
 69    * @author <a href="mailto:bob@eng.werken.com">bob@eng.werken.com </a>
 70    */
 71    class ObjectTypeNode
 72    implements
 73    Serializable
 74    {
 75    // ------------------------------------------------------------
 76    // Instance members
 77    // ------------------------------------------------------------
 78   
 79    /** The <code>ObjectType</code> semantic module. */
 80    private final ObjectType objectType;
 81   
 82    /** The <code>ParameterNode</code> children. */
 83    private final List parameterNodes = new ArrayList( 1 );
 84   
 85    // ------------------------------------------------------------
 86    // Constructors
 87    // ------------------------------------------------------------
 88   
 89    /**
 90    * Construct given a semantic <code>ObjectType</code>.
 91    *
 92    * @param objectType
 93    * The semantic object-type differentiator.
 94    */
 95  110 public ObjectTypeNode( ObjectType objectType )
 96    {
 97  110 this.objectType = objectType;
 98    }
 99   
 100    // ------------------------------------------------------------
 101    // Instance methods
 102    // ------------------------------------------------------------
 103   
 104    /**
 105    * Retrieve the semantic <code>ObjectType</code> differentiator.
 106    *
 107    * @return The semantic <code>ObjectType</code> differentiator.
 108    */
 109  109 public ObjectType getObjectType()
 110    {
 111  109 return this.objectType;
 112    }
 113   
 114    /**
 115    * Add a <code>ParameterNode</code> child to this node.
 116    *
 117    * @param node The <code>ParameterNode</code> child to add.
 118    */
 119  151 void addParameterNode( ParameterNode node )
 120    {
 121  151 if ( !this.parameterNodes.contains( node ) )
 122    {
 123  151 this.parameterNodes.add( node );
 124    }
 125    }
 126   
 127    /**
 128    * Retrieve the <code>Set</code> of <code>ParameterNodes/code>
 129    * children of this node.
 130    *
 131    * @return The <code>Set</code> of <code>ParameterNode</code>
 132    * children.
 133    * TODO: Remove this.
 134    */
 135  1 Collection getParameterNodes()
 136    {
 137  1 return this.parameterNodes;
 138    }
 139   
 140    /**
 141    * Retreive an <code>Iterator</code> over <code>ParameterNode</code>
 142    * children of this node.
 143    *
 144    * @return An <code>Iterator</code> over <code>ParameterNode</code>
 145    * children of this node.
 146    */
 147  0 Iterator getParameterNodeIterator()
 148    {
 149  0 return Collections.unmodifiableList( this.parameterNodes ).iterator( );
 150    }
 151   
 152    /**
 153    * Assert a new fact object into this <code>RuleBase</code> and the
 154    * specified <code>WorkingMemory</code>.
 155    *
 156    * @param handle The fact handle.
 157    * @param object The object to assert.
 158    * @param workingMemory The working memory session.
 159    *
 160    * @throws FactException if an error occurs during assertion.
 161    */
 162  4326 void assertObject( FactHandle handle,
 163    Object object,
 164    WorkingMemoryImpl workingMemory ) throws FactException
 165    {
 166  4326 if ( !this.objectType.matches( object ) )
 167    {
 168  3402 return;
 169    }
 170   
 171  924 for ( int i = 0, size = this.parameterNodes.size( ); i < size; i++ )
 172    {
 173  1245 ( ( ParameterNode ) this.parameterNodes.get( i ) ).assertObject( handle,
 174    object,
 175    workingMemory );
 176    }
 177    }
 178   
 179    /**
 180    * Retract a fact object from this <code>RuleBase</code> and the specified
 181    * <code>WorkingMemory</code>.
 182    *
 183    * @param handle The handle of the fact to retract.
 184    * @param workingMemory The working memory session.
 185    *
 186    * @throws FactException if an error occurs during assertion.
 187    */
 188  1164 void retractObject( FactHandle handle,
 189    WorkingMemoryImpl workingMemory ) throws FactException
 190    {
 191  1164 if ( !this.objectType.matches( workingMemory.getObject( handle ) ) )
 192    {
 193  792 return;
 194    }
 195   
 196   
 197  372 for ( int i = 0, size = this.parameterNodes.size( ); i < size; i++ )
 198    {
 199  667 ( ( ParameterNode ) this.parameterNodes.get( i ) ).retractObject( handle,
 200    workingMemory );
 201    }
 202    }
 203    }