1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.start.graph;
20
21 import java.util.ArrayList;
22 import java.util.HashSet;
23 import java.util.LinkedHashSet;
24 import java.util.List;
25 import java.util.Set;
26
27
28
29
30
31 public abstract class Node<T>
32 {
33
34 private String logicalName;
35
36 private int depth = 0;
37
38 private Set<Selection> selections = new LinkedHashSet<>();
39
40 private List<String> parentNames = new ArrayList<>();
41
42 private List<String> optionalParentNames = new ArrayList<>();
43
44
45 private Set<T> parentEdges = new LinkedHashSet<>();
46
47 private Set<T> childEdges = new LinkedHashSet<>();
48
49 public void addChildEdge(T child)
50 {
51 if (childEdges.contains(child))
52 {
53
54 return;
55 }
56 this.childEdges.add(child);
57 }
58
59 public void addOptionalParentName(String name)
60 {
61 if (this.optionalParentNames.contains(name))
62 {
63
64 return;
65 }
66 this.optionalParentNames.add(name);
67 }
68
69 public void addParentEdge(T parent)
70 {
71 if (parentEdges.contains(parent))
72 {
73
74 return;
75 }
76 this.parentEdges.add(parent);
77 }
78
79 public void addParentName(String name)
80 {
81 if (this.parentNames.contains(name))
82 {
83
84 return;
85 }
86 this.parentNames.add(name);
87 }
88
89 public void addSelection(Selection selection)
90 {
91 this.selections.add(selection);
92 }
93
94 public Set<T> getChildEdges()
95 {
96 return childEdges;
97 }
98
99 public int getDepth()
100 {
101 return depth;
102 }
103
104 @Deprecated
105 public String getLogicalName()
106 {
107 return logicalName;
108 }
109
110 public String getName()
111 {
112 return logicalName;
113 }
114
115 public List<String> getOptionalParentNames()
116 {
117 return optionalParentNames;
118 }
119
120 public Set<T> getParentEdges()
121 {
122 return parentEdges;
123 }
124
125 public List<String> getParentNames()
126 {
127 return parentNames;
128 }
129
130 public Set<Selection> getSelections()
131 {
132 return selections;
133 }
134
135 public Set<String> getSelectedCriteriaSet()
136 {
137 Set<String> criteriaSet = new HashSet<>();
138 for (Selection selection : selections)
139 {
140 criteriaSet.add(selection.getCriteria());
141 }
142 return criteriaSet;
143 }
144
145 public boolean isSelected()
146 {
147 return !selections.isEmpty();
148 }
149
150 public boolean matches(Predicate predicate)
151 {
152 return predicate.match(this);
153 }
154
155 public void setDepth(int depth)
156 {
157 this.depth = depth;
158 }
159
160 public void setName(String name)
161 {
162 this.logicalName = name;
163 }
164
165 public void setParentNames(List<String> parents)
166 {
167 this.parentNames.clear();
168 this.parentEdges.clear();
169 if (parents != null)
170 {
171 this.parentNames.addAll(parents);
172 }
173 }
174
175 public void setSelections(Set<Selection> selection)
176 {
177 this.selections = selection;
178 }
179 }