/** * Searches for the first occurrence of the given argument in list starting from * a specified index. The equality is tested using the operator <tt>==<tt> and * the <tt>equals</tt> method. * @param list * @param o an object (can be null) * @param fromIndex * @return the index of the first occurrence of the argument in this * list (where index>=fromIndex); returns <tt>-1</tt> if the * object is not found. * @deprecated replaced by {@link ECollections#indexOf(List, Object, int)} in 2.1.0 */ @Deprecated public static int indexOf(List<?> list, Object o, int fromIndex) { return ECollections.indexOf(list, o, fromIndex); }
/** * Searches for the first occurrence of the given argument in list starting from * a specified index. The equality is tested using the operator <tt>==<tt> and * the <tt>equals</tt> method. * @param list * @param o an object (can be null) * @param fromIndex * @return the index of the first occurrence of the argument in this * list (where index>=fromIndex); returns <tt>-1</tt> if the * object is not found. * @deprecated replaced by {@link ECollections#indexOf(List, Object, int)} in 2.1.0 */ @Deprecated public static int indexOf(List<?> list, Object o, int fromIndex) { return ECollections.indexOf(list, o, fromIndex); }
/** * Sorts the specified list. Use this method instead of * {@link Collections#sort(java.util.List)} to * avoid errors when sorting unique lists. * @since 2.1.0 */ public static void sort(EList<?> list) { Object[] listAsArray = list.toArray(); Arrays.sort(listAsArray); for (int i=0; i < listAsArray.length; i++) { int oldIndex = indexOf(list, listAsArray[i], i); if (i != oldIndex) { list.move(i, oldIndex); } } }
/** * Sorts the specified list based on the order defined by the * specified comparator. Use this method instead of * {@link Collections#sort(java.util.List, java.util.Comparator)} to * avoid errors when sorting unique lists. * @since 2.1.0 */ public static <T> void sort(EList<T> list, Comparator<? super T> comparator) { Object[] listAsArray = list.toArray(); @SuppressWarnings("unchecked") Comparator<Object> objectComparator = (Comparator<Object>)comparator; Arrays.sort(listAsArray, objectComparator); for (int i=0; i < listAsArray.length; i++) { int oldIndex = indexOf(list, listAsArray[i], i); if (i != oldIndex) { list.move(i, oldIndex); } } }