1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.mojo.system;
11 * @param <F> Type of the first element.
12 * @param <S> Type of the second element.
14 public class Pair<F, S> {
17 public final S second;
20 * Dedicated constructor.
22 * @param first the first element of the pair.
23 * @param second the second element of the pair.
25 public Pair(F first, S second) {
31 * equals() that handles null values.
33 private boolean equals(Object o1, Object o2) {
34 return o1 == null ? o2 == null : o1.equals(o2);
38 * @see Object#equals(Object)
41 public boolean equals(Object o) {
42 if (!(o instanceof Pair)) {
45 Pair<?, ?> p = (Pair<?, ?>) o;
46 return equals(first, p.first) && equals(second, p.second);
50 * @see Object#hashCode()
53 public int hashCode() {
54 return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
58 * Helper method for creating a pair.
60 * @param a the first element of the pair.
61 * @param b the second element of the pair.
62 * @return the pair containing a and b.
64 public static <A, B> Pair<A, B> create(A a, B b) {
65 return new Pair<A, B>(a, b);