source: josm/trunk/src/org/openstreetmap/josm/tools/Pair.java @ 5241

Revision 4272, 1.2 KB checked in by bastiK, 10 months ago (diff)

mapcss: proper support for scaled icons (fixes #6560)

  • Property svn:eol-style set to native
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3import java.util.ArrayList;
4
5/**
6 * A pair.
7 */
8public 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    /* convenience constructor method */
51    public static <U,V> Pair<U,V> create(U u, V v) {
52        return new Pair<U,V>(u,v);
53    }
54}
Note: See TracBrowser for help on using the repository browser.