-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathPair.java
More file actions
51 lines (39 loc) · 1.1 KB
/
Pair.java
File metadata and controls
51 lines (39 loc) · 1.1 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example.task01;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class Pair<T, K> {
private final T first;
private final K second;
private Pair(T first, K second){
this.first = first;
this.second = second;
}
public T getFirst(){
return first;
}
public K getSecond(){
return second;
}
public static <T, K> Pair<T, K> of(T first, K second){
return new Pair<>(first, second);
}
public void ifPresent(BiConsumer<? super T, ? super K> consumer) {
if (first != null && second != null)
consumer.accept(first, second);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Pair)) {
return false;
}
Pair<?, ?> other = (Pair<?, ?>) obj;
return Objects.equals(first, other.first) && Objects.equals(second, other.second);
}
public int hashCode() {
return Objects.hash(first, second);
}
}