Java List Move Item moveDownItems(List list, int[] positions)

Here you can find the source of moveDownItems(List list, int[] positions)

Description

move Down Items

License

Open Source License

Declaration

public static <T> void moveDownItems(List<T> list, int[] positions) 

Method Source Code

//package com.java2s;
/**/* www  .  j  av a2 s. c o  m*/
 * Copyright 2008 Autentia Real Business Solutions S.L. This file is part of autentia-util. autentia-util is free software:
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, version 3 of the License. autentia-util is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public
 * License along with autentia-util. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.List;

public class Main {
    public static <T> void moveDownItems(List<T> list, int[] positions) {
        for (int i = positions.length - 1; i >= 0; i--) {
            moveDownItem(list, positions[i]);
        }
    }

    public static <T> void moveDownItem(List<T> list, int position) {
        if (position < list.size() - 1) {
            final T aux = list.get(position + 1);
            list.set(position + 1, list.get(position));
            list.set(position, aux);
        }
    }
}

Related

  1. move(List aList, int anIndex1, int anIndex2)
  2. move(List collection, int indexToMoveFrom, int indexToMoveAt)
  3. moveBackward(final List list, final int[] indices)
  4. moveBefore(List list, T element, T referenceElement)
  5. moved(List old, List nu, Collection added, Collection removed)
  6. moveElementInList(List list, int targetIndex, int sourceIndex)
  7. moveElementToIndex( List list, ELEMENT fromElement, ELEMENT toElement)
  8. moveInList(List list, int index, T listItem)
  9. moveItem(List list, Object oldItem, int newIndex)

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