Coverage Report - com.healthmarketscience.jackcess.RowId
 
Classes in this File Line Coverage Branch Coverage Complexity
RowId
94%
15/16
83%
15/18
0
RowId$Type
100%
4/4
N/A
0
 
 1  
 /*
 2  
 Copyright (c) 2007 Health Market Science, Inc.
 3  
 
 4  
 This library is free software; you can redistribute it and/or
 5  
 modify it under the terms of the GNU Lesser General Public
 6  
 License as published by the Free Software Foundation; either
 7  
 version 2.1 of the License, or (at your option) any later version.
 8  
 
 9  
 This library is distributed in the hope that it will be useful,
 10  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  
 Lesser General Public License for more details.
 13  
 
 14  
 You should have received a copy of the GNU Lesser General Public
 15  
 License along with this library; if not, write to the Free Software
 16  
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 17  
 USA
 18  
 
 19  
 You can contact Health Market Science at info@healthmarketscience.com
 20  
 or at the following address:
 21  
 
 22  
 Health Market Science
 23  
 2700 Horizon Drive
 24  
 Suite 200
 25  
 King of Prussia, PA 19406
 26  
 */
 27  
 
 28  
 package com.healthmarketscience.jackcess;
 29  
 
 30  
 import org.apache.commons.lang.builder.CompareToBuilder;
 31  
 
 32  
 
 33  
 /**
 34  
  * Uniquely identifies a row of data within the access database.
 35  
  *
 36  
  * @author James Ahlborn
 37  
  */
 38  7
 public class RowId implements Comparable<RowId>
 39  
 {
 40  
   /** special page number which will sort before any other valid page
 41  
       number */
 42  
   public static final int FIRST_PAGE_NUMBER = -1;
 43  
   /** special page number which will sort after any other valid page
 44  
       number */
 45  
   public static final int LAST_PAGE_NUMBER = -2;
 46  
 
 47  
   /** special row number representing an invalid row number */
 48  
   public static final int INVALID_ROW_NUMBER = -1;
 49  
 
 50  
   /** type attributes for RowIds which simplify comparisons */
 51  4
   public enum Type {
 52  
     /** comparable type indicating this RowId should always compare less than
 53  
         normal RowIds */
 54  1
     ALWAYS_FIRST,
 55  
     /** comparable type indicating this RowId should always compare
 56  
         normally */
 57  1
     NORMAL,
 58  
     /** comparable type indicating this RowId should always compare greater
 59  
         than normal RowIds */
 60  1
     ALWAYS_LAST;
 61  
   }
 62  
   
 63  
   /** special rowId which will sort before any other valid rowId */
 64  1
   public static final RowId FIRST_ROW_ID = new RowId(
 65  
       FIRST_PAGE_NUMBER, INVALID_ROW_NUMBER);
 66  
 
 67  
   /** special rowId which will sort after any other valid rowId */
 68  1
   public static final RowId LAST_ROW_ID = new RowId(
 69  
       LAST_PAGE_NUMBER, INVALID_ROW_NUMBER);
 70  
 
 71  
   private final int _pageNumber;
 72  
   private final int _rowNumber;
 73  
   private final Type _type;
 74  
   
 75  
   /**
 76  
    * Creates a new <code>RowId</code> instance.
 77  
    *
 78  
    */
 79  33638
   public RowId(int pageNumber,int rowNumber) {
 80  33638
     _pageNumber = pageNumber;
 81  33638
     _rowNumber = rowNumber;
 82  33638
     _type = ((_pageNumber == FIRST_PAGE_NUMBER) ? Type.ALWAYS_FIRST :
 83  
              ((_pageNumber == LAST_PAGE_NUMBER) ? Type.ALWAYS_LAST :
 84  
               Type.NORMAL));
 85  33638
   }
 86  
 
 87  
   public int getPageNumber() {
 88  4305466
     return _pageNumber;
 89  
   }
 90  
 
 91  
   public int getRowNumber() {
 92  328067
     return _rowNumber;
 93  
   }
 94  
 
 95  
   /**
 96  
    * Returns {@code true} if this rowId potentially represents an actual row
 97  
    * of data, {@code false} otherwise.
 98  
    */
 99  
   public boolean isValid() {
 100  24775
     return((getRowNumber() >= 0) && (getPageNumber() >= 0));
 101  
   }
 102  
 
 103  
   public Type getType() {
 104  64280
     return _type;
 105  
   }
 106  
   
 107  
   public int compareTo(RowId other) {
 108  26117
     return new CompareToBuilder()
 109  
       .append(getType(), other.getType())
 110  
       .append(getPageNumber(), other.getPageNumber())
 111  
       .append(getRowNumber(), other.getRowNumber())
 112  
       .toComparison();
 113  
   }
 114  
 
 115  
   @Override
 116  
   public int hashCode() {
 117  0
     return getPageNumber() ^ getRowNumber();
 118  
   }
 119  
 
 120  
   @Override
 121  
   public boolean equals(Object o) {
 122  2098102
     return ((this == o) ||
 123  
             ((o != null) && (getClass() == o.getClass()) &&
 124  
              (getPageNumber() == ((RowId)o).getPageNumber()) &&
 125  
              (getRowNumber() == ((RowId)o).getRowNumber())));
 126  
   }
 127  
   
 128  
   @Override
 129  
   public String toString() {
 130  4
     return getPageNumber() + ":" + getRowNumber();
 131  
   }
 132  
   
 133  
 }