KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > detect > StreamEscape


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.detect;
21
22
23 import edu.umd.cs.findbugs.ba.Location;
24
25 /**
26  * A StreamEscape is an object representing the escape of a Stream
27  * to a called method.
28  * The "source" is the Stream which is escaping.
29  * The "target" is the Location where the stream instance escapes.
30  */

31 public class StreamEscape implements Comparable JavaDoc<StreamEscape> {
32     public final Stream source;
33     public final Location target;
34
35     /**
36      * Constructor.
37      *
38      * @param source Location where stream is opened
39      * @param target Location where stream escapes by being
40      * passed to a method
41      */

42     public StreamEscape(Stream source, Location target) {
43         this.source = source;
44         this.target = target;
45     }
46
47     public int compareTo(StreamEscape other) {
48         int cmp = source.compareTo(other.source);
49         if (cmp != 0) return cmp;
50         return target.compareTo(other.target);
51     }
52
53     public int hashCode() {
54         return source.hashCode() + 7*target.hashCode();
55     }
56     @Override JavaDoc
57     public boolean equals(Object JavaDoc o) {
58         if (!(o instanceof StreamEscape)) return false;
59         StreamEscape other = (StreamEscape) o;
60         return source.equals(other.source) && target.equals(other.target);
61     }
62     @Override JavaDoc
63          public String JavaDoc toString() {
64         return source + " to " + target;
65     }
66 }
67
68 // vim:ts=3
69
Popular Tags