GroupNode.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package holeg.model;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import java.util.logging.Logger;
  5. import java.util.stream.Stream;
  6. public class GroupNode extends AbstractCanvasObject {
  7. private static final Logger log = Logger.getLogger(AbstractCanvasObject.class.getName());
  8. private ArrayList<HolonObject> objectList = new ArrayList<>();
  9. private ArrayList<HolonSwitch> switchList = new ArrayList<>();
  10. private ArrayList<Node> nodeList = new ArrayList<>();
  11. private ArrayList<GroupNode> groupNodeList = new ArrayList<>();
  12. public GroupNode(String nodeName) {
  13. super(nodeName);
  14. this.setSav("CVS");
  15. }
  16. @Override
  17. public void initForReflection() {
  18. log.info("Executed");
  19. objectList = new ArrayList<>();
  20. switchList = new ArrayList<>();
  21. nodeList = new ArrayList<>();
  22. groupNodeList = new ArrayList<>();
  23. }
  24. public void addAll(Stream<AbstractCanvasObject> stream) {
  25. stream.forEach(obj -> add(obj));
  26. }
  27. public void addAll(Collection<AbstractCanvasObject> collection) {
  28. collection.forEach(obj -> add(obj));
  29. }
  30. public void add(AbstractCanvasObject object) {
  31. if (object instanceof HolonObject hObject) {
  32. objectList.add(hObject);
  33. }else if(object instanceof HolonSwitch hSwitch) {
  34. switchList.add(hSwitch);
  35. }else if(object instanceof Node node) {
  36. nodeList.add(node);
  37. }else if(object instanceof GroupNode groupNode) {
  38. groupNodeList.add(groupNode);
  39. }
  40. object.setGroupNode(this);
  41. }
  42. public void remove(AbstractCanvasObject object) {
  43. if (object instanceof HolonObject hObject) {
  44. objectList.remove(hObject);
  45. }else if(object instanceof HolonSwitch hSwitch) {
  46. switchList.remove(hSwitch);
  47. }else if(object instanceof Node node) {
  48. nodeList.remove(node);
  49. }else if(object instanceof GroupNode groupNode) {
  50. groupNodeList.remove(groupNode);
  51. }
  52. object.setGroupNode(null);
  53. }
  54. public Stream<AbstractCanvasObject> getObjectsInThisLayer() {
  55. return Stream.of(objectList.stream(), switchList.stream(), nodeList.stream(), groupNodeList.stream())
  56. .flatMap(s -> s);
  57. }
  58. public Stream<AbstractCanvasObject> getAllObjectsRecursive() {
  59. Stream<AbstractCanvasObject> objects = Stream.of(objectList.stream(), switchList.stream(), nodeList.stream())
  60. .flatMap(s -> s);
  61. return Stream.concat(objects,
  62. groupNodeList.stream().flatMap(groupnode -> groupnode.getObjectsInThisLayer()));
  63. }
  64. public Stream<HolonObject> getAllHolonObjectsRecursive() {
  65. return Stream.concat(objectList.stream(),
  66. groupNodeList.stream().flatMap(groupnode -> groupnode.getAllHolonObjectsRecursive()));
  67. }
  68. public Stream<HolonSwitch> getAllSwitchObjectsRecursive() {
  69. return Stream.concat(switchList.stream(),
  70. groupNodeList.stream().flatMap(groupnode -> groupnode.getAllSwitchObjectsRecursive()));
  71. }
  72. public Stream<Node> getAllNodeObjectsRecursive() {
  73. return Stream.concat(nodeList.stream(),
  74. groupNodeList.stream().flatMap(groupnode -> groupnode.getAllNodeObjectsRecursive()));
  75. }
  76. public Stream<GroupNode> getAllGroupNodeObjectsRecursive() {
  77. return Stream.concat(groupNodeList.stream(),
  78. groupNodeList.stream().flatMap(groupnode -> groupnode.getAllGroupNodeObjectsRecursive()));
  79. }
  80. public Stream<HolonObject> getHolonObjects() {
  81. return objectList.stream();
  82. }
  83. public Stream<HolonSwitch> getSwitches() {
  84. return switchList.stream();
  85. }
  86. public Stream<Node> getNodes() {
  87. return nodeList.stream();
  88. }
  89. public Stream<GroupNode> getGroupNodes() {
  90. return groupNodeList.stream();
  91. }
  92. public void clear() {
  93. objectList.clear();
  94. switchList.clear();
  95. nodeList.clear();
  96. groupNodeList.clear();
  97. }
  98. }