OLD | NEW |
| (Empty) |
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. | |
4 | |
5 package org.chromium.mojo.system; | |
6 | |
7 | |
8 /** | |
9 * A pair of object. | |
10 * | |
11 * @param <F> Type of the first element. | |
12 * @param <S> Type of the second element. | |
13 */ | |
14 public class Pair<F, S> { | |
15 | |
16 public final F first; | |
17 public final S second; | |
18 | |
19 /** | |
20 * Dedicated constructor. | |
21 * | |
22 * @param first the first element of the pair. | |
23 * @param second the second element of the pair. | |
24 */ | |
25 public Pair(F first, S second) { | |
26 this.first = first; | |
27 this.second = second; | |
28 } | |
29 | |
30 /** | |
31 * equals() that handles null values. | |
32 */ | |
33 private boolean equals(Object o1, Object o2) { | |
34 return o1 == null ? o2 == null : o1.equals(o2); | |
35 } | |
36 | |
37 /** | |
38 * @see Object#equals(Object) | |
39 */ | |
40 @Override | |
41 public boolean equals(Object o) { | |
42 if (!(o instanceof Pair)) { | |
43 return false; | |
44 } | |
45 Pair<?, ?> p = (Pair<?, ?>) o; | |
46 return equals(first, p.first) && equals(second, p.second); | |
47 } | |
48 | |
49 /** | |
50 * @see Object#hashCode() | |
51 */ | |
52 @Override | |
53 public int hashCode() { | |
54 return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : se
cond.hashCode()); | |
55 } | |
56 | |
57 /** | |
58 * Helper method for creating a pair. | |
59 * | |
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. | |
63 */ | |
64 public static <A, B> Pair<A, B> create(A a, B b) { | |
65 return new Pair<A, B>(a, b); | |
66 } | |
67 } | |
OLD | NEW |