| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.bulenkov.iconloader.util; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public class Pair<FIRST, SECOND> { |
| 23 |
public final FIRST first; |
| 24 |
public final SECOND second; |
| 25 |
|
| 26 |
@SuppressWarnings("unchecked") |
| 27 |
private static final Pair EMPTY = create(null, null); |
| 28 |
|
| 29 |
@SuppressWarnings("unchecked") |
| 30 |
public static <F, S> Pair<F, S> empty() { |
| 31 |
return EMPTY; |
| 32 |
} |
| 33 |
|
| 34 |
public Pair(FIRST first, SECOND second) { |
| 35 |
this.first = first; |
| 36 |
this.second = second; |
| 37 |
} |
| 38 |
|
| 39 |
public final FIRST getFirst() { |
| 40 |
return first; |
| 41 |
} |
| 42 |
|
| 43 |
public final SECOND getSecond() { |
| 44 |
return second; |
| 45 |
} |
| 46 |
|
| 47 |
public final boolean equals(Object o) { |
| 48 |
return o instanceof Pair |
| 49 |
&& ComparingUtils.equal(first, ((Pair) o).first) |
| 50 |
&& ComparingUtils.equal(second, ((Pair) o).second); |
| 51 |
} |
| 52 |
|
| 53 |
public int hashCode() { |
| 54 |
int result = first != null ? first.hashCode() : 0; |
| 55 |
result = 31 * result + (second != null ? second.hashCode() : 0); |
| 56 |
return result; |
| 57 |
} |
| 58 |
|
| 59 |
public String toString() { |
| 60 |
return "<" + first + ", " + second + ">"; |
| 61 |
} |
| 62 |
|
| 63 |
public static <F, S> Pair<F, S> create(F first, S second) { |
| 64 |
return new Pair<F, S>(first, second); |
| 65 |
} |
| 66 |
|
| 67 |
public static <T> T getFirst(Pair<T, ?> pair) { |
| 68 |
return pair != null ? pair.first : null; |
| 69 |
} |
| 70 |
|
| 71 |
public static <T> T getSecond(Pair<?, T> pair) { |
| 72 |
return pair != null ? pair.second : null; |
| 73 |
} |
| 74 |
} |