source: osm/applications/editors/josm/plugins/surveyor/src/org/dinopolis/util/collection/Tuple.java@ 13497

Last change on this file since 13497 was 13497, checked in by skela, 16 years ago

applications/editors/josm: Set svn:eol-style native on all *.java files
in plugins. Normalize the eol-style in
plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringEnumConfigurer.java.

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/**
2 * Copyright by Christof Dallermassl
3 * This program is free software and licensed under GPL.
4 */
5package org.dinopolis.util.collection;
6
7import java.util.Map;
8
9/**
10 * Simple implementation of a tuple (two objects).
11 *
12 * @author cdaller
13 *
14 */
15public class Tuple<T1 extends Object, T2 extends Object> implements Map.Entry<T1, T2>{
16 T1 first;
17 T2 second;
18
19 /**
20 * Default Constructor
21 */
22 public Tuple() {
23 }
24
25 /**
26 * Constructor filling the values.
27 * @param first the first value.
28 * @param second the second value.
29 */
30 public Tuple(T1 one, T2 two) {
31 this.first = one;
32 this.second = two;
33 }
34
35 /**
36 * @return the first
37 */
38 public T1 getFirst() {
39 return this.first;
40 }
41
42 /**
43 * @param first the first to set
44 */
45 public void setFirst(T1 first) {
46 this.first = first;
47 }
48
49 /**
50 * @return the second
51 */
52 public T2 getSecond() {
53 return this.second;
54 }
55
56 /**
57 * @param second the second to set
58 */
59 public T2 setSecond(T2 second) {
60 T2 oldValue = this.second;
61 this.second = second;
62 return oldValue;
63 }
64
65 /* (non-Javadoc)
66 * @see java.util.Map.Entry#getKey()
67 */
68 //@Override
69 public T1 getKey() {
70 return getFirst();
71 }
72
73 /* (non-Javadoc)
74 * @see java.util.Map.Entry#getValue()
75 */
76 //@Override
77 public T2 getValue() {
78 return getSecond();
79 }
80
81 /* (non-Javadoc)
82 * @see java.util.Map.Entry#setValue(java.lang.Object)
83 */
84 //@Override
85 public T2 setValue(T2 value) {
86 return setSecond(value);
87 }
88
89 /* (non-Javadoc)
90 * @see java.lang.Object#hashCode()
91 */
92 @Override
93 public int hashCode() {
94 final int prime = 31;
95 int result = 1;
96 result = prime * result + ((this.first == null) ? 0 : this.first.hashCode());
97 result = prime * result + ((this.second == null) ? 0 : this.second.hashCode());
98 return result;
99 }
100
101 /* (non-Javadoc)
102 * @see java.lang.Object#equals(java.lang.Object)
103 */
104 @SuppressWarnings("unchecked")
105 @Override
106 public boolean equals(Object obj) {
107 if (this == obj)
108 return true;
109 if (obj == null)
110 return false;
111 if (getClass() != obj.getClass())
112 return false;
113 final Tuple other = (Tuple) obj;
114 if (this.first == null) {
115 if (other.first != null)
116 return false;
117 } else if (!this.first.equals(other.first))
118 return false;
119 if (this.second == null) {
120 if (other.second != null)
121 return false;
122 } else if (!this.second.equals(other.second))
123 return false;
124 return true;
125 }
126
127 /* (non-Javadoc)
128 * @see java.lang.Object#toString()
129 */
130 public String toString() {
131 return "[" + first + "=" + second + "]";
132 }
133}
Note: See TracBrowser for help on using the repository browser.