boolean (ActionChangeRange @NotNull [] ranges, @NotNull Set<ActionChangeRange> rangesToMove) { for (int pass = 0; pass < rangesToMove.size(); pass++) { int destinationIndex = ranges.length - pass - 1; int currentIndex = destinationIndex; for (; currentIndex >= 0; currentIndex--) { if (rangesToMove.contains(ranges[currentIndex])) { break; } } if (currentIndex < 0) { throw new IllegalArgumentException("Array doesn't contain specified ranges"); } for (; currentIndex < destinationIndex; currentIndex++) { if (!swap(ranges, currentIndex)) { return false; } } } return true; }