📄 simplemessage.java
字号:
/** * implementations/SimpleMessage.java */package implementations;import java.util.ArrayList;import simulator.Message;import simulator.Node;/** * */public class SimpleMessage extends Message{ private int copiesToMake = 1; // Not actually sent over contacts, but used locally in nodes to mark nodes // which already received the message. private ArrayList<Node> nodesWithCopy = new ArrayList<Node>(); public SimpleMessage(int id, double creationTime, Node source, Node dest, int dLen) { super(id, creationTime, source, dest, dLen); } public SimpleMessage(SimpleMessage org) { super(org); // New copy will "receive" half of copies number, // and this node will leave the rest for itself copiesToMake = org.copiesToMake / 2; org.copiesToMake = org.copiesToMake - copiesToMake; } public void setCopiesToMake(int c) { if (c > 0) copiesToMake = c; } public int getCopiesToMake() { return copiesToMake; } public void removeNodeWithCopy(Node n) { nodesWithCopy.remove(n); } public void addNodeWithCopy(Node n) { if (!nodesWithCopy.contains(n)) nodesWithCopy.add(n); } public boolean hasCopy(Node n) { return nodesWithCopy.contains(n); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -