Coverage Report - org.dishevelled.graph.impl.AbstractGraphDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractGraphDecorator
94%
37/39
100%
2/2
1.083
 
 1  
 /*
 2  
 
 3  
     dsh-graph  Directed graph interface and implementation.
 4  
     Copyright (c) 2004-2013 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.graph.impl;
 25  
 
 26  
 import java.util.Collection;
 27  
 import java.util.Map;
 28  
 import java.util.Set;
 29  
 
 30  
 import org.dishevelled.functor.UnaryPredicate;
 31  
 import org.dishevelled.functor.UnaryProcedure;
 32  
 
 33  
 import org.dishevelled.graph.Edge;
 34  
 import org.dishevelled.graph.Graph;
 35  
 import org.dishevelled.graph.Node;
 36  
 
 37  
 /**
 38  
  * Abstract graph that decorates an instance of <code>Graph</code>.
 39  
  *
 40  
  * @param <N> node value type
 41  
  * @param <E> edge value type
 42  
  * @author  Michael Heuer
 43  
  * @version $Revision$ $Date$
 44  
  */
 45  
 public abstract class AbstractGraphDecorator<N, E>
 46  
     implements Graph<N, E>
 47  
 {
 48  
     /** Graph this decorator decorates. */
 49  
     private final Graph<N, E> graph;
 50  
 
 51  
 
 52  
     /**
 53  
      * Create a new abstract graph that decorates the specified graph.
 54  
      *
 55  
      * @param graph graph to decorate, must not be null
 56  
      */
 57  
     protected AbstractGraphDecorator(final Graph<N, E> graph)
 58  115
     {
 59  115
         if (graph == null)
 60  
         {
 61  1
             throw new IllegalArgumentException("graph must not be null");
 62  
         }
 63  114
         this.graph = graph;
 64  114
     }
 65  
 
 66  
 
 67  
     /**
 68  
      * Return a reference to the graph this decorator decorates.
 69  
      *
 70  
      * @return a reference to the graph this decorator decorates
 71  
      */
 72  
     protected final Graph<N, E> getGraph()
 73  
     {
 74  0
         return graph;
 75  
     }
 76  
 
 77  
     /** {@inheritDoc} */
 78  
     public boolean isEmpty()
 79  
     {
 80  0
         return graph.isEmpty();
 81  
     }
 82  
 
 83  
     /** {@inheritDoc} */
 84  
     public int nodeCount()
 85  
     {
 86  35
         return graph.nodeCount();
 87  
     }
 88  
 
 89  
     /** {@inheritDoc} */
 90  
     public Set<Node<N, E>> nodes()
 91  
     {
 92  49
         return graph.nodes();
 93  
     }
 94  
 
 95  
     /** {@inheritDoc} */
 96  
     public Collection<N> nodeValues()
 97  
     {
 98  28
         return graph.nodeValues();
 99  
     }
 100  
 
 101  
     /** {@inheritDoc} */
 102  
     public <T> Map<Node<N, E>, T> nodeMap(final T defaultValue)
 103  
     {
 104  40
         return graph.nodeMap(defaultValue);
 105  
     }
 106  
 
 107  
     /** {@inheritDoc} */
 108  
     public void forEachNode(final UnaryProcedure<Node<N, E>> procedure)
 109  
     {
 110  8
         graph.forEachNode(procedure);
 111  4
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     public void forEachNode(final UnaryPredicate<Node<N, E>> predicate,
 115  
                             final UnaryProcedure<Node<N, E>> procedure)
 116  
     {
 117  16
         graph.forEachNode(predicate, procedure);
 118  4
     }
 119  
 
 120  
     /** {@inheritDoc} */
 121  
     public void forEachNodeValue(final UnaryProcedure<? super N> procedure)
 122  
     {
 123  12
         graph.forEachNodeValue(procedure);
 124  8
     }
 125  
 
 126  
     /** {@inheritDoc} */
 127  
     public void forEachNodeValue(final UnaryPredicate<N> predicate, final UnaryProcedure<N> procedure)
 128  
     {
 129  16
         graph.forEachNodeValue(predicate, procedure);
 130  4
     }
 131  
 
 132  
     /** {@inheritDoc} */
 133  
     public int edgeCount()
 134  
     {
 135  35
         return graph.edgeCount();
 136  
     }
 137  
 
 138  
     /** {@inheritDoc} */
 139  
     public Set<Edge<N, E>> edges()
 140  
     {
 141  47
         return graph.edges();
 142  
     }
 143  
 
 144  
     /** {@inheritDoc} */
 145  
     public Collection<E> edgeValues()
 146  
     {
 147  28
         return graph.edgeValues();
 148  
     }
 149  
 
 150  
     /** {@inheritDoc} */
 151  
     public <T> Map<Edge<N, E>, T> edgeMap(final T defaultValue)
 152  
     {
 153  38
         return graph.edgeMap(defaultValue);
 154  
     }
 155  
 
 156  
     /** {@inheritDoc} */
 157  
     public void forEachEdge(final UnaryProcedure<Edge<N, E>> procedure)
 158  
     {
 159  8
         graph.forEachEdge(procedure);
 160  4
     }
 161  
 
 162  
     /** {@inheritDoc} */
 163  
     public void forEachEdge(final UnaryPredicate<Edge<N, E>> predicate,
 164  
                             final UnaryProcedure<Edge<N, E>> procedure)
 165  
     {
 166  16
         graph.forEachEdge(predicate, procedure);
 167  4
     }
 168  
 
 169  
     /** {@inheritDoc} */
 170  
     public void forEachEdgeValue(final UnaryProcedure<? super E> procedure)
 171  
     {
 172  12
         graph.forEachEdgeValue(procedure);
 173  8
     }
 174  
 
 175  
     /** {@inheritDoc} */
 176  
     public void forEachEdgeValue(final UnaryPredicate<E> predicate, final UnaryProcedure<E> procedure)
 177  
     {
 178  16
         graph.forEachEdgeValue(predicate, procedure);
 179  4
     }
 180  
 
 181  
     /** {@inheritDoc} */
 182  
     public void clear()
 183  
     {
 184  4
         graph.clear();
 185  4
     }
 186  
 
 187  
     /** {@inheritDoc} */
 188  
     public Node<N, E> createNode(final N value)
 189  
     {
 190  10
         return graph.createNode(value);
 191  
     }
 192  
 
 193  
     /** {@inheritDoc} */
 194  
     public void remove(final Node<N, E> node)
 195  
     {
 196  3
         graph.remove(node);
 197  1
     }
 198  
 
 199  
     /** {@inheritDoc} */
 200  
     public Edge<N, E> createEdge(final Node<N, E> source, final Node<N, E> target, final E value)
 201  
     {
 202  8
         return graph.createEdge(source, target, value);
 203  
     }
 204  
 
 205  
     /** {@inheritDoc} */
 206  
     public void remove(final Edge<N, E> edge)
 207  
     {
 208  3
         graph.remove(edge);
 209  1
     }
 210  
 }