| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| NodeNumberingAsPartitionVisitor |
|
| 1.0;1 |
| 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 10.02.2005 | |
| 20 | * | |
| 21 | */ | |
| 22 | package net.sourceforge.combean.graph.alg.partition; | |
| 23 | ||
| 24 | import net.sourceforge.combean.interfaces.graph.Graph; | |
| 25 | import net.sourceforge.combean.interfaces.graph.Node; | |
| 26 | import net.sourceforge.combean.interfaces.graph.alg.partition.NodePartitionVisitor; | |
| 27 | import net.sourceforge.combean.interfaces.graph.containers.NodeNumbering; | |
| 28 | ||
| 29 | /** | |
| 30 | * Use a node numbering to store the partition numbers. | |
| 31 | * Counting of the partitions starts from 1; | |
| 32 | * | |
| 33 | * @author schickin | |
| 34 | * | |
| 35 | */ | |
| 36 | public class NodeNumberingAsPartitionVisitor implements NodePartitionVisitor { | |
| 37 | ||
| 38 | 27 | private int partitionCounter = 0; |
| 39 | 27 | private NodeNumbering numbering = null; |
| 40 | ||
| 41 | /** | |
| 42 | * Constructor | |
| 43 | * | |
| 44 | * @param numbering the numbering to be used for storing the partitions. | |
| 45 | */ | |
| 46 | public NodeNumberingAsPartitionVisitor(NodeNumbering numbering) { | |
| 47 | 27 | super(); |
| 48 | ||
| 49 | 27 | this.numbering = numbering; |
| 50 | 27 | } |
| 51 | ||
| 52 | /* (non-Javadoc) | |
| 53 | * @see net.sourceforge.combean.interfaces.graph.alg.partition.NodePartitionVisitor#init() | |
| 54 | */ | |
| 55 | public void init(Graph g) { | |
| 56 | 27 | this.numbering.init(g); |
| 57 | 27 | this.partitionCounter = 0; |
| 58 | 27 | } |
| 59 | ||
| 60 | /* (non-Javadoc) | |
| 61 | * @see net.sourceforge.combean.interfaces.graph.alg.partition.NodePartitionVisitor#startPartition() | |
| 62 | */ | |
| 63 | public void startPartition() { | |
| 64 | 66 | this.partitionCounter++; |
| 65 | 66 | } |
| 66 | ||
| 67 | /* (non-Javadoc) | |
| 68 | * @see net.sourceforge.combean.interfaces.graph.alg.partition.NodePartitionVisitor#addNode(net.sourceforge.combean.interfaces.graph.Node) | |
| 69 | */ | |
| 70 | public void addNode(Node v) { | |
| 71 | 168 | this.numbering.setNumber(v, this.partitionCounter); |
| 72 | 168 | } |
| 73 | ||
| 74 | /* (non-Javadoc) | |
| 75 | * @see net.sourceforge.combean.interfaces.graph.alg.partition.NodePartitionVisitor#endPartition() | |
| 76 | */ | |
| 77 | public void endPartition() { | |
| 78 | /* nothing to do */ | |
| 79 | 66 | } |
| 80 | ||
| 81 | /* (non-Javadoc) | |
| 82 | * @see net.sourceforge.combean.interfaces.graph.alg.partition.NodePartitionVisitor#finish() | |
| 83 | */ | |
| 84 | public void finish() { | |
| 85 | /* nothing to do */ | |
| 86 | 15 | } |
| 87 | ||
| 88 | /* (non-Javadoc) | |
| 89 | * @see net.sourceforge.combean.interfaces.graph.alg.partition.NodePartitionVisitor#getNumPartitions() | |
| 90 | */ | |
| 91 | public int getNumPartitions() { | |
| 92 | 27 | return this.partitionCounter; |
| 93 | } | |
| 94 | } |