Coverage Report - org.dishevelled.observable.graph.impl.ObservableGraphImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ObservableGraphImpl
100%
32/32
N/A
1.909
 
 1  
 /*
 2  
 
 3  
     dsh-observable-graph  Observable decorators for graph interfaces.
 4  
     Copyright (c) 2008-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.observable.graph.impl;
 25  
 
 26  
 import org.dishevelled.graph.Edge;
 27  
 import org.dishevelled.graph.Graph;
 28  
 import org.dishevelled.graph.Node;
 29  
 
 30  
 import org.dishevelled.observable.graph.AbstractObservableGraph;
 31  
 
 32  
 import org.dishevelled.observable.graph.event.GraphChangeVetoException;
 33  
 
 34  
 /**
 35  
  * Observable graph decorator that fires vetoable graph change events
 36  
  * in <code>preXxx</code> methods and graph change events in
 37  
  * <code>postXxx</code> methods.
 38  
  *
 39  
  * @param <N> node value type
 40  
  * @param <E> edge value type
 41  
  * @author  Michael Heuer
 42  
  * @version $Revision$ $Date$
 43  
  */
 44  
 public final class ObservableGraphImpl<N, E>
 45  
     extends AbstractObservableGraph<N, E>
 46  
 {
 47  
 
 48  
     /**
 49  
      * Create a new observable decorator for the specified graph.
 50  
      *
 51  
      * @param graph graph to decorate, must not be null
 52  
      */
 53  
     public ObservableGraphImpl(final Graph<N, E> graph)
 54  
     {
 55  134
         super(graph);
 56  133
     }
 57  
 
 58  
 
 59  
     /** {@inheritDoc} */
 60  
     protected boolean preClear()
 61  
     {
 62  
         try
 63  
         {
 64  4
             fireWillClear();
 65  2
             return true;
 66  
         }
 67  2
         catch (GraphChangeVetoException e)
 68  
         {
 69  2
             return false;
 70  
         }
 71  
     }
 72  
 
 73  
     /** {@inheritDoc} */
 74  
     protected void postClear()
 75  
     {
 76  1
         fireCleared();
 77  1
     }
 78  
 
 79  
     /** {@inheritDoc} */
 80  
     protected boolean preCreateNode(final N value)
 81  
     {
 82  
         try
 83  
         {
 84  23
             fireWillCreateNode(value);
 85  17
             return true;
 86  
         }
 87  6
         catch (GraphChangeVetoException e)
 88  
         {
 89  6
             return false;
 90  
         }
 91  
     }
 92  
 
 93  
     /** {@inheritDoc} */
 94  
     protected void postCreateNode(final N value, final Node<N, E> node)
 95  
     {
 96  15
         fireNodeCreated(node);
 97  15
     }
 98  
 
 99  
     /** {@inheritDoc} */
 100  
     protected boolean preRemove(final Node<N, E> node)
 101  
     {
 102  
         try
 103  
         {
 104  4
             fireWillRemoveNode(node);
 105  2
             return true;
 106  
         }
 107  2
         catch (GraphChangeVetoException e)
 108  
         {
 109  2
             return false;
 110  
         }
 111  
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     protected void postRemove(final Node<N, E> node)
 115  
     {
 116  1
         fireNodeRemoved(node);
 117  1
     }
 118  
 
 119  
     /** {@inheritDoc} */
 120  
     protected boolean preCreateEdge(final Node<N, E> source,
 121  
                                     final Node<N, E> target,
 122  
                                     final E value)
 123  
     {
 124  
         try
 125  
         {
 126  5
             fireWillCreateEdge(source, target, value);
 127  3
             return true;
 128  
         }
 129  2
         catch (GraphChangeVetoException e)
 130  
         {
 131  2
             return false;
 132  
         }
 133  
     }
 134  
 
 135  
     /** {@inheritDoc} */
 136  
     protected void postCreateEdge(final Node<N, E> source,
 137  
                                   final Node<N, E> target,
 138  
                                   final E value,
 139  
                                   final Edge<N, E> edge)
 140  
     {
 141  3
         fireEdgeCreated(edge);
 142  3
     }
 143  
 
 144  
     /** {@inheritDoc} */
 145  
     protected boolean preRemove(final Edge<N, E> edge)
 146  
     {
 147  
         try
 148  
         {
 149  4
             fireWillRemoveEdge(edge);
 150  2
             return true;
 151  
         }
 152  2
         catch (GraphChangeVetoException e)
 153  
         {
 154  2
             return false;
 155  
         }
 156  
     }
 157  
 
 158  
     /** {@inheritDoc} */
 159  
     protected void postRemove(final Edge<N, E> edge)
 160  
     {
 161  1
         fireEdgeRemoved(edge);
 162  1
     }
 163  
 }