Package com.graphs.struct
Class Graph.Vertex<E extends T>
java.lang.Object
com.graphs.struct.Graph.Vertex<E>
- Type Parameters:
E
- the type of element stored in this vertex.
This inner class implements vertices of this graph.
- Since:
- 1.0-beta
- See Also:
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprivate
Vertex
(int index) This constructor creates vertex based on a givenint
parameter. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
canConnectWith
(Graph<T>.Vertex<E> vertex) This method checks if this vertex can be connected to the vertex given as a parameter.private boolean
canDisconnectWith
(Graph<T>.Vertex<E> vertex) This method check if this vertex can be disconnected with the vertex given as a parameter.private boolean
connectWith
(Graph<T>.Vertex<E> vertex) This method connects this vertex with other givenVertex
.private boolean
disconnectWith
(Graph<T>.Vertex<E> vertex) This method disconnects this vertex with other givenVertex
.private int
This method returns the degree of this vertex.private boolean
isConnectedWith
(Graph<T>.Vertex<E> vertex) This method checks whether this vertex is connected with other givenVertex
or is not.@NotNull String
toString()
-
Field Details
-
index
private final int indexThis field represents the index of a vertex. Once initialized, it cannot be changed.Minimal value: 0 Maximal value:
Integer.MAX_VALUE
- Since:
- 1.0-beta
-
neighbours
This field represents (open) neighbourhood of this vertex.- Since:
- 1.0-beta
- See Also:
-
element
This field represents data stored in this vertex.- Since:
- 2.0
- See Also:
-
-
Constructor Details
-
Vertex
This constructor creates vertex based on a givenint
parameter.- Parameters:
index
- numerical index of a vertex.- Throws:
NegativeVertexIndexException
- if given parameter typeint < 0
.- Since:
- 1.0-beta
- See Also:
-
-
Method Details
-
getDegree
private int getDegree()This method returns the degree of this vertex.- Returns:
- number of vertices in an open neighbourhood of this vertex.
- Since:
- 1.0-beta
- See Also:
-
isConnectedWith
This method checks whether this vertex is connected with other givenVertex
or is not.- Parameters:
vertex
- a different vertex that is possibly adjacent to this vertex.- Returns:
true
if vertices are adjacent,false
otherwise.- Since:
- 1.0-beta
-
connectWith
This method connects this vertex with other givenVertex
. They connect only if they are not the same vertex and if they are not connected yet.- Parameters:
vertex
- a vertex to be adjacent to this vertex.- Returns:
true
if this vertex has been connected with givenVertex
,false
otherwise.- Since:
- 1.0-beta
- See Also:
-
canConnectWith
This method checks if this vertex can be connected to the vertex given as a parameter.- Parameters:
vertex
- a vertex to check if it can be connected with this vertex.- Returns:
true
if vertices can be connected,false
otherwise.- Since:
- 1.1
-
canDisconnectWith
This method check if this vertex can be disconnected with the vertex given as a parameter.- Parameters:
vertex
- - a vertex to check if it can be disconnected with this vertex.- Returns:
true
if vertices can be disconnected,false
otherwise.- Since:
- 1.1
-
disconnectWith
This method disconnects this vertex with other givenVertex
. They disconnect only if they are not the same vertex and if they are already connected.- Parameters:
vertex
- a vertex to be disconnected with this vertex.- Returns:
true
if this vertex has been disconnected with givenVertex
,false
otherwise.- Since:
- 1.0-beta
- See Also:
-
toString
-