Skip to content

Commit

Permalink
moditect#27 Formatting and style adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Jan 27, 2019
1 parent 34ad025 commit 3ae3499
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
*/
package org.moditect.deptective.internal.graph;

import org.moditect.deptective.internal.graph.Dependency;

/**
* @author Gerd Wütherich (gw@code-kontor.io)
*/
public class Dependency {

private Node from;
private Node to;
private int aggregatdWeight;
private final Node from;
private final Node to;
private final int aggregatedWeight;

public Dependency(Node from, Node to, int aggregatdWeight) {
public Dependency(Node from, Node to, int aggregatedWeight) {
this.from = from;
this.to = to;
this.aggregatdWeight = aggregatdWeight;
this.aggregatedWeight = aggregatedWeight;

from.addOutgoingDependency(this);
}
Expand All @@ -43,11 +41,11 @@ public Node getTo() {
}

public int getAggregatedWeight() {
return aggregatdWeight;
return aggregatedWeight;
}

@Override
public String toString() {
return "SimpleDependency [from=" + from + ", to=" + to + ", aggregatdWeight=" + aggregatdWeight + "]";
return "Dependency [from=" + from + ", to=" + to + ", aggregatdWeight=" + aggregatedWeight + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.moditect.deptective.internal.graph.impl.Tarjan;

/**
*
* @author Gerd Wütherich (gw@code-kontor.io)
*/
public class GraphUtils {
Expand All @@ -40,10 +39,11 @@ public class GraphUtils {
*
* @param nodes the collection of nodes (the directed graph)
* @return a list of strongly connected components (SCCs). Note that the result also contains components that
* contain just a single node. If you want to detect 'real' cycle (size > 1) please use {@link GraphUtils#detectCycles(Collection)}.
* contain just a single node. If you want to detect 'real' cycle (size > 1) please use
* {@link GraphUtils#detectCycles(Collection)}.
*/
public static List<List<Node>> detectStronglyConnectedComponents(Collection<Node> nodes) {
return new Tarjan<Node>().detectStronglyConnectedComponents(Objects.requireNonNull(nodes));
return new Tarjan<>().detectStronglyConnectedComponents(Objects.requireNonNull(nodes));
}

/**
Expand All @@ -53,7 +53,7 @@ public static List<List<Node>> detectStronglyConnectedComponents(Collection<Node
* @return a list of strongly connected components (SCCs) with a size > 1.
*/
public static List<List<Node>> detectCycles(Collection<Node> nodes) {
return new Tarjan<Node>().detectStronglyConnectedComponents(nodes).stream().filter(cycle -> cycle.size() > 1)
return new Tarjan<>().detectStronglyConnectedComponents(nodes).stream().filter(cycle -> cycle.size() > 1)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public String getId() {
}

public Dependency getOutgoingDependencyTo(Node node) {

if (!hasOutgoingDependencies() || !outgoingDependencies.containsKey(Objects.requireNonNull(node))) {
if (!hasOutgoingDependencies()) {
return null;
}

return outgoingDependencies.get(node);
}

public Set<Dependency> getOutgoingDependenciesTo(Collection<Node> nodes) {
return Objects.requireNonNull(nodes).stream().map(node -> getOutgoingDependencyTo(node)).filter(dep -> dep != null)
return Objects.requireNonNull(nodes).stream().map(node -> getOutgoingDependencyTo(node))
.filter(dep -> dep != null)
.collect(Collectors.toSet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,16 @@
import org.junit.Test;

/**
*
* @author Gerd W&uuml;therich (gw@code-kontor.io)
*/
public class CyclesTest {

@Test
public void detectCycle() {

//
List<Node> nodes = TestModelCreator.createDummyModel();

//
List<List<Node>> cycles = GraphUtils.detectCycles(nodes);

//
assertThat(cycles).hasSize(1);

//
assertThat(cycles.get(0)).contains(nodes.get(2)).contains(nodes.get(3));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,22 @@
import org.junit.Test;

/**
*
* @author Gerd W&uuml;therich (gw@code-kontor.io)
*/
public class DependencyStructureMatrixTest {

@Test
public void detectCycle() {

//
List<Node> nodes = TestModelCreator.createDummyModel();

//
IDependencyStructureMatrix dsm = GraphUtils.createDependencyStructureMatrix(nodes);

// assert ordered nodes
assertThat(dsm.getOrderedNodes()).hasSize(4).containsExactly(
nodes.get(0), nodes.get(1), nodes.get(2),
nodes.get(3)
);

// assert upward dependencies
assertThat(dsm.getUpwardDependencies()).hasSize(1)
.containsExactly(nodes.get(3).getOutgoingDependencyTo(nodes.get(2)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@ public class FasNodeSorterTest {

@Test
public void sortNodes() {

//
List<Node> nodes = TestModelCreator.createDummyModel();

//
INodeSorter nodeSorter = GraphUtils.createFasNodeSorter();

//
SortResult sortResult = nodeSorter.sort(nodes);

//
assertThat(sortResult.getUpwardsDependencies()).hasSize(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,17 @@
import org.junit.Test;

/**
*
* @author Gerd W&uuml;therich (gw@code-kontor.io)
*/
public class StronglyConnectedComponentsTest {

@Test
public void detectCycle() {

//
List<Node> nodes = TestModelCreator.createDummyModel();

//
List<List<Node>> stronglyConnectedComponents = GraphUtils.detectStronglyConnectedComponents(nodes);

//
assertThat(stronglyConnectedComponents).hasSize(3);

//
for (List<Node> scc : stronglyConnectedComponents) {
if (scc.size() == 2) {
assertThat(scc).contains(nodes.get(2)).contains(nodes.get(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
import java.util.Arrays;
import java.util.List;

import org.moditect.deptective.internal.graph.Dependency;
import org.moditect.deptective.internal.graph.Node;

/**
*
* @author Gerd W&uuml;therich (gw@code-kontor.io)
*/
public class TestModelCreator {

/**
*
* @return
* Returns a test graph in with this structure:
* <p>
* P1 -> P2 -> P3 <-> P4
*/
public static List<Node> createDummyModel() {

Expand Down

0 comments on commit 3ae3499

Please sign in to comment.