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 import java.util.Comparator;
21
22 import com.healthmarketscience.jackcess.RowId;
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 static final Comparator<RowIdImpl> COMPARATOR =
66 Comparator.comparing(RowIdImpl::getType)
67 .thenComparing(RowIdImpl::getPageNumber)
68 .thenComparing(RowIdImpl::getRowNumber);
69
70 private final int _pageNumber;
71 private final int _rowNumber;
72 private final Type _type;
73
74
75
76
77
78 public RowIdImpl(int pageNumber,int rowNumber) {
79 _pageNumber = pageNumber;
80 _rowNumber = rowNumber;
81 _type = ((_pageNumber == FIRST_PAGE_NUMBER) ? Type.ALWAYS_FIRST :
82 ((_pageNumber == LAST_PAGE_NUMBER) ? Type.ALWAYS_LAST :
83 Type.NORMAL));
84 }
85
86 public int getPageNumber() {
87 return _pageNumber;
88 }
89
90 public int getRowNumber() {
91 return _rowNumber;
92 }
93
94
95
96
97
98 public boolean isValid() {
99 return((getRowNumber() >= 0) && (getPageNumber() >= 0));
100 }
101
102 public Type getType() {
103 return _type;
104 }
105
106 @Override
107 public int compareTo(RowId other) {
108 return compareTo((RowIdImpl)other);
109 }
110
111 public int compareTo(RowIdImpl other) {
112 return COMPARATOR.compare(this, other);
113 }
114
115 @Override
116 public int hashCode() {
117 return getPageNumber() ^ getRowNumber();
118 }
119
120 @Override
121 public boolean equals(Object o) {
122 return ((this == o) ||
123 ((o != null) && (getClass() == o.getClass()) &&
124 (getPageNumber() == ((RowIdImpl)o).getPageNumber()) &&
125 (getRowNumber() == ((RowIdImpl)o).getRowNumber())));
126 }
127
128 @Override
129 public String toString() {
130 return getPageNumber() + ":" + getRowNumber();
131 }
132
133 }