Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See License.txt in the project root for license information.
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for * license information. */
package com.microsoft.azure.arm.dag; import java.util.ArrayList; import java.util.Collections; import java.util.List;
Type represents a node in a Graph.
Type parameters:
  • <DataT> – the type of the data stored in the node
  • <NodeT> – the type of the node
/** * Type represents a node in a {@link Graph}. * * @param <DataT> the type of the data stored in the node * @param <NodeT> the type of the node */
public class Node<DataT, NodeT extends Node<DataT, NodeT>> {
The graph that owns this node.
/** * The graph that owns this node. */
private Graph<DataT, NodeT> ownerGraph;
A key that uniquely identifies this node in the owner graph this#ownerGraph.
/** * A key that uniquely identifies this node in the owner graph {@link this#ownerGraph}. */
private final String key;
reference to the data stored in the node.
/** * reference to the data stored in the node. */
private final DataT data;
the collection of child node keys.
/** * the collection of child node keys. */
private List<String> children;
Creates a graph node.
Params:
  • key – unique id of the node
  • data – data to be stored in the node
/** * Creates a graph node. * * @param key unique id of the node * @param data data to be stored in the node */
public Node(final String key, final DataT data) { this.key = key; this.data = data; this.children = new ArrayList<>(); }
Returns:this node's unique id
/** * @return this node's unique id */
public String key() { return this.key; }
Returns:data stored in this node
/** * @return data stored in this node */
public DataT data() { return data; }
Returns:true if this node has any children
/** * @return <tt>true</tt> if this node has any children */
public boolean hasChildren() { return !this.children.isEmpty(); }
Returns:children (neighbours) of this node
/** * @return children (neighbours) of this node */
public List<String> children() { return Collections.unmodifiableList(this.children); }
Params:
  • childKey – add a child (neighbour) of this node
/** * @param childKey add a child (neighbour) of this node */
public void addChild(String childKey) { this.children.add(childKey); }
Params:
  • childKey – remove child (neighbour) of this node
/** * @param childKey remove child (neighbour) of this node */
public void removeChild(String childKey) { this.children.remove(childKey); }
Sets reference to the graph owning this node.
Params:
  • ownerGraph – the owning graph
/** * Sets reference to the graph owning this node. * * @param ownerGraph the owning graph */
public void setOwner(Graph<DataT, NodeT> ownerGraph) { if (this.ownerGraph != null) { throw new RuntimeException("Changing owner graph is not allowed"); } this.ownerGraph = ownerGraph; }
Returns:the owner (container) graph of this node.
/** * @return the owner (container) graph of this node. */
public Graph<DataT, NodeT> owner() { if (this.ownerGraph == null) { throw new RuntimeException("Required owner graph is not set"); } return this.ownerGraph; } }