source: osm/applications/editors/josm/plugins/opendata/includes/org/jopendocument/util/Tuple2.java

Last change on this file was 36483, checked in by stoecker, 4 months ago

set eol-style, fix checkstyle issues, add ignores

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2008 jOpenDocument, by ILM Informatique. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of the GNU
7 * General Public License Version 3 only ("GPL").
8 * You may not use this file except in compliance with the License.
9 * You can obtain a copy of the License at http://www.gnu.org/licenses/gpl-3.0.html
10 * See the License for the specific language governing permissions and limitations under the License.
11 *
12 * When distributing the software, include this License Header Notice in each file.
13 *
14 */
15
16package org.jopendocument.util;
17
18import java.util.Arrays;
19import java.util.List;
20
21/**
22 * A simple class to hold 2 values in a type-safe manner.
23 *
24 * @author Sylvain
25 *
26 * @param <A> type of first value.
27 * @param <B> type of second value.
28 */
29public class Tuple2<A, B> {
30
31 // just to make the code shorter
32 public static final <A, B> Tuple2<A, B> create(A a, B b) {
33 return new Tuple2<>(a, b);
34 }
35
36 private final A a;
37 private final B b;
38
39 public Tuple2(A a, B b) {
40 super();
41 this.a = a;
42 this.b = b;
43 }
44
45 public final A get0() {
46 return this.a;
47 }
48
49 public final B get1() {
50 return this.b;
51 }
52
53 public List<Object> asList() {
54 return Arrays.asList(get0(), get1());
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59 if (obj instanceof Tuple2) {
60 final Tuple2<?, ?> o = (Tuple2<?, ?>) obj;
61 return this.asList().equals(o.asList());
62 } else
63 return false;
64 }
65
66 @Override
67 public int hashCode() {
68 return this.asList().hashCode();
69 }
70
71 @Override
72 public String toString() {
73 return getClass().getSimpleName() + " " + this.asList();
74 }
75}
Note: See TracBrowser for help on using the repository browser.