Coverage Report - net.sourceforge.combean.samples.simplegraphs.CompositeNumberGraph
 
Classes in this File Line Coverage Branch Coverage Complexity
CompositeNumberGraph
100%
34/34
100%
12/12
0
 
 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 15.01.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.samples.simplegraphs;
 23  
 
 24  
 import java.util.Collection;
 25  
 import java.util.Iterator;
 26  
 import java.util.LinkedList;
 27  
 
 28  
 import net.sourceforge.combean.util.Pair;
 29  
 
 30  
 /**
 31  
  * @author schickin
 32  
  *
 33  
  */
 34  
 public class CompositeNumberGraph extends NumberGraph {
 35  
         
 36  
         private Collection<Pair> childGraphs;
 37  
 
 38  
         /**
 39  
          * 
 40  
          */
 41  
         public CompositeNumberGraph() {
 42  78
                 super();
 43  
                 
 44  78
                 this.childGraphs = new LinkedList<Pair>();
 45  78
         }
 46  
 
 47  
         /**
 48  
          * @see net.sourceforge.combean.samples.simplegraphs.NumberGraph#calcNextNode(int, int)
 49  
          */
 50  
         protected int calcNextNode(int sourceNodeNum, int minNodeNum) {
 51  585
                 int nextNodeCand = NumberGraph.NOSUCHNODE;
 52  
                 
 53  585
                 Iterator itChild = this.childGraphs.iterator();
 54  1755
                 while (itChild.hasNext()) {
 55  1170
                         Pair offsetAndGraph = (Pair) itChild.next(); 
 56  1170
                         Integer offset = (Integer) offsetAndGraph.getFirst(); 
 57  1170
                         NumberGraph g = (NumberGraph) offsetAndGraph.getSecond();
 58  
                         
 59  1170
                         int startNodeInG = sourceNodeNum - offset.intValue();
 60  
                         
 61  1170
                         if (0 <= startNodeInG && startNodeInG < g.getNumNodes()) {
 62  771
                                 int currNodeInG = minNodeNum - offset.intValue();
 63  771
                                 int nextNodeOfG = g.calcNextNode(startNodeInG, currNodeInG);
 64  
 
 65  771
                                 if (nextNodeOfG != NumberGraph.NOSUCHNODE) {
 66  480
                                         nextNodeOfG += offset.longValue();
 67  
                                         
 68  480
                                         if (nextNodeCand == NumberGraph.NOSUCHNODE) {
 69  408
                                                 nextNodeCand = nextNodeOfG;
 70  
                                         }
 71  
                                         else {
 72  72
                                                 nextNodeCand = Math.min(nextNodeCand, nextNodeOfG);
 73  
                                         }
 74  
                                 }
 75  
                         }
 76  1170
                 }
 77  585
                 return nextNodeCand;
 78  
         }
 79  
 
 80  
         /**
 81  
          * @see net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp#getNumNodes()
 82  
          */
 83  
         public int getNumNodes() {
 84  1440
                 int maxNodeOffset = 0;
 85  1440
                 Iterator itChild = this.childGraphs.iterator();
 86  4320
                 while (itChild.hasNext()) {
 87  2880
                         Pair offsetAndGraph = (Pair) itChild.next(); 
 88  2880
                         Integer offset = (Integer) offsetAndGraph.getFirst(); 
 89  2880
                         NumberGraph g = (NumberGraph) offsetAndGraph.getSecond();
 90  2880
                         maxNodeOffset =
 91  
                                 Math.max(maxNodeOffset,
 92  
                                                  offset.intValue() + g.getNumNodes());
 93  2880
                 }
 94  1440
                 return maxNodeOffset;
 95  
         }
 96  
 
 97  
         public void add(NumberGraph g) {
 98  93
                 add(g, 0);
 99  93
         }
 100  
 
 101  
         public void add(NumberGraph g, int offset) {
 102  156
                 this.childGraphs.add(new Pair(new Integer(offset), g));
 103  156
         }
 104  
         
 105  
         public int getNumGraphs() {
 106  6
                 return this.childGraphs.size();
 107  
         }
 108  
 }