1 /* |
1 /* |
2 * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javac.util; |
26 package com.sun.tools.javac.util; |
27 |
27 |
|
28 import java.util.Objects; |
|
29 |
28 /** A generic class for pairs. |
30 /** A generic class for pairs. |
29 * |
31 * |
30 * <p><b>This is NOT part of any supported API. |
32 * <p><b>This is NOT part of any supported API. |
31 * If you write code that depends on this, you do so at your own risk. |
33 * If you write code that depends on this, you do so at your own risk. |
32 * This code and its internal interfaces are subject to change or |
34 * This code and its internal interfaces are subject to change or |
44 |
46 |
45 public String toString() { |
47 public String toString() { |
46 return "Pair[" + fst + "," + snd + "]"; |
48 return "Pair[" + fst + "," + snd + "]"; |
47 } |
49 } |
48 |
50 |
49 private static boolean equals(Object x, Object y) { |
|
50 return (x == null && y == null) || (x != null && x.equals(y)); |
|
51 } |
|
52 |
|
53 public boolean equals(Object other) { |
51 public boolean equals(Object other) { |
54 return |
52 return |
55 other instanceof Pair<?,?> && |
53 other instanceof Pair<?,?> && |
56 equals(fst, ((Pair<?,?>)other).fst) && |
54 Objects.equals(fst, ((Pair<?,?>)other).fst) && |
57 equals(snd, ((Pair<?,?>)other).snd); |
55 Objects.equals(snd, ((Pair<?,?>)other).snd); |
58 } |
56 } |
59 |
57 |
60 public int hashCode() { |
58 public int hashCode() { |
61 if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1; |
59 if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1; |
62 else if (snd == null) return fst.hashCode() + 2; |
60 else if (snd == null) return fst.hashCode() + 2; |