Clover coverage report - ActiveIO - 1.0
Coverage timestamp: Fri Apr 22 2005 14:27:22 PDT
file stats: LOC: 167   Methods: 19
NCLOC: 93   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
LogFileNode.java 41.7% 60.5% 78.9% 62.2%
coverage coverage
 1   
 /**
 2   
  *
 3   
  * Copyright 2004 Hiram Chirino
 4   
  *
 5   
  * Licensed under the Apache License, Version 2.0 (the "License");
 6   
  * you may not use this file except in compliance with the License.
 7   
  * You may obtain a copy of the License at
 8   
  *
 9   
  * http://www.apache.org/licenses/LICENSE-2.0
 10   
  *
 11   
  * Unless required by applicable law or agreed to in writing, software
 12   
  * distributed under the License is distributed on an "AS IS" BASIS,
 13   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14   
  * See the License for the specific language governing permissions and
 15   
  * limitations under the License.
 16   
  *
 17   
  **/
 18   
 package org.activeio.journal.active;
 19   
 
 20   
 import java.io.DataInput;
 21   
 import java.io.DataOutput;
 22   
 import java.io.IOException;
 23   
 
 24   
 /**
 25   
  * @version $Revision: 1.1 $
 26   
  */
 27   
 final class LogFileNode {
 28   
     
 29   
     static final public int SERIALIZED_SIZE = 10;
 30   
 
 31   
     private final LogFile logFile;    
 32   
     private LogFileNode next;
 33   
 
 34   
     /** The id of the log file. */
 35   
     private int id;
 36   
     /** Does it have live records in it? */
 37   
     private boolean active = false;
 38   
     /** Is the log file in readonly mode */
 39   
     private boolean readOnly;
 40   
     /** The location of the next append offset */
 41   
     private int appendOffset = 0;
 42   
 
 43  40
     public LogFileNode(LogFile logFile) {
 44  40
         this.logFile = logFile;
 45   
     }
 46   
 
 47  112
     public LogFile getLogFile() {
 48  112
         return logFile;
 49   
     }
 50   
 
 51   
     /////////////////////////////////////////////////////////////
 52   
     //
 53   
     // Method used to mange the state of the log file.
 54   
     //
 55   
     /////////////////////////////////////////////////////////////
 56   
 
 57  16
     public void activate(int id) {
 58  16
         if (active)
 59  0
             throw new IllegalStateException("Log allready active.");
 60   
 
 61  16
         this.id = id;
 62  16
         this.readOnly = false;
 63  16
         this.active = true;
 64  16
         this.appendOffset = 0;
 65   
     }
 66   
 
 67  72
     public int getId() {
 68  72
         return id;
 69   
     }
 70   
 
 71  6
     public void setReadOnly(boolean enable) {
 72  6
         if (!active)
 73  0
             throw new IllegalStateException("Log not active.");
 74  6
         this.readOnly = enable;
 75   
     }
 76   
 
 77  0
     public void reinitialize() throws IOException {
 78  0
         if (active)
 79  0
             throw new IllegalStateException("Cannot reinitialize an active log.");
 80   
         
 81  0
         this.id = -1;
 82  0
         this.readOnly = true;
 83  0
         this.appendOffset = 0;
 84  0
         getLogFile().resize();
 85   
     }
 86   
 
 87  78
     public boolean isActive() {
 88  78
         return active;
 89   
     }
 90   
 
 91  0
     public void setActive(boolean enable) {
 92  0
         active = enable;
 93   
     }
 94   
 
 95  104
     public int getAppendOffset() {
 96  104
         return appendOffset;
 97   
     }
 98   
 
 99   
 
 100  0
     public Location getFirstRecordLocation() {
 101  0
         if (isActive() && appendOffset > 0)
 102  0
             return new Location(getId(), 0);
 103  0
         return null;
 104   
     }
 105   
 
 106  20
     public boolean isReadOnly() {
 107  20
         return readOnly;
 108   
     }
 109   
 
 110  20
     public void appended(int i) {
 111  20
         appendOffset += i;
 112   
     }
 113   
     
 114   
     /////////////////////////////////////////////////////////////
 115   
     //
 116   
     // Method used to maitain the list of LogFileNodes used by 
 117   
     // the LogFileManager
 118   
     //
 119   
     /////////////////////////////////////////////////////////////
 120   
     
 121  216
     public LogFileNode getNext() {
 122  216
         return next;
 123   
     }
 124   
 
 125  40
     public void setNext(LogFileNode state) {
 126  40
         next = state;
 127   
     }
 128   
 
 129  2
     public LogFileNode getNextActive() {
 130  2
         if (getNext().isActive())
 131  0
             return getNext();
 132  2
         return null;
 133   
     }
 134   
 
 135  16
     public LogFileNode getNextInactive() {
 136  16
         if (!getNext().isActive())
 137  14
             return getNext();
 138  2
         return null;
 139   
     }
 140   
     
 141   
     /**
 142   
      * @param data
 143   
      * @throws IOException 
 144   
      */
 145  144
     public void writeExternal(DataOutput data) throws IOException {
 146  144
         data.writeInt(id);
 147  144
         data.writeBoolean(active);
 148  144
         data.writeBoolean(readOnly);
 149  144
         data.writeInt(appendOffset);
 150   
     }
 151   
 
 152   
     /**
 153   
      * @param data
 154   
      * @throws IOException 
 155   
      */
 156  0
     public void readExternal(DataInput data) throws IOException {
 157  0
         id = data.readInt();
 158  0
         active = data.readBoolean();
 159  0
         readOnly = data.readBoolean();
 160  0
         appendOffset = data.readInt();
 161   
     }
 162   
 
 163  10
     public void setAppendOffset(int offset) {
 164  10
         appendOffset = offset;
 165   
     }
 166   
 
 167   
 }