Last change
on this file since 2646 was 2626, checked in by jttt, 14 years ago |
Fixed some of the warnings found by FindBugs
|
-
Property svn:eol-style
set to
native
|
File size:
934 bytes
|
Line | |
---|
1 | package org.openstreetmap.josm.tools;
|
---|
2 | import java.util.ArrayList;
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * A pair.
|
---|
6 | */
|
---|
7 | public final class Pair<A,B> {
|
---|
8 | public A a;
|
---|
9 | public B b;
|
---|
10 |
|
---|
11 | public Pair(A a, B b) {
|
---|
12 | this.a = a;
|
---|
13 | this.b = b;
|
---|
14 | }
|
---|
15 |
|
---|
16 | @Override public int hashCode() {
|
---|
17 | return a.hashCode() ^ b.hashCode();
|
---|
18 | }
|
---|
19 |
|
---|
20 | @Override public boolean equals(Object other) {
|
---|
21 | if (other instanceof Pair<?, ?>) {
|
---|
22 | Pair<?, ?> o = (Pair<?, ?>)other;
|
---|
23 | return a.equals(o.a) && b.equals(o.b);
|
---|
24 | } else
|
---|
25 | return false;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public static <T> ArrayList<T> toArrayList(Pair<T, T> p) {
|
---|
29 | ArrayList<T> l = new ArrayList<T>(2);
|
---|
30 | l.add(p.a);
|
---|
31 | l.add(p.b);
|
---|
32 | return l;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static <T> Pair<T,T> sort(Pair<T,T> p) {
|
---|
36 | if (p.b.hashCode() < p.a.hashCode()) {
|
---|
37 | T tmp = p.a;
|
---|
38 | p.a = p.b;
|
---|
39 | p.b = tmp;
|
---|
40 | }
|
---|
41 | return p;
|
---|
42 | }
|
---|
43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.