From 267b35a813dd1ad5c3eec253f5d6f9d613bbb1ec Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Wed, 1 Oct 2025 21:31:26 -0500 Subject: Tweak ChannelNode to pass tests --- src/main/java/ChannelNode.java | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/ChannelNode.java b/src/main/java/ChannelNode.java index e984cf0..ddc1488 100644 --- a/src/main/java/ChannelNode.java +++ b/src/main/java/ChannelNode.java @@ -26,6 +26,7 @@ public class ChannelNode implements IChannelNode { @Override public void setNumConnections(IChannelNode node, Direction dir, int num) throws IllegalArgumentException { if(node == null) throw new IllegalArgumentException("node is null"); + if(node == this) throw new IllegalArgumentException("node is self"); if(dir == null) throw new IllegalArgumentException("dir is null"); if(num < 0) throw new IllegalArgumentException("num < 0"); @@ -35,10 +36,10 @@ public class ChannelNode implements IChannelNode { } @Override - public void addConnection(IChannelNode node, Direction dir) { + public void addConnection(IChannelNode node, Direction dir) throws IllegalArgumentException { if(node == null) throw new IllegalArgumentException("node is null"); if(node == this) throw new IllegalArgumentException("node is self"); - if(dir == null) throw new IllegalStateException("dir is null"); + if(dir == null) throw new IllegalArgumentException("dir is null"); int dv = dir.getVal(); if(dv >= Direction.INCOMING.getVal()) incoming.put(node, incoming.get(node) + 1); @@ -46,7 +47,7 @@ public class ChannelNode implements IChannelNode { } @Override - public void addConnections(Iterable nodes, Direction dir) { + public void addConnections(Iterable nodes, Direction dir) throws IllegalArgumentException { if(nodes == null) throw new IllegalArgumentException("node is null"); if(dir == null) throw new IllegalArgumentException("dir is null"); nodes.forEach((node) -> {if(node == this) throw new IllegalArgumentException("one of the included nodes is this node");}); @@ -62,10 +63,10 @@ public class ChannelNode implements IChannelNode { } @Override - public void removeConnection(IChannelNode node, Direction dir) { + public void removeConnection(IChannelNode node, Direction dir) throws IllegalArgumentException { if(node == null) throw new IllegalArgumentException("node is null"); if(node == this) throw new IllegalArgumentException("node is self"); - if(dir == null) throw new IllegalStateException("dir is null"); + if(dir == null) throw new IllegalArgumentException("dir is null"); int dv = dir.getVal(); if(dv >= Direction.INCOMING.getVal()) incoming.put(node, Math.max(incoming.get(node) - 1, 0)); @@ -73,7 +74,7 @@ public class ChannelNode implements IChannelNode { } @Override - public void removeConnections(Iterable nodes, Direction dir) { + public void removeConnections(Iterable nodes, Direction dir) throws IllegalArgumentException { if(nodes == null) throw new IllegalArgumentException("node is null"); if(dir == null) throw new IllegalArgumentException("dir is null"); nodes.forEach((node) -> {if(node == this) throw new IllegalArgumentException("one of the included nodes is this node");}); @@ -89,7 +90,7 @@ public class ChannelNode implements IChannelNode { } @Override - public void clearConnections(Direction dir) { + public void clearConnections(Direction dir) throws IllegalArgumentException { if(dir == null) throw new IllegalArgumentException("dir is null"); int dv = dir.getVal(); @@ -98,7 +99,7 @@ public class ChannelNode implements IChannelNode { } @Override - public boolean connectionExists(IChannelNode node, Direction dir) { + public boolean connectionExists(IChannelNode node, Direction dir) throws IllegalArgumentException { if(node == null) throw new IllegalArgumentException("node is null"); if(dir == null) throw new IllegalArgumentException("dir is null"); @@ -111,7 +112,9 @@ public class ChannelNode implements IChannelNode { } @Override - public int getNumConnections(Direction dir) { + public int getNumConnections(Direction dir) throws IllegalArgumentException { + if(dir == null) throw new IllegalArgumentException("dir is null"); + int total = 0; int dv = dir.getVal(); @@ -131,7 +134,7 @@ public class ChannelNode implements IChannelNode { } @Override - public List> getConnections(Direction dir) { + public List> getConnections(Direction dir) throws IllegalArgumentException { if(dir == null) throw new IllegalArgumentException("dir is null"); int dv = dir.getVal(); @@ -143,7 +146,7 @@ public class ChannelNode implements IChannelNode { } @Override - public int compareTo(IChannelNode iChannelNode) { + public int compareTo(IChannelNode iChannelNode) throws IllegalArgumentException { if(iChannelNode == null) throw new IllegalArgumentException("comparison node is null"); int selfTotal = getNumConnections(Direction.BOTH), theirTotal = iChannelNode.getNumConnections(Direction.BOTH); -- cgit v1.2.3