1 package org.codehaus.plexus.util.dag;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
22
23
24
25
26
27 public class Vertex
28 implements Cloneable, Serializable
29 {
30
31
32
33 private String label = null;
34
35 List<Vertex> children = new ArrayList<>();
36
37 List<Vertex> parents = new ArrayList<>();
38
39
40
41
42
43 public Vertex( final String label )
44 {
45 this.label = label;
46 }
47
48
49
50
51
52 public String getLabel()
53 {
54 return label;
55 }
56
57 public void addEdgeTo( final Vertex vertex )
58 {
59 children.add( vertex );
60 }
61
62 public void removeEdgeTo( final Vertex vertex )
63 {
64 children.remove( vertex );
65 }
66
67 public void addEdgeFrom( final Vertex vertex )
68 {
69 parents.add( vertex );
70 }
71
72 public void removeEdgeFrom( final Vertex vertex )
73 {
74 parents.remove( vertex );
75 }
76
77 public List<Vertex> getChildren()
78 {
79 return children;
80 }
81
82
83
84
85
86
87 public List<String> getChildLabels()
88 {
89 final List<String> retValue = new ArrayList<>( children.size() );
90
91 for ( Vertex vertex : children )
92 {
93 retValue.add( vertex.getLabel() );
94 }
95 return retValue;
96 }
97
98
99
100
101
102
103 public List<Vertex> getParents()
104 {
105 return parents;
106 }
107
108
109
110
111
112
113 public List<String> getParentLabels()
114 {
115 final List<String> retValue = new ArrayList<>( parents.size() );
116
117 for ( Vertex vertex : parents )
118 {
119 retValue.add( vertex.getLabel() );
120 }
121 return retValue;
122 }
123
124
125
126
127
128
129 public boolean isLeaf()
130 {
131 return children.size() == 0;
132 }
133
134
135
136
137
138
139 public boolean isRoot()
140 {
141 return parents.size() == 0;
142 }
143
144
145
146
147
148
149 public boolean isConnected()
150 {
151 return isRoot() || isLeaf();
152 }
153
154 @Override
155 public Object clone()
156 throws CloneNotSupportedException
157 {
158
159 final Object retValue = super.clone();
160
161 return retValue;
162 }
163
164 @Override
165 public String toString()
166 {
167 return "Vertex{" + "label='" + label + "'" + "}";
168 }
169
170 }