1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.healthmarketscience.jackcess.impl;
18
19 import java.io.Serializable;
20
21 import com.healthmarketscience.jackcess.RowId;
22 import org.apache.commons.lang3.builder.CompareToBuilder;
23
24
25
26
27
28
29
30 public class RowIdImpl implements RowId, Serializable
31 {
32 private static final long serialVersionUID = 20131014L;
33
34
35
36 public static final int FIRST_PAGE_NUMBER = -1;
37
38
39 public static final int LAST_PAGE_NUMBER = -2;
40
41
42 public static final int INVALID_ROW_NUMBER = -1;
43
44
45 public enum Type {
46
47
48 ALWAYS_FIRST,
49
50
51 NORMAL,
52
53
54 ALWAYS_LAST;
55 }
56
57
58 public static final RowIdImpl/RowIdImpl.html#RowIdImpl">RowIdImpl FIRST_ROW_ID = new RowIdImpl(
59 FIRST_PAGE_NUMBER, INVALID_ROW_NUMBER);
60
61
62 public static final RowIdImpll/RowIdImpl.html#RowIdImpl">RowIdImpl LAST_ROW_ID = new RowIdImpl(
63 LAST_PAGE_NUMBER, INVALID_ROW_NUMBER);
64
65 private final int _pageNumber;
66 private final int _rowNumber;
67 private final Type _type;
68
69
70
71
72
73 public RowIdImpl(int pageNumber,int rowNumber) {
74 _pageNumber = pageNumber;
75 _rowNumber = rowNumber;
76 _type = ((_pageNumber == FIRST_PAGE_NUMBER) ? Type.ALWAYS_FIRST :
77 ((_pageNumber == LAST_PAGE_NUMBER) ? Type.ALWAYS_LAST :
78 Type.NORMAL));
79 }
80
81 public int getPageNumber() {
82 return _pageNumber;
83 }
84
85 public int getRowNumber() {
86 return _rowNumber;
87 }
88
89
90
91
92
93 public boolean isValid() {
94 return((getRowNumber() >= 0) && (getPageNumber() >= 0));
95 }
96
97 public Type getType() {
98 return _type;
99 }
100
101 @Override
102 public int compareTo(RowId other) {
103 return compareTo((RowIdImpl)other);
104 }
105
106 public int compareTo(RowIdImpl other) {
107 return new CompareToBuilder()
108 .append(getType(), other.getType())
109 .append(getPageNumber(), other.getPageNumber())
110 .append(getRowNumber(), other.getRowNumber())
111 .toComparison();
112 }
113
114 @Override
115 public int hashCode() {
116 return getPageNumber() ^ getRowNumber();
117 }
118
119 @Override
120 public boolean equals(Object o) {
121 return ((this == o) ||
122 ((o != null) && (getClass() == o.getClass()) &&
123 (getPageNumber() == ((RowIdImpl)o).getPageNumber()) &&
124 (getRowNumber() == ((RowIdImpl)o).getRowNumber())));
125 }
126
127 @Override
128 public String toString() {
129 return getPageNumber() + ":" + getRowNumber();
130 }
131
132 }