Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2003, the JUNG Project and the Regents of the University | |
3 | * of California | |
4 | * All rights reserved. | |
5 | * | |
6 | * This software is open-source under the BSD license; see either | |
7 | * "license.txt" or | |
8 | * http://jung.sourceforge.net/license.txt for a description. | |
9 | */ | |
10 | package edu.uci.ics.jung.utils; | |
11 | ||
12 | import edu.uci.ics.jung.exceptions.FatalException; | |
13 | ||
14 | /** | |
15 | * Stores a pair of values together. Access either one by directly | |
16 | * getting the fields. Pairs are not mutable, respect <tt>equals</tt> | |
17 | * and may be used as indices.<p> | |
18 | * Note that they do not protect from malevolent behavior: if one or another | |
19 | * object in the tuple is mutable, then that can be changed with the usual bad | |
20 | * effects. | |
21 | * | |
22 | * @author scott white and Danyel Fisher | |
23 | */ | |
24 | final public class Pair { | |
25 | private final Object value1; | |
26 | private final Object value2; | |
27 | ||
28 | 315468 | public Pair(Object value1, Object value2) { |
29 | 315468 | if ( value1 == null || value2 == null) |
30 | 0 | throw new FatalException("A Pair can't hold nulls."); |
31 | 315468 | this.value1 = value1; |
32 | 315468 | this.value2 = value2; |
33 | 315468 | } |
34 | ||
35 | public Object getFirst() { | |
36 | 2119190 | return value1; |
37 | } | |
38 | public Object getSecond() { | |
39 | 272895 | return value2; |
40 | } | |
41 | ||
42 | public boolean equals( Object o ) { | |
43 | 100 | if (o instanceof Pair) { |
44 | 100 | Pair tt = (Pair) o; |
45 | 100 | Object first = tt.getFirst(); |
46 | 100 | Object second = tt.getSecond(); |
47 | 100 | return ((first == value1 || first.equals(value1)) && |
48 | (second == value2 || second.equals(value2))); | |
49 | } else { | |
50 | 0 | return false; |
51 | } | |
52 | } | |
53 | ||
54 | public int hashCode() | |
55 | { | |
56 | 1734288 | return value1.hashCode() + value2.hashCode(); |
57 | } | |
58 | ||
59 | public String toString() | |
60 | { | |
61 | 0 | return "<" + value1.toString() + ", " + value2.toString() + ">"; |
62 | } | |
63 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |