Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 195   Methods: 11
NCLOC: 96   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ReteTuple.java 50% 79.2% 90.9% 78%
coverage coverage
 1    package org.drools.reteoo;
 2   
 3    /*
 4    * $Id: ReteTuple.java,v 1.66 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   
 45    import org.drools.FactHandle;
 46    import org.drools.NoSuchFactHandleException;
 47    import org.drools.NoSuchFactObjectException;
 48    import org.drools.WorkingMemory;
 49    import org.drools.rule.Declaration;
 50    import org.drools.spi.Tuple;
 51   
 52    /**
 53    * Base Rete-OO <code>Tuple</code> implementation.
 54    *
 55    * @see Tuple
 56    *
 57    * @author <a href="mailto:bob@werken.com">bob mcwhirter </a>
 58    */
 59    class ReteTuple
 60    implements
 61    Tuple,
 62    Serializable
 63    {
 64    // ------------------------------------------------------------
 65    // Instance members
 66    // ------------------------------------------------------------
 67   
 68    private final WorkingMemoryImpl workingMemory;
 69   
 70    private final TupleKey key;
 71   
 72    private FactHandleImpl mostRecentFact;
 73   
 74    private FactHandleImpl leastRecentFact;
 75   
 76    // ------------------------------------------------------------
 77    // Constructors
 78    // ------------------------------------------------------------
 79   
 80  10 ReteTuple( WorkingMemoryImpl workingMemory )
 81    {
 82  10 this.workingMemory = workingMemory;
 83  10 this.key = TupleKey.EMPTY_KEY;
 84    }
 85   
 86  24797 ReteTuple(ReteTuple left,
 87    ReteTuple right)
 88    {
 89  24797 this.workingMemory = left.workingMemory;
 90  24797 this.key = new TupleKey( left.key,
 91    right.key );
 92    }
 93   
 94  1250 ReteTuple( WorkingMemoryImpl workingMemory,
 95    Declaration declaration,
 96    FactHandle handle )
 97    {
 98  1250 this.workingMemory = workingMemory;
 99  1250 this.key = new TupleKey( declaration,
 100    handle );
 101    }
 102   
 103  3 public String toString()
 104    {
 105  3 return "{" + key.getDeclarations( ) + "}";
 106    }
 107   
 108    // ------------------------------------------------------------
 109    // Instance methods
 110    // ------------------------------------------------------------
 111   
 112    /**
 113    * Retrieve the key for this tuple.
 114    *
 115    * @return The key.
 116    */
 117  80381 TupleKey getKey()
 118    {
 119  80381 return this.key;
 120    }
 121   
 122    /**
 123    * Determine if this tuple depends upon a specified object.
 124    *
 125    * @param handle
 126    * The object handle to test.
 127    *
 128    * @return <code>true</code> if this tuple depends upon the specified
 129    * object, otherwise <code>false</code>.
 130    */
 131  6 boolean dependsOn(FactHandle handle)
 132    {
 133  6 return this.key.containsFactHandle( handle );
 134    }
 135   
 136    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 137   
 138    /**
 139    * @see Tuple
 140    */
 141  83444 public Object get(Declaration declaration)
 142    {
 143  83444 FactHandle handle = this.key.get( declaration );
 144  83444 if (handle != null)
 145    {
 146  83444 try
 147    {
 148  83444 return this.workingMemory.getObject( handle );
 149    }
 150    catch ( NoSuchFactObjectException e )
 151    {
 152    }
 153    }
 154   
 155  0 return null;
 156    }
 157   
 158    /**
 159    * @see Tuple
 160    */
 161  361 public FactHandle getFactHandleForObject(Object object)
 162    {
 163  361 try
 164    {
 165  361 return this.workingMemory.getFactHandle( object );
 166    }
 167    catch ( NoSuchFactHandleException e )
 168    {
 169  0 return null;
 170    }
 171    }
 172   
 173  40340 public WorkingMemory getWorkingMemory()
 174    {
 175  40340 return this.workingMemory;
 176    }
 177   
 178  93614 public long getMostRecentFactTimeStamp()
 179    {
 180  93614 if ( this.mostRecentFact == null )
 181    {
 182  5868 this.mostRecentFact = this.key.getMostRecentFact( );
 183    }
 184  93614 return this.mostRecentFact.getRecency( );
 185    }
 186   
 187  0 public long getLeastRecentFactTimeStamp()
 188    {
 189  0 if ( this.leastRecentFact == null )
 190    {
 191  0 this.leastRecentFact = this.key.getLeastRecentFact( );
 192    }
 193  0 return this.leastRecentFact.getRecency( );
 194    }
 195    }