@@ -232,14 +232,13 @@ public void onSourceRemoved(SourceRemovedEvent event) {
232232 }
233233
234234 /**
235- * Adds the step between two other steps.
236- * @param stepToAdd The step to add to the pipeline
237- * @param lower The step to be added above
238- * @param higher The step to be added below
235+ * Finds the index between the two steps
236+ * @param lower The lower step
237+ * @param higher The higher step
238+ * @return The index that is in between the two of these steps
239239 */
240- public void addStepBetween (Step stepToAdd , @ Nullable Step lower , @ Nullable Step higher ) {
241- checkNotNull (stepToAdd , "The step to add cannot be null" );
242- int index = readStepsSafely (steps -> {
240+ private int indexBetween (@ Nullable Step lower , @ Nullable Step higher ) {
241+ return readStepsSafely (steps -> {
243242 // If not in the list these can return -1
244243 int lowerIndex = steps .indexOf (lower );
245244 int upperIndex = steps .indexOf (higher );
@@ -259,9 +258,33 @@ public void addStepBetween(Step stepToAdd, @Nullable Step lower, @Nullable Step
259258 return steps .size ();
260259 }
261260 });
261+ }
262+
263+ /**
264+ * Adds the step between two other steps.
265+ * @param stepToAdd The step to add to the pipeline
266+ * @param lower The step to be added above
267+ * @param higher The step to be added below
268+ */
269+ public void addStepBetween (Step stepToAdd , @ Nullable Step lower , @ Nullable Step higher ) {
270+ checkNotNull (stepToAdd , "The step to add cannot be null" );
271+ final int index = indexBetween (lower , higher );
262272 addStep (index , stepToAdd );
263273 }
264274
275+ /**
276+ *
277+ * @param toMove The step to move
278+ * @param lower The lower step
279+ * @param higher The upper step
280+ */
281+ public void moveStepBetween (Step toMove , @ Nullable Step lower , @ Nullable Step higher ) {
282+ checkNotNull (toMove , "The step to move cannot be null" );
283+ final int index = indexBetween (lower , higher );
284+ final int currentIndex = readStepsSafely (steps -> steps .indexOf (toMove ));
285+ moveStep (toMove , index > currentIndex ? index - (currentIndex + 1 ) : index - currentIndex );
286+ }
287+
265288 public void addStep (int index , Step step ) {
266289 checkNotNull (step , "The step can not be null" );
267290 checkArgument (!step .removed (), "The step must not have been disabled already" );
0 commit comments