Last change
on this file since 3966 was 3719, checked in by bastiK, 13 years ago |
added missing license information
|
-
Property svn:eol-style
set to
native
|
File size:
1.0 KB
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 | import java.util.ArrayList;
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * A pair.
|
---|
7 | */
|
---|
8 | public final class Pair<A,B> {
|
---|
9 | public A a;
|
---|
10 | public B b;
|
---|
11 |
|
---|
12 | public Pair(A a, B b) {
|
---|
13 | this.a = a;
|
---|
14 | this.b = b;
|
---|
15 | }
|
---|
16 |
|
---|
17 | @Override public int hashCode() {
|
---|
18 | return a.hashCode() + b.hashCode();
|
---|
19 | }
|
---|
20 |
|
---|
21 | @Override public boolean equals(Object other) {
|
---|
22 | if (other instanceof Pair<?, ?>) {
|
---|
23 | Pair<?, ?> o = (Pair<?, ?>)other;
|
---|
24 | return a.equals(o.a) && b.equals(o.b);
|
---|
25 | } else
|
---|
26 | return false;
|
---|
27 | }
|
---|
28 |
|
---|
29 | public static <T> ArrayList<T> toArrayList(Pair<T, T> p) {
|
---|
30 | ArrayList<T> l = new ArrayList<T>(2);
|
---|
31 | l.add(p.a);
|
---|
32 | l.add(p.b);
|
---|
33 | return l;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public static <T> Pair<T,T> sort(Pair<T,T> p) {
|
---|
37 | if (p.b.hashCode() < p.a.hashCode()) {
|
---|
38 | T tmp = p.a;
|
---|
39 | p.a = p.b;
|
---|
40 | p.b = tmp;
|
---|
41 | }
|
---|
42 | return p;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public String toString() {
|
---|
47 | return "<"+a+","+b+">";
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.