@@ -42,13 +42,6 @@ public class NodeRelationshipFinder {
42
42
43
43
private LinkedHashMap <String , NodeRelationship > relationships = new LinkedHashMap <>();
44
44
45
- // Print debug message if 'isDebugEnabled' is true.
46
- private void dump (String message , Object ... args ) {
47
- if (isDebugEnabled ) {
48
- logger .debug (String .format (message , args ));
49
- }
50
- }
51
-
52
45
public NodeRelationshipFinder () {}
53
46
54
47
/**
@@ -57,14 +50,18 @@ public NodeRelationshipFinder() {}
57
50
@ NonNull
58
51
public LinkedHashMap <String , NodeRelationship > getNodeRelationships (
59
52
@ NonNull LinkedHashMap <String , FlowNode > nodeMap ) {
60
- dump ("Original Ids: %s" , String .join (", " , nodeMap .keySet ()));
53
+ if (isDebugEnabled ) {
54
+ logger .debug ("Original Ids: {}" , String .join (", " , nodeMap .keySet ()));
55
+ }
61
56
// This is important, determining the the relationships depends on the order of
62
57
// iteration.
63
58
// If there was a method to tell if a node was a parallel block this might be
64
59
// less of an issue.
65
60
List <String > sortedIds = new ArrayList <>(nodeMap .keySet ());
66
61
Collections .sort (sortedIds , new FlowNodeWrapper .NodeIdComparator ().reversed ());
67
- dump ("Sorted Ids: %s" , String .join (", " , sortedIds ));
62
+ if (isDebugEnabled ) {
63
+ logger .debug ("Sorted Ids: {}" , String .join (", " , sortedIds ));
64
+ }
68
65
for (String id : sortedIds ) {
69
66
getRelationshipForNode (nodeMap .get (id ));
70
67
// Add this node to the parents's stack as the last of it's child nodes that
@@ -90,15 +87,17 @@ private void handleBlockStart(@NonNull FlowNode node) {
90
87
if (FlowNodeWrapper .isStart (node )) {
91
88
addBlockRelationship (node );
92
89
} else {
93
- dump ("Why are we here?? %s - %s " , node .getId (), node .getClass ());
90
+ logger . debug ("Why are we here?? {} - {} " , node .getId (), node .getClass ());
94
91
}
95
92
}
96
93
97
94
private void addSeenNodes (FlowNode node ) {
98
95
if (!seenChildNodes .keySet ().contains (node .getEnclosingId ())) {
99
96
seenChildNodes .put (node .getEnclosingId (), new ArrayDeque <FlowNode >());
100
97
}
101
- dump ("Adding %s to seenChildNodes %s" , node .getId (), node .getEnclosingId ());
98
+ if (isDebugEnabled ) {
99
+ logger .debug ("Adding {} to seenChildNodes {}" , node .getId (), node .getEnclosingId ());
100
+ }
102
101
seenChildNodes .get (node .getEnclosingId ()).push (node );
103
102
}
104
103
@@ -113,9 +112,13 @@ private FlowNode getAfterNode(FlowNode node) {
113
112
// If there are no later siblings, get the parents later sibling.
114
113
ArrayDeque <FlowNode > parentsLaterSiblings = getProcessedChildren (getFirstEnclosingNode (parentStartNode ));
115
114
after = parentsLaterSiblings .isEmpty () ? null : parentsLaterSiblings .peek ();
116
- dump (parentsLaterSiblings .toString ());
115
+ if (isDebugEnabled ) {
116
+ logger .debug (parentsLaterSiblings .toString ());
117
+ }
117
118
} else {
118
- dump (laterSiblings .toString ());
119
+ if (isDebugEnabled ) {
120
+ logger .debug (laterSiblings .toString ());
121
+ }
119
122
after = laterSiblings .peek ();
120
123
}
121
124
return after ;
@@ -136,15 +139,19 @@ private ArrayDeque<FlowNode> getProcessedChildren(@CheckForNull FlowNode node) {
136
139
}
137
140
138
141
private void addStepRelationship (@ NonNull StepAtomNode step ) {
139
- dump ("Generating relationship for step %s" , step .getId ());
142
+ if (isDebugEnabled ) {
143
+ logger .debug ("Generating relationship for step {}" , step .getId ());
144
+ }
140
145
// FlowNode after = subsequentNode;
141
146
FlowNode after = getAfterNode (step );
142
- dump (
143
- "Adding step for %s(%s),%s(%s)" ,
144
- step .getId (),
145
- step .getClass ().getName (),
146
- after == null ? "null" : after .getId (),
147
- after == null ? "null" : after .getClass ().getName ());
147
+ if (isDebugEnabled ) {
148
+ logger .debug (
149
+ "Adding step for {}({}),{}({})" ,
150
+ step .getId (),
151
+ step .getClass ().getName (),
152
+ after == null ? "null" : after .getId (),
153
+ after == null ? "null" : after .getClass ().getName ());
154
+ }
148
155
NodeRelationship nodeRelationship = new NodeRelationship (step , step , after );
149
156
relationships .put (step .getId (), nodeRelationship );
150
157
}
@@ -166,7 +173,9 @@ private void addBlockRelationship(@NonNull FlowNode node) {
166
173
if (PipelineNodeUtil .isParallelBranch (node )) {
167
174
addParallelBranchRelationship (node , endNode );
168
175
} else {
169
- dump ("Adding relationship for %s" , node .getId ());
176
+ if (isDebugEnabled ) {
177
+ logger .debug ("Adding relationship for {}" , node .getId ());
178
+ }
170
179
if (!pendingBranchRelationships .isEmpty ()) {
171
180
blockRelationship = addParallelRelationship (node , endNode );
172
181
} else {
@@ -186,12 +195,14 @@ private void addParallelBranchRelationship(@NonNull FlowNode node, @NonNull Flow
186
195
// Store a parallel branch relationship - these will be used to build up the
187
196
// parent parallel block relationship.
188
197
// Once generated, that relationship will be superseded this one.
189
- dump (
190
- "Adding parallel branch relationship for %s(%s)->%s(%s)" ,
191
- node .getId (),
192
- node .getClass ().getName (),
193
- endNode .getId (),
194
- endNode .getClass ().getName ());
198
+ if (isDebugEnabled ) {
199
+ logger .debug (
200
+ "Adding parallel branch relationship for {}({})->{}({})" ,
201
+ node .getId (),
202
+ node .getClass ().getName (),
203
+ endNode .getId (),
204
+ endNode .getClass ().getName ());
205
+ }
195
206
// After doesn't matter as this relationship object is temporary (only start and
196
207
// end node are used).
197
208
NodeRelationship blockRelationship = new NodeRelationship (node , endNode , after );
@@ -200,9 +211,12 @@ private void addParallelBranchRelationship(@NonNull FlowNode node, @NonNull Flow
200
211
201
212
private NodeRelationship addParallelRelationship (@ NonNull FlowNode node , @ NonNull FlowNode endNode ) {
202
213
FlowNode after = getAfterNode (node );
203
- dump (
204
- "Generating relationship for parallel Block %s (with after %s)" ,
205
- node .getId (), (after != null ) ? after .getId () : "null" );
214
+ if (isDebugEnabled ) {
215
+ logger .debug (
216
+ "Generating relationship for parallel Block {} (with after {})" ,
217
+ node .getId (),
218
+ (after != null ) ? after .getId () : "null" );
219
+ }
206
220
// handle parallel block case.
207
221
NodeRelationship parallelRelationship =
208
222
new ParallelBlockRelationship (node , endNode , after , pendingBranchRelationships );
@@ -221,14 +235,16 @@ private NodeRelationship addParallelRelationship(@NonNull FlowNode node, @NonNul
221
235
222
236
private NodeRelationship addStageRelationship (@ NonNull FlowNode node , @ NonNull FlowNode endNode ) {
223
237
FlowNode after = getAfterNode (node );
224
- dump (
225
- "Generating relationship for Block %s{%s}->%s{%s} (with after %s{%s})" ,
226
- node .getId (),
227
- node .getClass (),
228
- endNode .getId (),
229
- endNode .getClass (),
230
- (after != null ) ? after .getId () : "null" ,
231
- (after != null ) ? after .getClass () : "null" );
238
+ if (isDebugEnabled ) {
239
+ logger .debug (
240
+ "Generating relationship for Block {}{{}}->{}{{}} (with after {}{{}})" ,
241
+ node .getId (),
242
+ node .getClass (),
243
+ endNode .getId (),
244
+ endNode .getClass (),
245
+ (after != null ) ? after .getId () : "null" ,
246
+ (after != null ) ? after .getClass () : "null" );
247
+ }
232
248
return new NodeRelationship (node , endNode , after );
233
249
}
234
250
}
0 commit comments