Here you can find the source of moveBefore(List
Parameter | Description |
---|---|
list | a parameter |
element | a parameter |
referenceElement | a parameter |
true
if the element has been moved or inserted. Otherwise false
.
private static <T> boolean moveBefore(List<T> list, T element, T referenceElement)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/* w ww . j ava 2s. c o m*/ * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.util.List; public class Main { /** * Moves the given element before the reference element. Both are expected to be part of the given list. If the * reference element is not in the list, the list remains untouched. If the element to move is not part of the list, * it is added before the reference element. * * @param list * @param element * @param referenceElement * @return Returns <code>true</code> if the element has been moved or inserted. Otherwise <code>false</code>. * @since 3.8.2 */ private static <T> boolean moveBefore(List<T> list, T element, T referenceElement) { int index = list.indexOf(referenceElement); if (index != -1) { list.remove(element); list.add(index, element); return true; } return false; } }