Last change
on this file since 2575 was 1169, checked in by stoecker, 15 years ago |
removed usage of tab stops
|
-
Property svn:eol-style
set to
native
|
File size:
881 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 o) {
|
---|
21 | return o == null ? o == null : o instanceof Pair
|
---|
22 | && a.equals(((Pair<?,?>) o).a) && b.equals(((Pair<?,?>) o).b);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public static <T> ArrayList<T> toArrayList(Pair<T, T> p) {
|
---|
26 | ArrayList<T> l = new ArrayList<T>(2);
|
---|
27 | l.add(p.a);
|
---|
28 | l.add(p.b);
|
---|
29 | return l;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public static <T> Pair<T,T> sort(Pair<T,T> p) {
|
---|
33 | if (p.b.hashCode() < p.a.hashCode()) {
|
---|
34 | T tmp = p.a;
|
---|
35 | p.a = p.b;
|
---|
36 | p.b = tmp;
|
---|
37 | }
|
---|
38 | return p;
|
---|
39 | }
|
---|
40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.