Skip to content

Commit 137d7cc

Browse files
committed
DATACMNS-818 - Renamed Tuple to Pair.
Got rid off manual implementation code in favor of Lombok annotations.
1 parent 036f718 commit 137d7cc

File tree

3 files changed

+82
-126
lines changed

3 files changed

+82
-126
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2015-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.util;
17+
18+
import lombok.AccessLevel;
19+
import lombok.EqualsAndHashCode;
20+
import lombok.NonNull;
21+
import lombok.RequiredArgsConstructor;
22+
import lombok.ToString;
23+
24+
/**
25+
* A tuple of things.
26+
*
27+
* @author Tobias Trelle
28+
* @author Oliver Gierke
29+
* @param <T> Type of the first thing.
30+
* @param <S> Type of the second thing.
31+
* @since 1.12
32+
*/
33+
@ToString
34+
@EqualsAndHashCode
35+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
36+
public final class Pair<S, T> {
37+
38+
private final @NonNull S first;
39+
private final @NonNull T second;
40+
41+
/**
42+
* Creates a new {@link Pair} for the given elements.
43+
*
44+
* @param first must not be {@literal null}.
45+
* @param second must not be {@literal null}.
46+
* @return
47+
*/
48+
public static <S, T> Pair<S, T> of(S first, T second) {
49+
return new Pair<S, T>(first, second);
50+
}
51+
52+
/**
53+
* Returns the first element of the {@link Pair}.
54+
*
55+
* @return
56+
*/
57+
public S getFirst() {
58+
return first;
59+
}
60+
61+
/**
62+
* Returns the second element of the {@link Pair}.
63+
*
64+
* @return
65+
*/
66+
public T getSecond() {
67+
return second;
68+
}
69+
}

src/main/java/org/springframework/data/util/Tuple.java

Lines changed: 0 additions & 113 deletions
This file was deleted.

src/test/java/org/springframework/data/util/TupleUnitTests.java renamed to src/test/java/org/springframework/data/util/PairUnitTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,38 +21,38 @@
2121
import org.junit.Test;
2222

2323
/**
24-
* Unit tests for {@link Tuple}.
24+
* Unit tests for {@link Pair}.
2525
*
2626
* @author Oliver Gierke
2727
*/
28-
public class TupleUnitTests {
28+
public class PairUnitTests {
2929

3030
/**
3131
* @see DATACMNS-790
3232
*/
3333
@Test
3434
public void setsUpSimpleInstance() {
3535

36-
Tuple<Integer, Integer> tuple = Tuple.of(1, 2);
36+
Pair<Integer, Integer> pair = Pair.of(1, 2);
3737

38-
assertThat(tuple.getFirst(), is(1));
39-
assertThat(tuple.getSecond(), is(2));
38+
assertThat(pair.getFirst(), is(1));
39+
assertThat(pair.getSecond(), is(2));
4040
}
4141

4242
/**
4343
* @see DATACMNS-790
4444
*/
4545
@Test(expected = IllegalArgumentException.class)
4646
public void rejectsNullFirstElement() {
47-
Tuple.of(null, 1);
47+
Pair.of(null, 1);
4848
}
4949

5050
/**
5151
* @see DATACMNS-790
5252
*/
5353
@Test(expected = IllegalArgumentException.class)
5454
public void rejectsNullSecondElement() {
55-
Tuple.of(1, null);
55+
Pair.of(1, null);
5656
}
5757

5858
/**
@@ -61,8 +61,8 @@ public void rejectsNullSecondElement() {
6161
@Test
6262
public void hasCorrectEquals() {
6363

64-
Tuple<Integer, Integer> first = Tuple.of(1, 2);
65-
Tuple<Integer, Integer> second = Tuple.of(1, 2);
64+
Pair<Integer, Integer> first = Pair.of(1, 2);
65+
Pair<Integer, Integer> second = Pair.of(1, 2);
6666

6767
assertThat(first, is(first));
6868
assertThat(first, is(second));
@@ -75,9 +75,9 @@ public void hasCorrectEquals() {
7575
@Test
7676
public void hasCorrectHashCode() {
7777

78-
Tuple<Integer, Integer> first = Tuple.of(1, 2);
79-
Tuple<Integer, Integer> second = Tuple.of(1, 2);
80-
Tuple<Integer, Integer> third = Tuple.of(2, 2);
78+
Pair<Integer, Integer> first = Pair.of(1, 2);
79+
Pair<Integer, Integer> second = Pair.of(1, 2);
80+
Pair<Integer, Integer> third = Pair.of(2, 2);
8181

8282
assertThat(first.hashCode(), is(second.hashCode()));
8383
assertThat(first.hashCode(), is(not(third.hashCode())));

0 commit comments

Comments
 (0)