Java Reference
In-Depth Information
Display 14.5
A Generic Ordered Pair Class (part 2 of 2)
12
first = firstItem;
13
second = secondItem;
14
}
15
public void setFirst(T newFirst)
16
{
17
first = newFirst;
18
}
19
public void setSecond(T newSecond)
20
{
21
second = newSecond;
22
}
23
public T getFirst()
24
{
25
return first;
26
}
27
public T getSecond()
28
{
29
return second;
30
}
31
public String toString()
32
{
33
return ( "first: " + first.toString() + "\n"
34
+ "second: " + second.toString() );
35
}
36
37
public boolean equals(Object otherObject)
38
{
39
if (otherObject == null )
40
return false ;
41
else if (getClass() != otherObject.getClass())
42
return false ;
43
else
44
{
45
Pair<T> otherPair = (Pair<T>)otherObject;
46
return (first.equals(otherPair.first)
47
&& second.equals(otherPair.second));
48
}
49
}
50
}
 
Search WWH ::




Custom Search