
java.util.Collections Maven / Gradle / Ivy
/*
* Copyright 2016 Carlos Ballesteros Velasco
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package java.util;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Collections {
private Collections() {
}
native public static > void sort(List list);
native public static void sort(List list, Comparator super T> c);
native public static int binarySearch(List extends Comparable super T>> list, T key);
native public static int binarySearch(List extends T> list, T key, Comparator super T> c);
public static void reverse(List> list) {
int size = list.size();
for (int i = 0, mid = size >> 1, j = size - 1; i < mid; i++, j--) {
swap(list, i, j);
}
}
native public static void shuffle(List> list);
native public static void shuffle(List> list, Random rnd);
public static void swap(List> list, int i, int j) {
final List l = list;
l.set(i, l.set(j, l.get(i)));
}
public static void fill(List super T> list, T obj) {
int length = list.size();
for (int n = 0; n < length; n++) list.set(n, obj);
}
native public static void copy(List super T> dest, List extends T> src);
native public static > T min(Collection extends T> coll);
native public static T min(Collection extends T> coll, Comparator super T> comp);
native public static > T max(Collection extends T> coll);
native public static T max(Collection extends T> coll, Comparator super T> comp);
public static void rotate(List> list, int distance) {
int length = list.size();
for (int n = 0; n < length; n++) {
swap(list, n, (n + distance) % length);
}
}
public static boolean replaceAll(List list, T oldVal, T newVal) {
int length = list.size();
int count = 0;
for (int n = 0; n < length; n++) {
if (Objects.equals(list.get(n), oldVal)) {
list.set(n, newVal);
count++;
}
}
return count > 0;
}
native public static int indexOfSubList(List> source, List> target);
native public static int lastIndexOfSubList(List> source, List> target);
public static Collection unmodifiableCollection(Collection extends T> c) {
return (Collection) c;
}
public static Set unmodifiableSet(Set extends T> s) {
return (Set) s;
}
public static SortedSet unmodifiableSortedSet(SortedSet s) {
return s;
}
public static NavigableSet unmodifiableNavigableSet(NavigableSet s) {
return s;
}
public static List unmodifiableList(List extends T> list) {
return (List) list;
}
public static Map unmodifiableMap(Map extends K, ? extends V> m) {
return (Map) m;
}
public static SortedMap unmodifiableSortedMap(SortedMap m) {
return (SortedMap) m;
}
public static NavigableMap unmodifiableNavigableMap(NavigableMap m) {
return (NavigableMap) m;
}
public static Collection synchronizedCollection(Collection c) {
return c;
}
public static Set synchronizedSet(Set s) {
return s;
}
public static SortedSet synchronizedSortedSet(SortedSet s) {
return s;
}
public static NavigableSet synchronizedNavigableSet(NavigableSet s) {
return s;
}
static List synchronizedList(List list, Object mutex) {
return (list instanceof RandomAccess ? list : list);
}
public static Map synchronizedMap(Map m) {
return m;
}
public static SortedMap synchronizedSortedMap(SortedMap m) {
return m;
}
public static NavigableMap synchronizedNavigableMap(NavigableMap m) {
return m;
}
native public static Collection checkedCollection(Collection c, Class type);
native public static Queue checkedQueue(Queue queue, Class type);
native public static Set checkedSet(Set s, Class type);
native public static SortedSet checkedSortedSet(SortedSet s, Class type);
native public static NavigableSet checkedNavigableSet(NavigableSet s, Class type);
native public static List checkedList(List list, Class type);
native public static Map checkedMap(Map m, Class keyType, Class valueType);
native public static SortedMap checkedSortedMap(SortedMap m, Class keyType, Class valueType);
native public static NavigableMap checkedNavigableMap(NavigableMap m, Class keyType, Class valueType);
static private List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy