123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package holeg.model;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.logging.Logger;
- import java.util.stream.Stream;
- public class GroupNode extends AbstractCanvasObject {
- private static final Logger log = Logger.getLogger(AbstractCanvasObject.class.getName());
- private ArrayList<HolonObject> objectList = new ArrayList<>();
- private ArrayList<HolonSwitch> switchList = new ArrayList<>();
- private ArrayList<Node> nodeList = new ArrayList<>();
- private ArrayList<GroupNode> groupNodeList = new ArrayList<>();
- public GroupNode(String nodeName) {
- super(nodeName);
- this.setSav("CVS");
- }
- @Override
- public void initForReflection() {
- log.info("Executed");
- objectList = new ArrayList<>();
- switchList = new ArrayList<>();
- nodeList = new ArrayList<>();
- groupNodeList = new ArrayList<>();
- }
- public void addAll(Stream<AbstractCanvasObject> stream) {
- stream.forEach(obj -> add(obj));
- }
- public void addAll(Collection<AbstractCanvasObject> collection) {
- collection.forEach(obj -> add(obj));
- }
-
- public void add(AbstractCanvasObject object) {
- if (object instanceof HolonObject hObject) {
- objectList.add(hObject);
- }else if(object instanceof HolonSwitch hSwitch) {
- switchList.add(hSwitch);
- }else if(object instanceof Node node) {
- nodeList.add(node);
- }else if(object instanceof GroupNode groupNode) {
- groupNodeList.add(groupNode);
- }
- object.setGroupNode(this);
- }
-
- public void remove(AbstractCanvasObject object) {
- if (object instanceof HolonObject hObject) {
- objectList.remove(hObject);
- }else if(object instanceof HolonSwitch hSwitch) {
- switchList.remove(hSwitch);
- }else if(object instanceof Node node) {
- nodeList.remove(node);
- }else if(object instanceof GroupNode groupNode) {
- groupNodeList.remove(groupNode);
- }
- object.setGroupNode(null);
- }
-
- public Stream<AbstractCanvasObject> getObjectsInThisLayer() {
- return Stream.of(objectList.stream(), switchList.stream(), nodeList.stream(), groupNodeList.stream())
- .flatMap(s -> s);
- }
- public Stream<AbstractCanvasObject> getAllObjectsRecursive() {
- Stream<AbstractCanvasObject> objects = Stream.of(objectList.stream(), switchList.stream(), nodeList.stream())
- .flatMap(s -> s);
- return Stream.concat(objects,
- groupNodeList.stream().flatMap(groupnode -> groupnode.getObjectsInThisLayer()));
- }
- public Stream<HolonObject> getAllHolonObjectsRecursive() {
- return Stream.concat(objectList.stream(),
- groupNodeList.stream().flatMap(groupnode -> groupnode.getAllHolonObjectsRecursive()));
- }
- public Stream<HolonSwitch> getAllSwitchObjectsRecursive() {
- return Stream.concat(switchList.stream(),
- groupNodeList.stream().flatMap(groupnode -> groupnode.getAllSwitchObjectsRecursive()));
- }
- public Stream<Node> getAllNodeObjectsRecursive() {
- return Stream.concat(nodeList.stream(),
- groupNodeList.stream().flatMap(groupnode -> groupnode.getAllNodeObjectsRecursive()));
- }
- public Stream<GroupNode> getAllGroupNodeObjectsRecursive() {
- return Stream.concat(groupNodeList.stream(),
- groupNodeList.stream().flatMap(groupnode -> groupnode.getAllGroupNodeObjectsRecursive()));
- }
-
- public Stream<HolonObject> getHolonObjects() {
- return objectList.stream();
- }
-
- public Stream<HolonSwitch> getSwitches() {
- return switchList.stream();
- }
- public Stream<Node> getNodes() {
- return nodeList.stream();
- }
-
- public Stream<GroupNode> getGroupNodes() {
- return groupNodeList.stream();
- }
-
- public void clear() {
- objectList.clear();
- switchList.clear();
- nodeList.clear();
- groupNodeList.clear();
- }
- }
|