Java - Help creating an object of my type from other classes

1

I'm new to SO. I need a help or a tip with this problem that I have. I do not need a complete solution, nor code. If not just help how to think or start.

I have 3 predefined classes:

  • GraphDescriptor
  • NodeDescriptor
  • LinkDescriptor

GraphDescriptor:

public class GraphDescriptor {
    public Set<NodeDescriptor> nodes;

    public GraphDescriptor() {
        nodes = new HashSet<NodeDescriptor>();
    }

    public Set<NodeDescriptor> getNodes() {
        return nodes;
    }

    public void setNodes(Set<NodeDescriptor> nodes) {
        this.nodes = nodes;
    }
}

NodeDescriptor:

public class NodeDescriptor {
    private Set<LinkDescriptor> links;

    public NodeDescriptor() {
        links = new HashSet<LinkDescriptor>();
    }

    public Set<LinkDescriptor> getLinks() {
        return links;
    }

    public void setLinks(Set<LinkDescriptor> links) {
        this.links = links;
    }
}

LinkDescriptor:

public class LinkDescriptor {
    private NodeDescriptor sourceNode; //a Descriptor for the source node of the link
    private NodeDescriptor destinationNode; // a Descriptor for the destination node of the link

    public LinkDescriptor() {
    }

    public NodeDescriptor getSourceNode() {
        return sourceNode;
    }

    public void setSourceNode(NodeDescriptor sourceNode) {
        this.sourceNode = sourceNode;
    }

    public NodeDescriptor getDestinationNode() {
        return destinationNode;
    }

    public void setDestinationNode(NodeDescriptor destinationNode) {
        this.destinationNode = destinationNode;
    }

}

On the other hand I have MY classes: myGraph, Nodes, Links, Node and Link:

myGraph:

        public class MyGraph {

            protected Nodes nodes;
            protected Links links;
            protected String name;

            public Nodes getNodes() {
                return nodes;
            }

            public void setNodes(Nodes value) {
                this.nodes = value;
            }

            public Links getLinks() {
                return links;
            }

           public void setLinks(Links value) {
                this.links = value;
            }

            public String getName() {
                return name;
            }

            public void setName(String value) {
                this.name = value;
           }
    }

Nodes:

    public class Nodes {

        protected List<Nodes.Node> node;

        public List<Nodes.Node> getNode() {
            if (node == null) {
                node = new ArrayList<Nodes.Node>();
            }
            return this.node;
        }

Node:

        public static class Node {

            protected String name;

            public String getName() {
                return name;
            }

            public void setName(String value) {
                this.name = value;
            }
    }

Links:

        public class Links {

            protected List<Links.Link> link;

            public List<Links.Link> getLink() {
                if (link == null) {
                    link = new ArrayList<Links.Link>();
                }
                return this.link;
            }
    }

Link

public static class Link {

        protected String name;
        protected String source;
        protected String destination;


        public String getName() {
            return name;
        }

        public void setName(String value) {
            this.name = value;
        }
        public String getSource() {
            return source;
        }

        public void setSource(String value) {
            this.source = value;
        }

        public String getDestination() {
            return destination;
        }

        public void setDestination(String value) {
            this.destination = value;
        }
}

What I need is CREATE AN OBJECT OF MY TYPE (MyGraph) given a GraphDescriptor object.

The problem is that the descriptor objects (Node or Link) do not have a name or identification and I can not find a way to interconnect them.

First, I can start by creating a MyGraph object, then I can create a new Node for each NodeDescriptor belonging to the NodeDescriptors set of the GraphDescriptor.

Afterwards, for each NodeDescriptor I can go through its set of LinkDescriptors, set this node as source and create a new node as a destination. And continue like this until the last node.

But in the end I will have these nodes each connected with links with their new nodes but between these there will be no connection. That is, I will not have a complete system, but several mini systems not connected. That's the problem, I do not know how to join or connect them.

I hope the doubt has been clear and anything you can ask me. Thanks !!

(I translated the question, since it was in English and this is SOes.)

    
asked by JuliaS1887 18.01.2018 в 10:41
source

0 answers