Debian Codegraph @

src/com/bulenkov/iconloader/util/Pair.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2014 JetBrains s.r.o.
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
17 package com.bulenkov.iconloader.util;
18
19 /**
20 * @author Konstantin Bulenkov
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 }