Coverage Report - net.sourceforge.combean.graph.decorators.OrderedNodesGraph
 
Classes in this File Line Coverage Branch Coverage Complexity
OrderedNodesGraph
92%
12/13
50%
2/4
1,5
 
 1  
 /*
 2  
     This file is part of Combean.
 3  
 
 4  
     Combean is free software; you can redistribute it and/or modify
 5  
     it under the terms of the GNU General Public License as published by
 6  
     the Free Software Foundation; either version 2 of the License, or
 7  
     (at your option) any later version.
 8  
 
 9  
     Combean is distributed in the hope that it will be useful,
 10  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
     GNU General Public License for more details.
 13  
 
 14  
     You should have received a copy of the GNU General Public License
 15  
     along with Combean; if not, write to the Free Software
 16  
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17  
 */
 18  
 /*
 19  
  * Created on 25.03.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.graph.decorators;
 23  
 
 24  
 import net.sourceforge.combean.interfaces.graph.NodeIterator;
 25  
 import net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp;
 26  
 import net.sourceforge.combean.util.except.UnsupportedMethodException;
 27  
 
 28  
 /**
 29  
  * A decorator which returns a specific all nodes iterator, i.e., which
 30  
  * enforces traversal of the nodes of the graph in a given order.
 31  
  * 
 32  
  * @author schickin
 33  
  *
 34  
  */
 35  
 public class OrderedNodesGraph extends AbstractDecoratedGraph
 36  
 implements GlobalNodesGraphProp {
 37  
     
 38  18
     private GlobalNodesGraphProp g = null;
 39  18
     private NodeIterator itAllNodes = null;
 40  
 
 41  
     /**
 42  
      * Constructor
 43  
      * 
 44  
      * @param g the graph the nodes of which shall be traversed in a specific order
 45  
      * @param itAllNodes the iterator (with the current implementation
 46  
      * getAllNodesIterator() may only be invoked once on the decorated graph) 
 47  
      */
 48  
     public OrderedNodesGraph(GlobalNodesGraphProp g, NodeIterator itAllNodes) {
 49  18
         super(g);
 50  
         
 51  18
         this.g = g;
 52  18
         this.itAllNodes = itAllNodes;
 53  18
     }
 54  
 
 55  
     /* (non-Javadoc)
 56  
      * @see net.sourceforge.combean.interfaces.graph.GlobalNodesGraphProp#getNumNodes()
 57  
      */
 58  
     public int getNumNodes() {
 59  3
          return this.g.getNumNodes();
 60  
     }
 61  
 
 62  
     /* (non-Javadoc)
 63  
      * @see net.sourceforge.combean.interfaces.graph.GlobalNodesGraphProp#getAllNodesIterator()
 64  
      */
 65  
     public NodeIterator getAllNodesIterator() {
 66  15
         NodeIterator result = this.itAllNodes;
 67  15
         if (result == null) {
 68  0
             throw new UnsupportedMethodException("OrderedNodes can only produce one iterator for all nodes");
 69  
         }
 70  15
         this.itAllNodes = null;
 71  15
         return result;
 72  
     }
 73  
     
 74  
     /**
 75  
      * All nested properties except those which refer to the global nodes
 76  
      * and their identity (GlobalNodesGraphProp and derivatives) may be nested.
 77  
      * 
 78  
      * @see net.sourceforge.combean.interfaces.graph.prop.NestedGraphProp#mayNestGraphProp(java.lang.Class)
 79  
      */
 80  
     public boolean mayNestGraphProp(Class wantedProp) {
 81  24
          return !GlobalNodesGraphProp.class.isAssignableFrom(wantedProp);
 82  
     }
 83  
 }