Java List Move Item moveUpInList(List list, int... indices)

Here you can find the source of moveUpInList(List list, int... indices)

Description

move Up In List

License

Open Source License

Declaration

public static <E> boolean moveUpInList(List<E> list, int... indices) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;
import java.util.List;

public class Main {
    public static <E> boolean moveUpInList(List<E> list, int... indices) {
        // ignore calls which contain first index
        if (isInArray(indices, 0)) {
            return false;
        }//  www .java2s .c  o m
        Arrays.sort(indices);
        boolean changed = false;
        for (int i : indices) {
            changed |= moveUpInListSingleEntry(list, i);
        }
        return changed;
    }

    public static boolean isInArray(int[] array, int element) {
        for (int i : array) {
            if (i == element) {
                return true;
            }
        }
        return false;
    }

    private static <E> boolean moveUpInListSingleEntry(List<E> list, int index) {
        // ignore calls which try to move up first index
        if (index == 0) {
            return false;
        }
        E element = list.remove(index);
        list.add(index - 1, element);
        return true;
    }
}

Related

  1. moveToFront(List aList, Object anObj)
  2. moveTop(List list, int[] indices)
  3. moveUp(final List list, final T toMoveUp)
  4. moveUp(List list, List toMoveUp)
  5. moveUp(List list, int[] selectionIndexes)
  6. moveUpInListSingleEntry(List list, int index)

  7. HOME | Copyright © www.java2s.com 2016