Skip to content

Commit 5c43b7a

Browse files
committed
Fix compile error.
1 parent e06b883 commit 5c43b7a

File tree

3 files changed

+118
-8
lines changed

3 files changed

+118
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.aliyun.openservices</groupId>
66
<artifactId>ots-public</artifactId>
7-
<version>2.2.4</version>
7+
<version>2.2.5</version>
88
<packaging>jar</packaging>
99
<name>Aliyun Open Services SDK for Java</name>
1010
<url>http://www.aliyun.com</url>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.aliyun.openservices.ots.utils;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* A generic class for pairs.
7+
* @param <T1>
8+
* @param <T2>
9+
*/
10+
public class Pair<T1, T2> implements Serializable
11+
{
12+
protected T1 first = null;
13+
protected T2 second = null;
14+
15+
/**
16+
* Default constructor.
17+
*/
18+
public Pair()
19+
{
20+
}
21+
22+
/**
23+
* Constructor
24+
* @param a operand
25+
* @param b operand
26+
*/
27+
public Pair(T1 a, T2 b)
28+
{
29+
this.first = a;
30+
this.second = b;
31+
}
32+
33+
/**
34+
* Constructs a new pair, inferring the type via the passed arguments
35+
* @param <T1> type for first
36+
* @param <T2> type for second
37+
* @param a first element
38+
* @param b second element
39+
* @return a new pair containing the passed arguments
40+
*/
41+
public static <T1,T2> Pair<T1,T2> newPair(T1 a, T2 b) {
42+
return new Pair<T1,T2>(a, b);
43+
}
44+
45+
/**
46+
* Replace the first element of the pair.
47+
* @param a operand
48+
*/
49+
public void setFirst(T1 a)
50+
{
51+
this.first = a;
52+
}
53+
54+
/**
55+
* Replace the second element of the pair.
56+
* @param b operand
57+
*/
58+
public void setSecond(T2 b)
59+
{
60+
this.second = b;
61+
}
62+
63+
/**
64+
* Return the first element stored in the pair.
65+
* @return T1
66+
*/
67+
public T1 getFirst()
68+
{
69+
return first;
70+
}
71+
72+
/**
73+
* Return the second element stored in the pair.
74+
* @return T2
75+
*/
76+
public T2 getSecond()
77+
{
78+
return second;
79+
}
80+
81+
private static boolean equals(Object x, Object y)
82+
{
83+
return (x == null && y == null) || (x != null && x.equals(y));
84+
}
85+
86+
@Override
87+
@SuppressWarnings("unchecked")
88+
public boolean equals(Object other)
89+
{
90+
return other instanceof Pair && equals(first, ((Pair)other).first) &&
91+
equals(second, ((Pair)other).second);
92+
}
93+
94+
@Override
95+
public int hashCode()
96+
{
97+
if (first == null)
98+
return (second == null) ? 0 : second.hashCode() + 1;
99+
else if (second == null)
100+
return first.hashCode() + 2;
101+
else
102+
return first.hashCode() * 17 + second.hashCode();
103+
}
104+
105+
@Override
106+
public String toString()
107+
{
108+
return "{" + getFirst() + "," + getSecond() + "}";
109+
}
110+
}

src/test/java/examples/OTSPaginationReadSample.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.aliyun.openservices.ots.*;
44
import com.aliyun.openservices.ots.model.*;
5+
import com.aliyun.openservices.ots.utils.Pair;
56
import com.aliyun.openservices.ots.utils.Preconditions;
6-
import javafx.util.Pair;
77

88
import java.util.ArrayList;
99
import java.util.List;
@@ -116,21 +116,21 @@ private static void readByPage(OTSClient client, String tableName) {
116116
endKey.addPrimaryKeyColumn(COLUMN_UID_NAME, PrimaryKeyValue.INF_MAX);
117117
// 读第一页,从范围的offset=33的行开始读起
118118
Pair<List<Row>, RowPrimaryKey> result = readByPage(client, tableName, startKey, endKey, offset, pageSize);
119-
for (Row row : result.getKey()) {
119+
for (Row row : result.getFirst()) {
120120
System.out.println(row.getColumns());
121121
}
122-
System.out.println("Total rows count: " + result.getKey().size());
122+
System.out.println("Total rows count: " + result.getFirst().size());
123123

124124
// 顺序翻页,读完范围内的所有数据
125-
startKey = result.getValue();
125+
startKey = result.getSecond();
126126
while (startKey != null) {
127127
System.out.println("============= start read next page ==============");
128128
result = readByPage(client, tableName, startKey, endKey, 0, pageSize);
129-
for (Row row : result.getKey()) {
129+
for (Row row : result.getFirst()) {
130130
System.out.println(row.getColumns());
131131
}
132-
startKey = result.getValue();
133-
System.out.println("Total rows count: " + result.getKey().size());
132+
startKey = result.getSecond();
133+
System.out.println("Total rows count: " + result.getFirst().size());
134134
}
135135
}
136136

0 commit comments

Comments
 (0)