Clover coverage report - Convert - proto0
Coverage timestamp: Mo Nov 22 2004 13:19:16 CET
file stats: LOC: 117   Methods: 11
NCLOC: 74   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SparseWeightedDirectedGraph.java 40% 50% 63,6% 49,3%
coverage coverage
 1    /*
 2    * Copyright 2004 Ronald Blaschke.
 3    *
 4    * Licensed under the Apache License, Version 2.0 (the "License");
 5    * you may not use this file except in compliance with the License.
 6    * You may obtain a copy of the License at
 7    *
 8    * http://www.apache.org/licenses/LICENSE-2.0
 9    *
 10    * Unless required by applicable law or agreed to in writing, software
 11    * distributed under the License is distributed on an "AS IS" BASIS,
 12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13    * See the License for the specific language governing permissions and
 14    * limitations under the License.
 15    */
 16    package org.rblasch.convert.graph;
 17   
 18    import java.util.Collections;
 19    import java.util.HashSet;
 20    import java.util.Iterator;
 21    import java.util.Set;
 22   
 23    public final class SparseWeightedDirectedGraph implements WeightedDirectedGraph {
 24    private final Set /* of Vertex */ vertices = new HashSet();
 25    private final Set /* of WeightedDirectedEdge */ edges = new HashSet();
 26    private final Set /* of Connection */ connections = new HashSet();
 27   
 28  73 public Set /* of Vertex */ getVertices() {
 29  73 return Collections.unmodifiableSet(vertices);
 30    }
 31   
 32  0 public Set /* of WeightedDirectedEdge */ getEdges() {
 33  0 return Collections.unmodifiableSet(edges);
 34    }
 35   
 36  468 public void addVertex(final Vertex v) {
 37  468 vertices.add(v);
 38    }
 39   
 40    /**
 41    * Enter a new segment in the graph.
 42    */
 43  2981 public void addConnection(final Vertex start, final Edge edge, final Vertex end) {
 44  2981 vertices.add(start);
 45  2981 edges.add(edge);
 46  2981 vertices.add(end);
 47  2981 connections.add(new Connection(start, edge, end));
 48    }
 49   
 50  14 public Set/*<Connection>*/ getAllConnections() {
 51  14 return Collections.unmodifiableSet(connections);
 52    }
 53   
 54  12294 public Set /* of Connection */ getConnections(final Vertex start, final Vertex end) {
 55  12294 final Set /* of Connection */ cons = new HashSet();
 56  12294 for (final Iterator i = connections.iterator(); i.hasNext();) {
 57  1138537 final Connection c = (Connection) i.next();
 58  1138537 if (c.getStart().equals(start) && c.getEnd().equals(end)) {
 59  12294 cons.add(c);
 60    }
 61    }
 62  12294 return cons;
 63    }
 64   
 65    /**
 66    * Get the list of vertices that can be reached from the given vertex.
 67    */
 68  5770 public Set /* Vertex */ getOutbound(final Vertex vertex) {
 69  5770 final Set destinations = new HashSet();
 70   
 71  5770 for (final Iterator i = connections.iterator(); i.hasNext();) {
 72  518006 final Connection c = (Connection) i.next();
 73  518006 if (c.getStart().equals(vertex)) {
 74  12590 destinations.add(c.getEnd());
 75    }
 76    }
 77   
 78  5770 return destinations;
 79    }
 80   
 81    /**
 82    * Get the list of vertices that lead to the given vertex.
 83    */
 84  0 public Set /* of Vertex */ getInbound(final Vertex vertex) {
 85  0 final Set predecessors = new HashSet();
 86   
 87  0 for (final Iterator i = connections.iterator(); i.hasNext();) {
 88  0 final Connection c = (Connection) i.next();
 89  0 if (c.getEnd().equals(vertex)) {
 90  0 predecessors.add(c.getStart());
 91    }
 92    }
 93   
 94  0 return predecessors;
 95    }
 96   
 97  0 public boolean equals(final Object obj) {
 98  0 if (this == obj) return true;
 99  0 if (!(obj instanceof SparseWeightedDirectedGraph)) return false;
 100   
 101  0 final SparseWeightedDirectedGraph rhs = (SparseWeightedDirectedGraph) obj;
 102  0 if (!edges.equals(rhs.edges)) return false;
 103  0 if (!vertices.equals(rhs.vertices)) return false;
 104   
 105  0 return true;
 106    }
 107   
 108  0 public int hashCode() {
 109  0 int result = vertices.hashCode();
 110  0 result = 29 * result + edges.hashCode();
 111  0 return result;
 112    }
 113   
 114  120 public String toString() {
 115  120 return connections.toString();
 116    }
 117    }