diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/ChannelNode.java | 25 |
1 files 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 { | |||
| 26 | @Override | 26 | @Override |
| 27 | public void setNumConnections(IChannelNode node, Direction dir, int num) throws IllegalArgumentException { | 27 | public void setNumConnections(IChannelNode node, Direction dir, int num) throws IllegalArgumentException { |
| 28 | if(node == null) throw new IllegalArgumentException("node is null"); | 28 | if(node == null) throw new IllegalArgumentException("node is null"); |
| 29 | if(node == this) throw new IllegalArgumentException("node is self"); | ||
| 29 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 30 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 30 | if(num < 0) throw new IllegalArgumentException("num < 0"); | 31 | if(num < 0) throw new IllegalArgumentException("num < 0"); |
| 31 | 32 | ||
| @@ -35,10 +36,10 @@ public class ChannelNode implements IChannelNode { | |||
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | @Override | 38 | @Override |
| 38 | public void addConnection(IChannelNode node, Direction dir) { | 39 | public void addConnection(IChannelNode node, Direction dir) throws IllegalArgumentException { |
| 39 | if(node == null) throw new IllegalArgumentException("node is null"); | 40 | if(node == null) throw new IllegalArgumentException("node is null"); |
| 40 | if(node == this) throw new IllegalArgumentException("node is self"); | 41 | if(node == this) throw new IllegalArgumentException("node is self"); |
| 41 | if(dir == null) throw new IllegalStateException("dir is null"); | 42 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 42 | 43 | ||
| 43 | int dv = dir.getVal(); | 44 | int dv = dir.getVal(); |
| 44 | if(dv >= Direction.INCOMING.getVal()) incoming.put(node, incoming.get(node) + 1); | 45 | if(dv >= Direction.INCOMING.getVal()) incoming.put(node, incoming.get(node) + 1); |
| @@ -46,7 +47,7 @@ public class ChannelNode implements IChannelNode { | |||
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | @Override | 49 | @Override |
| 49 | public void addConnections(Iterable<IChannelNode> nodes, Direction dir) { | 50 | public void addConnections(Iterable<IChannelNode> nodes, Direction dir) throws IllegalArgumentException { |
| 50 | if(nodes == null) throw new IllegalArgumentException("node is null"); | 51 | if(nodes == null) throw new IllegalArgumentException("node is null"); |
| 51 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 52 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 52 | nodes.forEach((node) -> {if(node == this) throw new IllegalArgumentException("one of the included nodes is this node");}); | 53 | 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 { | |||
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | @Override | 65 | @Override |
| 65 | public void removeConnection(IChannelNode node, Direction dir) { | 66 | public void removeConnection(IChannelNode node, Direction dir) throws IllegalArgumentException { |
| 66 | if(node == null) throw new IllegalArgumentException("node is null"); | 67 | if(node == null) throw new IllegalArgumentException("node is null"); |
| 67 | if(node == this) throw new IllegalArgumentException("node is self"); | 68 | if(node == this) throw new IllegalArgumentException("node is self"); |
| 68 | if(dir == null) throw new IllegalStateException("dir is null"); | 69 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 69 | 70 | ||
| 70 | int dv = dir.getVal(); | 71 | int dv = dir.getVal(); |
| 71 | if(dv >= Direction.INCOMING.getVal()) incoming.put(node, Math.max(incoming.get(node) - 1, 0)); | 72 | if(dv >= Direction.INCOMING.getVal()) incoming.put(node, Math.max(incoming.get(node) - 1, 0)); |
| @@ -73,7 +74,7 @@ public class ChannelNode implements IChannelNode { | |||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | @Override | 76 | @Override |
| 76 | public void removeConnections(Iterable<IChannelNode> nodes, Direction dir) { | 77 | public void removeConnections(Iterable<IChannelNode> nodes, Direction dir) throws IllegalArgumentException { |
| 77 | if(nodes == null) throw new IllegalArgumentException("node is null"); | 78 | if(nodes == null) throw new IllegalArgumentException("node is null"); |
| 78 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 79 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 79 | nodes.forEach((node) -> {if(node == this) throw new IllegalArgumentException("one of the included nodes is this node");}); | 80 | 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 { | |||
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | @Override | 92 | @Override |
| 92 | public void clearConnections(Direction dir) { | 93 | public void clearConnections(Direction dir) throws IllegalArgumentException { |
| 93 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 94 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 94 | 95 | ||
| 95 | int dv = dir.getVal(); | 96 | int dv = dir.getVal(); |
| @@ -98,7 +99,7 @@ public class ChannelNode implements IChannelNode { | |||
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | @Override | 101 | @Override |
| 101 | public boolean connectionExists(IChannelNode node, Direction dir) { | 102 | public boolean connectionExists(IChannelNode node, Direction dir) throws IllegalArgumentException { |
| 102 | if(node == null) throw new IllegalArgumentException("node is null"); | 103 | if(node == null) throw new IllegalArgumentException("node is null"); |
| 103 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 104 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 104 | 105 | ||
| @@ -111,7 +112,9 @@ public class ChannelNode implements IChannelNode { | |||
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | @Override | 114 | @Override |
| 114 | public int getNumConnections(Direction dir) { | 115 | public int getNumConnections(Direction dir) throws IllegalArgumentException { |
| 116 | if(dir == null) throw new IllegalArgumentException("dir is null"); | ||
| 117 | |||
| 115 | int total = 0; | 118 | int total = 0; |
| 116 | int dv = dir.getVal(); | 119 | int dv = dir.getVal(); |
| 117 | 120 | ||
| @@ -131,7 +134,7 @@ public class ChannelNode implements IChannelNode { | |||
| 131 | } | 134 | } |
| 132 | 135 | ||
| 133 | @Override | 136 | @Override |
| 134 | public List<Map<IChannelNode, Integer>> getConnections(Direction dir) { | 137 | public List<Map<IChannelNode, Integer>> getConnections(Direction dir) throws IllegalArgumentException { |
| 135 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 138 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 136 | 139 | ||
| 137 | int dv = dir.getVal(); | 140 | int dv = dir.getVal(); |
| @@ -143,7 +146,7 @@ public class ChannelNode implements IChannelNode { | |||
| 143 | } | 146 | } |
| 144 | 147 | ||
| 145 | @Override | 148 | @Override |
| 146 | public int compareTo(IChannelNode iChannelNode) { | 149 | public int compareTo(IChannelNode iChannelNode) throws IllegalArgumentException { |
| 147 | if(iChannelNode == null) throw new IllegalArgumentException("comparison node is null"); | 150 | if(iChannelNode == null) throw new IllegalArgumentException("comparison node is null"); |
| 148 | int selfTotal = getNumConnections(Direction.BOTH), | 151 | int selfTotal = getNumConnections(Direction.BOTH), |
| 149 | theirTotal = iChannelNode.getNumConnections(Direction.BOTH); | 152 | theirTotal = iChannelNode.getNumConnections(Direction.BOTH); |
