Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 177   Methods: 14
NCLOC: 109   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
PrimitiveLongStack.java 25% 42.4% 50% 41.8%
coverage coverage
 1    package org.drools.util;
 2    /*
 3    * $Id: PrimitiveLongStack.java,v 1.6 2004/12/06 01:30:38 dbarnett Exp $
 4    *
 5    * Copyright 2001-2003 (C) The Werken Company. All Rights Reserved.
 6    *
 7    * Redistribution and use of this software and associated documentation
 8    * ("Software"), with or without modification, are permitted provided that the
 9    * following conditions are met:
 10    *
 11    * 1. Redistributions of source code must retain copyright statements and
 12    * notices. Redistributions must also contain a copy of this document.
 13    *
 14    * 2. Redistributions in binary form must reproduce the above copyright notice,
 15    * this list of conditions and the following disclaimer in the documentation
 16    * and/or other materials provided with the distribution.
 17    *
 18    * 3. The name "drools" must not be used to endorse or promote products derived
 19    * from this Software without prior written permission of The Werken Company.
 20    * For written permission, please contact bob@werken.com.
 21    *
 22    * 4. Products derived from this Software may not be called "drools" nor may
 23    * "drools" appear in their names without prior written permission of The Werken
 24    * Company. "drools" is a trademark of The Werken Company.
 25    *
 26    * 5. Due credit should be given to The Werken Company. (http://werken.com/)
 27    *
 28    * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
 29    * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 30    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 31    * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
 32    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 33    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 34    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 35    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 36    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 37    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 38    * POSSIBILITY OF SUCH DAMAGE.
 39    *
 40    */
 41   
 42    import java.io.Serializable;
 43   
 44    public class PrimitiveLongStack
 45    implements
 46    Serializable
 47    {
 48    private final int tableSize;
 49    private int currentPageId;
 50    private Page currentPage;
 51   
 52  71 public PrimitiveLongStack()
 53    {
 54  71 this( 256 );
 55    }
 56   
 57  71 public PrimitiveLongStack(int tableSize)
 58    {
 59  71 this.tableSize = tableSize;
 60  71 this.currentPageId = 0;
 61   
 62    // instantiate the first node
 63    // previous sibling of first node is null
 64    // next sibling of last node is null
 65  71 this.currentPage = new Page( null,
 66    this.currentPageId,
 67    this.tableSize );
 68    }
 69   
 70  54 public void push(long value)
 71    {
 72  54 if ( this.currentPage.getPosition( ) == this.tableSize - 1 )
 73    {
 74   
 75  0 Page node = new Page( this.currentPage,
 76    ++this.currentPageId,
 77    this.tableSize );
 78  0 this.currentPage = node;
 79    }
 80   
 81  54 this.currentPage.push( value );
 82    }
 83   
 84  0 public long pop()
 85    {
 86  0 if ( this.currentPage.getPosition( ) == -1 )
 87    {
 88  0 if ( this.currentPageId == 0 )
 89    {
 90  0 throw new RuntimeException( "Unable to pop" );
 91    }
 92   
 93  0 Page node = this.currentPage;
 94  0 this.currentPage = node.getPreviousSibling( );
 95  0 this.currentPageId--;
 96  0 node.remove( );
 97   
 98    }
 99   
 100  0 return this.currentPage.pop( );
 101    }
 102   
 103  872 public boolean isEmpty()
 104    {
 105  872 return this.currentPageId == 0 && this.currentPage.getPosition( ) == -1;
 106    }
 107   
 108    private static final class Page
 109    implements
 110    Serializable
 111    {
 112    private final int pageId;
 113    private Page nextSibling;
 114    private Page previousSibling;
 115    private long[] table;
 116    private int lastKey;
 117   
 118  71 Page(Page previousSibling,
 119    int nodeId,
 120    int tableSize)
 121    {
 122    // create bi-directional link
 123  71 this.previousSibling = previousSibling;
 124  71 if ( this.previousSibling != null )
 125    {
 126  0 this.previousSibling.setNextSibling( this );
 127    }
 128  71 this.pageId = nodeId;
 129  71 lastKey = -1;
 130   
 131    // initiate tree;
 132  71 this.table = new long[tableSize];
 133    }
 134   
 135  0 public int getNodeId()
 136    {
 137  0 return this.pageId;
 138    }
 139   
 140  0 void setNextSibling(Page nextSibling)
 141    {
 142  0 this.nextSibling = nextSibling;
 143    }
 144   
 145  0 public Page getNextSibling()
 146    {
 147  0 return this.nextSibling;
 148    }
 149   
 150  0 public Page getPreviousSibling()
 151    {
 152  0 return this.previousSibling;
 153    }
 154   
 155  0 public long pop()
 156    {
 157  0 return this.table[this.lastKey--];
 158    }
 159   
 160  54 public void push(long value)
 161    {
 162  54 this.table[++this.lastKey] = value;
 163    }
 164   
 165  926 public int getPosition()
 166    {
 167  926 return this.lastKey;
 168    }
 169   
 170  0 void remove()
 171    {
 172  0 previousSibling.setNextSibling( null );
 173  0 this.previousSibling = null;
 174  0 this.table = null;
 175    }
 176    }
 177    }