/** * Returns the minimal distance between startIndex (excluded) and endIndex (excluded). * <p> * In other words, returns the minimum between {@code subLengthExclusive(startIndex, endIndex, list)} and {@code subLengthExclusive(endIndex, startIndex, list)}. */ public static int minDistanceExclusive(int startIndex, int endIndex, List<?> list) { if (endIndex == startIndex) return 0; else return Math.min(subLengthExclusive(startIndex, endIndex, list), subLengthExclusive(endIndex, startIndex, list)); }
/** * Returns a list that contains all the elements of the input from startIndex (excluded) to endIndex (excluded). */ public static <T> List<T> subListExclusive(int startIndex, int endIndex, List<T> input) { List<T> output = new ArrayList<>(); if (startIndex == endIndex) return output; int outputLenth = subLengthExclusive(startIndex, endIndex, input); int i = startIndex + 1; while (output.size() != outputLenth) output.add(getWrap(i++, input)); return output; }
/** * Removes all the elements from the list from startIndex (excluded) to endIndex (excluded). */ public static int removeAllExclusive(int startIndex, int endIndex, List<?> list) { int numberOfElementsToRemove = subLengthExclusive(startIndex, endIndex, list); startIndex = next(startIndex, list); for (int count = 0; count < numberOfElementsToRemove; count++) { startIndex = wrap(startIndex, list); list.remove(startIndex); } return numberOfElementsToRemove; } }