| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
package com.healthmarketscience.jackcess; |
| 29 | |
|
| 30 | |
import org.apache.commons.lang.builder.CompareToBuilder; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 7 | public class RowId implements Comparable<RowId> |
| 39 | |
{ |
| 40 | |
|
| 41 | |
|
| 42 | |
public static final int FIRST_PAGE_NUMBER = -1; |
| 43 | |
|
| 44 | |
|
| 45 | |
public static final int LAST_PAGE_NUMBER = -2; |
| 46 | |
|
| 47 | |
|
| 48 | |
public static final int INVALID_ROW_NUMBER = -1; |
| 49 | |
|
| 50 | |
|
| 51 | 4 | public enum Type { |
| 52 | |
|
| 53 | |
|
| 54 | 1 | ALWAYS_FIRST, |
| 55 | |
|
| 56 | |
|
| 57 | 1 | NORMAL, |
| 58 | |
|
| 59 | |
|
| 60 | 1 | ALWAYS_LAST; |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | 1 | public static final RowId FIRST_ROW_ID = new RowId( |
| 65 | |
FIRST_PAGE_NUMBER, INVALID_ROW_NUMBER); |
| 66 | |
|
| 67 | |
|
| 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 | |
|
| 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 | |
|
| 97 | |
|
| 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 | |
} |