Coverage details for edu.uci.ics.jung.utils.Pair

LineHitsSource
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  
28315468    public Pair(Object value1, Object value2) {
29315468        if ( value1 == null || value2 == null)
300            throw new FatalException("A Pair can't hold nulls.");
31315468        this.value1 = value1;
32315468        this.value2 = value2;
33315468    }
34  
35     public Object getFirst() {
362119190        return value1;
37     }
38     public Object getSecond() {
39272895        return value2;
40     }
41     
42     public boolean equals( Object o ) {
43100        if (o instanceof Pair) {
44100            Pair tt = (Pair) o;
45100            Object first = tt.getFirst();
46100            Object second = tt.getSecond();
47100            return ((first == value1 || first.equals(value1)) &&
48                     (second == value2 || second.equals(value2)));
49         } else {
500            return false;
51         }
52     }
53     
54     public int hashCode()
55     {
561734288        return value1.hashCode() + value2.hashCode();
57     }
58     
59     public String toString()
60     {
610        return "<" + value1.toString() + ", " + value2.toString() + ">";
62     }
63 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.