Package com.storedobject.chart
Class GraphData.Node
java.lang.Object
com.storedobject.chart.GraphData.Node
- All Implemented Interfaces:
ComponentPart
,ComponentProperty
- Direct Known Subclasses:
GraphData.ValueNode
,GraphData.XYNode
- Enclosing class:
GraphData<N extends GraphData.Node>
The abstract class Node serves as the base class for components within a graph structure.
It represents a single node entity that can be connected to other nodes via edges and contains
functionality to manage its own metadata and relationships.
This class ensures each node has a unique identifier, a name, a category, and a list of edges.
Nodes can be connected to other nodes and can serialize themselves into JSON format.
- Author:
- Syam
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconnectTo
(GraphData.Node target) Connects the current node to the specified target node by creating an edge between them.void
Encode the JSON string with the properties of this.Retrieves the category associated with this node.final long
getId()
Each part should have a unique Id.final String
getName()
Retrieves the name of the node.int
Get the current serial number (Serial number used for internal purposes only).void
setCategory
(GraphData.Category category) Sets the category associated with this node.void
Sets the name of this node.void
setSerial
(int serial) Set a serial number (Serial number used for internal purposes only).final Stream
<GraphData.Edge> Streams the edges associated with this node as aStream
.void
validate()
This method is invoked bySOChart
to check if the component or part is valid or not.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.storedobject.chart.ComponentPart
className, getRenderingIndex, setRenderingIndex
-
Field Details
-
name
-
-
Constructor Details
-
Node
public Node()
-
-
Method Details
-
getCategory
Retrieves the category associated with this node.- Returns:
- The category of this node.
-
setCategory
Sets the category associated with this node.- Parameters:
category
- The category to be associated with this node.
-
connectTo
Connects the current node to the specified target node by creating an edge between them. If an edge already exists between the current node and the target node, it is returned. Otherwise, a new edge is created, added to the current node's list of edges, and returned.- Parameters:
target
- The target node to which a connection is to be established. May not be null.- Returns:
- The
Edge
object representing the connection to the target node, ornull
if the target node is null.
-
getName
Retrieves the name of the node.- Specified by:
getName
in interfaceComponentPart
- Returns:
- the name of the node as a String.
-
setName
Sets the name of this node.- Specified by:
setName
in interfaceComponentPart
- Parameters:
name
- The name to be set for this node.
-
getId
public final long getId()Description copied from interface:ComponentPart
Each part should have a unique Id. (It can be a final variable and can be set by callingID.newID()
.- Specified by:
getId
in interfaceComponentPart
- Returns:
- Unique Id.
-
setSerial
public void setSerial(int serial) Description copied from interface:ComponentPart
Set a serial number (Serial number used for internal purposes only). The implementation of this method must be in such a way that the serial number set here must be returned by theComponentPart.getSerial()
method.- Specified by:
setSerial
in interfaceComponentPart
- Parameters:
serial
- Serial number to set.
-
getSerial
public int getSerial()Description copied from interface:ComponentPart
Get the current serial number (Serial number used for internal purposes only). The serial number set by theComponentPart.setSerial(int)
method should be returned by this method.- Specified by:
getSerial
in interfaceComponentPart
- Returns:
- Current serial number.
-
validate
Description copied from interface:ComponentPart
This method is invoked bySOChart
to check if the component or part is valid or not.- Specified by:
validate
in interfaceComponentPart
- Throws:
ChartException
- Raises exception if the component or part is not valid.
-
streamEdges
Streams the edges associated with this node as aStream
.- Returns:
- A
Stream
ofEdge
objects representing the edges of this node.
-
encodeJSON
Description copied from interface:ComponentProperty
Encode the JSON string with the properties of this.- Specified by:
encodeJSON
in interfaceComponentProperty
- Parameters:
sb
- Encoded JSON string to be appended to this.
-