diff options
| author | @syxhe <t.me/syxhe> | 2025-10-02 19:05:32 -0500 |
|---|---|---|
| committer | @syxhe <t.me/syxhe> | 2025-10-02 19:05:32 -0500 |
| commit | 3de3a9d4ca7b188abb0411c9e0a484ed2561a4b7 (patch) | |
| tree | a1e98915a810354e51ef2a82e616d586702b522a /src/main | |
| parent | 82c6f12de286db3c89758f201f619a63accf17f4 (diff) | |
Wrangle with test cases
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/ChannelNode.java | 19 | ||||
| -rw-r--r-- | src/main/java/IChannelNode.java | 10 |
2 files changed, 13 insertions, 16 deletions
diff --git a/src/main/java/ChannelNode.java b/src/main/java/ChannelNode.java index 20a7ac0..6c2e9a3 100644 --- a/src/main/java/ChannelNode.java +++ b/src/main/java/ChannelNode.java | |||
| @@ -43,8 +43,8 @@ public class ChannelNode implements IChannelNode { | |||
| 43 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 43 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 44 | 44 | ||
| 45 | Direction.overVals(Map.ofEntries( | 45 | Direction.overVals(Map.ofEntries( |
| 46 | entry(Direction.INCOMING, () -> incoming.put(node, incoming.get(node) + 1)), | 46 | entry(Direction.INCOMING, () -> incoming.put(node, ((incoming.get(node) != null) ? incoming.get(node) : 0) + 1)), |
| 47 | entry(Direction.OUTGOING, () -> outgoing.put(node, outgoing.get(node) + 1)) | 47 | entry(Direction.OUTGOING, () -> outgoing.put(node, ((outgoing.get(node) != null) ? outgoing.get(node) : 0) + 1)) |
| 48 | ), dir); | 48 | ), dir); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| @@ -56,8 +56,8 @@ public class ChannelNode implements IChannelNode { | |||
| 56 | 56 | ||
| 57 | for(IChannelNode node: nodes) { | 57 | for(IChannelNode node: nodes) { |
| 58 | Direction.overVals(Map.ofEntries( | 58 | Direction.overVals(Map.ofEntries( |
| 59 | entry(Direction.INCOMING, () -> incoming.put(node, incoming.get(node) + 1)), | 59 | entry(Direction.INCOMING, () -> incoming.put(node,((incoming.get(node) != null) ? incoming.get(node) : 0) + 1)), |
| 60 | entry(Direction.OUTGOING, () -> outgoing.put(node, outgoing.get(node) + 1)) | 60 | entry(Direction.OUTGOING, () -> outgoing.put(node,((outgoing.get(node) != null) ? outgoing.get(node) : 0) + 1)) |
| 61 | ), dir); | 61 | ), dir); |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| @@ -89,13 +89,10 @@ public class ChannelNode implements IChannelNode { | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | @Override | 91 | @Override |
| 92 | public void clearConnections(Direction dir) throws IllegalArgumentException { | 92 | public void clearConnections() throws IllegalArgumentException { |
| 93 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 93 | // I have no idea why this is throwing an unsupported operation exception |
| 94 | 94 | incoming.clear(); | |
| 95 | Direction.overVals(Map.ofEntries( | 95 | outgoing.clear(); |
| 96 | entry(Direction.INCOMING, () -> incoming.clear()), | ||
| 97 | entry(Direction.OUTGOING, () -> outgoing.clear()) | ||
| 98 | ), dir); | ||
| 99 | } | 96 | } |
| 100 | 97 | ||
| 101 | @Override | 98 | @Override |
diff --git a/src/main/java/IChannelNode.java b/src/main/java/IChannelNode.java index a6446f1..cc1d3e8 100644 --- a/src/main/java/IChannelNode.java +++ b/src/main/java/IChannelNode.java | |||
| @@ -3,9 +3,9 @@ import java.util.Map; | |||
| 3 | 3 | ||
| 4 | public interface IChannelNode extends Comparable<IChannelNode> { | 4 | public interface IChannelNode extends Comparable<IChannelNode> { |
| 5 | enum Direction { | 5 | enum Direction { |
| 6 | INCOMING(1), // Users incoming from outside channel (aka: other channel forwarded this channel's post) | 6 | INCOMING(1 << 0), // Users incoming from outside channel (aka: other channel forwarded this channel's post) |
| 7 | OUTGOING(2), // Users outgoing from this channel (aka: this channel forwarded someone else's post) | 7 | OUTGOING(1 << 1), // Users outgoing from this channel (aka: this channel forwarded someone else's post) |
| 8 | BOTH(3); // Modify both incoming and outgoing counts at once | 8 | BOTH(INCOMING.val | OUTGOING.val); // Modify both incoming and outgoing counts at once |
| 9 | 9 | ||
| 10 | private final int val; | 10 | private final int val; |
| 11 | Direction(int val) {this.val = val;} | 11 | Direction(int val) {this.val = val;} |
| @@ -22,7 +22,7 @@ public interface IChannelNode extends Comparable<IChannelNode> { | |||
| 22 | 22 | ||
| 23 | // For each direction in the map, check that the given direction is gte, and if so run the callback | 23 | // For each direction in the map, check that the given direction is gte, and if so run the callback |
| 24 | for(Direction cdir: cmap.keySet()) | 24 | for(Direction cdir: cmap.keySet()) |
| 25 | if(dir.getVal() >= cdir.getVal()) | 25 | if((dir.getVal() & cdir.getVal()) > 0) |
| 26 | cmap.get(cdir).cb(); | 26 | cmap.get(cdir).cb(); |
| 27 | } | 27 | } |
| 28 | // This is hilariously overengineered because java fucking sucks my entire cock and balls | 28 | // This is hilariously overengineered because java fucking sucks my entire cock and balls |
| @@ -35,7 +35,7 @@ public interface IChannelNode extends Comparable<IChannelNode> { | |||
| 35 | void addConnections(Iterable<IChannelNode> nodes, Direction dir); | 35 | void addConnections(Iterable<IChannelNode> nodes, Direction dir); |
| 36 | void removeConnection(IChannelNode node, Direction dir); | 36 | void removeConnection(IChannelNode node, Direction dir); |
| 37 | void removeConnections(Iterable<IChannelNode> nodes, Direction dir); | 37 | void removeConnections(Iterable<IChannelNode> nodes, Direction dir); |
| 38 | void clearConnections(Direction dir); | 38 | void clearConnections(); |
| 39 | 39 | ||
| 40 | boolean connectionExists(IChannelNode node, Direction dir); | 40 | boolean connectionExists(IChannelNode node, Direction dir); |
| 41 | int getNumConnections(Direction dir); | 41 | int getNumConnections(Direction dir); |
