1package org.robolectric.util;
2
3/*
4 * Copyright (C) 2009 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/**
20 * Container to ease passing around a tuple of two objects.
21 *
22 * @param <F> First type.
23 * @param <S> Second type.
24 */
25public class Pair<F, S> {
26  public final F first;
27  public final S second;
28
29  public Pair(F first, S second) {
30    this.first = first;
31    this.second = second;
32  }
33
34  @Override
35  public boolean equals(Object o) {
36    if (!(o instanceof Pair)) {
37      return false;
38    }
39    Pair<?, ?> p = (Pair<?, ?>) o;
40    return equal(p.first, first) && equal(p.second, second);
41  }
42
43  @Override
44  public int hashCode() {
45    return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
46  }
47
48  public static <A, B> Pair <A, B> create(A a, B b) {
49    return new Pair<>(a, b);
50  }
51
52  private static boolean equal(Object a, Object b) {
53    return a == b || (a != null && a.equals(b));
54  }
55}
56