1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import java.util.List;
import java.util.Map;
public interface IChannelNode extends Comparable<IChannelNode> {
enum Direction {
INCOMING(1 << 0), // Users incoming from outside channel (aka: other channel forwarded this channel's post)
OUTGOING(1 << 1), // Users outgoing from this channel (aka: this channel forwarded someone else's post)
BOTH(INCOMING.val | OUTGOING.val); // Modify both incoming and outgoing counts at once
private final int val;
Direction(int val) {this.val = val;}
public int getVal() {return this.val;}
public interface callback {
void cb();
}
public static void overVals(Map<Direction, callback> cmap, Direction dir) throws IllegalArgumentException {
if(cmap == null) throw new IllegalArgumentException("callback map is null");
if(dir == null) throw new IllegalArgumentException("dir is null");
for(Direction cdir: cmap.keySet()) if(cdir == null) throw new IllegalArgumentException("One of the directions is null");
for(callback cb: cmap.values()) if(cb == null) throw new IllegalArgumentException("One of the callbacks is null");
// For each direction in the map, check that the given direction is gte, and if so run the callback
for(Direction cdir: cmap.keySet())
if((dir.getVal() & cdir.getVal()) > 0)
cmap.get(cdir).cb();
}
// This is hilariously overengineered because java fucking sucks my entire cock and balls
// Barely even saves any space too
}
void setConnections(Map<IChannelNode, Integer> conmap, Direction dir);
void setNumConnections(IChannelNode node, Direction dir, int num);
void addConnection(IChannelNode node, Direction dir);
void addConnections(Iterable<IChannelNode> nodes, Direction dir);
void removeConnection(IChannelNode node, Direction dir);
void removeConnections(Iterable<IChannelNode> nodes, Direction dir);
void clearConnections();
boolean connectionExists(IChannelNode node, Direction dir);
int getNumConnections(Direction dir);
Map<IChannelNode, Integer> getIncomingConnections();
Map<IChannelNode, Integer> getOutgoingConnections();
List<Map<IChannelNode, Integer>> getConnections(Direction dir);
}
|