Skip to content

Commit

Permalink
#27 Removing unused field from Dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Jan 27, 2019
1 parent a249943 commit 9a76633
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@
*/
public class Dependency {

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

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

from.addOutgoingDependency(this);
}

public Node getFrom() {
return from;
}

public Node getTo() {
Expand All @@ -46,6 +38,6 @@ public int getAggregatedWeight() {

@Override
public String toString() {
return "Dependency [from=" + from + ", to=" + to + ", aggregatdWeight=" + aggregatedWeight + "]";
return "Dependency [to=" + to + ", aggregatdWeight=" + aggregatedWeight + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public Dependency getOutgoingDependencyTo(Node node) {
}

public Set<Dependency> getOutgoingDependenciesTo(Collection<Node> nodes) {
return Objects.requireNonNull(nodes).stream().map(node -> getOutgoingDependencyTo(node))
return Objects.requireNonNull(nodes).stream()
.map(node -> getOutgoingDependencyTo(node))
.filter(dep -> dep != null)
.collect(Collectors.toSet());
}
Expand All @@ -56,9 +57,8 @@ public boolean hasOutgoingDependencies() {
return outgoingDependencies != null && !outgoingDependencies.isEmpty();
}

public void addOutgoingDependency(Dependency dependency) {
Objects.requireNonNull(dependency);
outgoingDependencies().put(dependency.getTo(), dependency);
public void addOutgoingDependency(Node to, int aggregatedWeight) {
outgoingDependencies().put(to, new Dependency(to, aggregatedWeight));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public static List<Node> createDummyModel() {
Node p3 = new Node("p3");
Node p4 = new Node("p4");

new Dependency(p1, p2, 13);
new Dependency(p2, p3, 57);
new Dependency(p3, p4, 45);
new Dependency(p4, p3, 3);
p1.addOutgoingDependency(p2, 13);
p2.addOutgoingDependency(p3, 57);
p3.addOutgoingDependency(p4, 45);
p4.addOutgoingDependency(p3, 3);

return new ArrayList<>(Arrays.asList(p1, p2, p3, p4));
}
Expand Down

0 comments on commit 9a76633

Please sign in to comment.