530 |
* @throws NullPointerException if a null element has compareTo called |
* @throws NullPointerException if a null element has compareTo called |
531 |
* @see #sort(List) |
* @see #sort(List) |
532 |
*/ |
*/ |
533 |
<T extends Object & Comparable<? super T>> |
public static <T extends Object & Comparable<? super T>> |
534 |
public static int binarySearch(List<? extends T> l, T key) |
int binarySearch(List<? extends T> l, T key) |
535 |
{ |
{ |
536 |
return binarySearch(l, key, null); |
return binarySearch(l, key, null); |
537 |
} |
} |
563 |
* ordering (only possible when c is null) |
* ordering (only possible when c is null) |
564 |
* @see #sort(List, Comparator) |
* @see #sort(List, Comparator) |
565 |
*/ |
*/ |
566 |
<T> public static int binarySearch(List<T> l, T key, Comparator<? super T> c) |
public static <T> int binarySearch(List<T> l, T key, Comparator<? super T> c) |
567 |
{ |
{ |
568 |
int pos = 0; |
int pos = 0; |
569 |
int low = 0; |
int low = 0; |
624 |
* @throws UnsupportedOperationException if dest.listIterator() does not |
* @throws UnsupportedOperationException if dest.listIterator() does not |
625 |
* support the set operation |
* support the set operation |
626 |
*/ |
*/ |
627 |
<T> public static void copy(List<T> dest, List<T> source) |
public static <T> void copy(List<T> dest, List<T> source) |
628 |
{ |
{ |
629 |
int pos = source.size(); |
int pos = source.size(); |
630 |
if (dest.size() < pos) |
if (dest.size() < pos) |
647 |
* @param c the Collection to iterate over |
* @param c the Collection to iterate over |
648 |
* @return an Enumeration backed by an Iterator over c |
* @return an Enumeration backed by an Iterator over c |
649 |
*/ |
*/ |
650 |
<T> public static Enumeration<T> enumeration(Collection<T> c) |
public static <T> Enumeration<T> enumeration(Collection<T> c) |
651 |
{ |
{ |
652 |
final Iterator<T> i = c.iterator(); |
final Iterator<T> i = c.iterator(); |
653 |
return new Enumeration<T>() |
return new Enumeration<T>() |
672 |
* @throws UnsupportedOperationException if l.listIterator() does not |
* @throws UnsupportedOperationException if l.listIterator() does not |
673 |
* support the set operation. |
* support the set operation. |
674 |
*/ |
*/ |
675 |
<T> public static void fill(List<T> l, T val) |
public static <T> void fill(List<T> l, T val) |
676 |
{ |
{ |
677 |
ListIterator<T> itr = l.listIterator(); |
ListIterator<T> itr = l.listIterator(); |
678 |
for (int i = l.size() - 1; i >= 0; --i) |
for (int i = l.size() - 1; i >= 0; --i) |
736 |
* @see ArrayList |
* @see ArrayList |
737 |
* @since 1.4 |
* @since 1.4 |
738 |
*/ |
*/ |
739 |
<T> public static ArrayList<T> list(Enumeration<T> e) |
public static <T> ArrayList<T> list(Enumeration<T> e) |
740 |
{ |
{ |
741 |
ArrayList<T> l = new ArrayList<T>(); |
ArrayList<T> l = new ArrayList<T>(); |
742 |
while (e.hasMoreElements()) |
while (e.hasMoreElements()) |
755 |
* @exception ClassCastException if elements in c are not mutually comparable |
* @exception ClassCastException if elements in c are not mutually comparable |
756 |
* @exception NullPointerException if null.compareTo is called |
* @exception NullPointerException if null.compareTo is called |
757 |
*/ |
*/ |
758 |
<T extends Object & Comparable<? super T>> |
public static <T extends Object & Comparable<? super T>> |
759 |
public static T max(Collection<? extends T> c) |
T max(Collection<? extends T> c) |
760 |
{ |
{ |
761 |
return max(c, null); |
return max(c, null); |
762 |
} |
} |
775 |
* @throws NullPointerException if null is compared by natural ordering |
* @throws NullPointerException if null is compared by natural ordering |
776 |
* (only possible when order is null) |
* (only possible when order is null) |
777 |
*/ |
*/ |
778 |
<T> public static T max(Collection<? extends T> c, |
public static <T> T max(Collection<? extends T> c, |
779 |
Comparator<? super T> order) |
Comparator<? super T> order) |
780 |
{ |
{ |
781 |
Iterator<? extends T> itr = c.iterator(); |
Iterator<? extends T> itr = c.iterator(); |
801 |
* @throws ClassCastException if elements in c are not mutually comparable |
* @throws ClassCastException if elements in c are not mutually comparable |
802 |
* @throws NullPointerException if null.compareTo is called |
* @throws NullPointerException if null.compareTo is called |
803 |
*/ |
*/ |
804 |
<T extends Object & Comparable<? super T>> |
public static <T extends Object & Comparable<? super T>> |
805 |
public static T min(Collection<? extends T> c) |
T min(Collection<? extends T> c) |
806 |
{ |
{ |
807 |
return min(c, null); |
return min(c, null); |
808 |
} |
} |
821 |
* @throws NullPointerException if null is compared by natural ordering |
* @throws NullPointerException if null is compared by natural ordering |
822 |
* (only possible when order is null) |
* (only possible when order is null) |
823 |
*/ |
*/ |
824 |
<T> public static T min(Collection<? extends T> c, |
public static <T> T min(Collection<? extends T> c, |
825 |
Comparator<? super T> order) |
Comparator<? super T> order) |
826 |
{ |
{ |
827 |
Iterator<T> itr = c.iterator(); |
Iterator<T> itr = c.iterator(); |
851 |
* @see Serializable |
* @see Serializable |
852 |
* @see RandomAccess |
* @see RandomAccess |
853 |
*/ |
*/ |
854 |
<T> public static List<T> nCopies(final int n, final T o) |
public static <T> List<T> nCopies(final int n, final T o) |
855 |
{ |
{ |
856 |
return new CopiesList<T>(n, o); |
return new CopiesList<T>(n, o); |
857 |
} |
} |
991 |
* it being added to the list |
* it being added to the list |
992 |
* @since 1.4 |
* @since 1.4 |
993 |
*/ |
*/ |
994 |
<T> public static boolean replaceAll(List<T> list, T oldval, T newval) |
public static <T> boolean replaceAll(List<T> list, T oldval, T newval) |
995 |
{ |
{ |
996 |
ListIterator<T> itr = list.listIterator(); |
ListIterator<T> itr = list.listIterator(); |
997 |
boolean replace_occured = false; |
boolean replace_occured = false; |
1011 |
* @throws UnsupportedOperationException if l.listIterator() does not |
* @throws UnsupportedOperationException if l.listIterator() does not |
1012 |
* support the set operation |
* support the set operation |
1013 |
*/ |
*/ |
1014 |
<T> public static void reverse(List<T> l) |
public static <T> void reverse(List<T> l) |
1015 |
{ |
{ |
1016 |
ListIterator<T> i1 = l.listIterator(); |
ListIterator<T> i1 = l.listIterator(); |
1017 |
int pos1 = 1; |
int pos1 = 1; |
1038 |
* @see Comparable |
* @see Comparable |
1039 |
* @see Serializable |
* @see Serializable |
1040 |
*/ |
*/ |
1041 |
<T>public static Comparator<T> reverseOrder<T>() |
public static <T> Comparator<T> reverseOrder<T>() |
1042 |
{ |
{ |
1043 |
return (Comparator<T>) rcInstance; // fixme? |
return (Comparator<T>) rcInstance; // fixme? |
1044 |
} |
} |
1256 |
* @return an immutable Set containing only o |
* @return an immutable Set containing only o |
1257 |
* @see Serializable |
* @see Serializable |
1258 |
*/ |
*/ |
1259 |
<T> public static Set<T> singleton(T o) |
public static <T> Set<T> singleton(T o) |
1260 |
{ |
{ |
1261 |
return new SingletonSet<T>(o); |
return new SingletonSet<T>(o); |
1262 |
} |
} |
1389 |
* @see RandomAccess |
* @see RandomAccess |
1390 |
* @since 1.3 |
* @since 1.3 |
1391 |
*/ |
*/ |
1392 |
<T> public static List<T> singletonList(T o) |
public static <T> List<T> singletonList(T o) |
1393 |
{ |
{ |
1394 |
return new SingletonList<T>(o); |
return new SingletonList<T>(o); |
1395 |
} |
} |
1529 |
* @see Serializable |
* @see Serializable |
1530 |
* @since 1.3 |
* @since 1.3 |
1531 |
*/ |
*/ |
1532 |
<K, V> public static Map<K, V> singletonMap(K key, V value) |
public static <K, V> Map<K, V> singletonMap(K key, V value) |
1533 |
{ |
{ |
1534 |
return new SingletonMap<K, V>(key, value); |
return new SingletonMap<K, V>(key, value); |
1535 |
} |
} |
1678 |
* @throws NullPointerException if some element is null |
* @throws NullPointerException if some element is null |
1679 |
* @see Arrays#sort(Object[]) |
* @see Arrays#sort(Object[]) |
1680 |
*/ |
*/ |
1681 |
<T extends Comparable<? super T>> public static void sort(List<T> l) |
public static <T extends Comparable<? super T>> void sort(List<T> l) |
1682 |
{ |
{ |
1683 |
sort(l, null); |
sort(l, null); |
1684 |
} |
} |
1700 |
* (only possible when c is null) |
* (only possible when c is null) |
1701 |
* @see Arrays#sort(Object[], Comparator) |
* @see Arrays#sort(Object[], Comparator) |
1702 |
*/ |
*/ |
1703 |
<T> public static void sort(List<T> l, Comparator<? super T> c) |
public static <T> void sort(List<T> l, Comparator<? super T> c) |
1704 |
{ |
{ |
1705 |
Object[] a = l.toArray(); |
Object[] a = l.toArray(); |
1706 |
Arrays.sort(a, c); |
Arrays.sort(a, c); |
1757 |
* @return a synchronized view of the collection |
* @return a synchronized view of the collection |
1758 |
* @see Serializable |
* @see Serializable |
1759 |
*/ |
*/ |
1760 |
<T> public static Collection<T> synchronizedCollection(Collection<T> c) |
public static <T> Collection<T> synchronizedCollection(Collection<T> c) |
1761 |
{ |
{ |
1762 |
return new SynchronizedCollection<T>(c); |
return new SynchronizedCollection<T>(c); |
1763 |
} |
} |
1913 |
} |
} |
1914 |
} |
} |
1915 |
|
|
1916 |
<T> public T[] toArray(T[] a) |
public <T> T[] toArray(T[] a) |
1917 |
{ |
{ |
1918 |
synchronized (mutex) |
synchronized (mutex) |
1919 |
{ |
{ |
2011 |
* @see Serializable |
* @see Serializable |
2012 |
* @see RandomAccess |
* @see RandomAccess |
2013 |
*/ |
*/ |
2014 |
<T> public static List<T> synchronizedList(List<T> l) |
public static <T> List<T> synchronizedList(List<T> l) |
2015 |
{ |
{ |
2016 |
if (l instanceof RandomAccess) |
if (l instanceof RandomAccess) |
2017 |
return new SynchronizedRandomAccessList<T>(l); |
return new SynchronizedRandomAccessList<T>(l); |
2307 |
* @return a synchronized view of the map |
* @return a synchronized view of the map |
2308 |
* @see Serializable |
* @see Serializable |
2309 |
*/ |
*/ |
2310 |
<K, V> public static Map<K, V> synchronizedMap(Map<K, V> m) |
public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m) |
2311 |
{ |
{ |
2312 |
return new SynchronizedMap<K, V>(m); |
return new SynchronizedMap<K, V>(m); |
2313 |
} |
} |
2606 |
* @return a synchronized view of the set |
* @return a synchronized view of the set |
2607 |
* @see Serializable |
* @see Serializable |
2608 |
*/ |
*/ |
2609 |
<T> public static Set<T> synchronizedSet(Set<T> s) |
public static <T> Set<T> synchronizedSet(Set<T> s) |
2610 |
{ |
{ |
2611 |
return new SynchronizedSet<T>(s); |
return new SynchronizedSet<T>(s); |
2612 |
} |
} |
2694 |
* @return a synchronized view of the sorted map |
* @return a synchronized view of the sorted map |
2695 |
* @see Serializable |
* @see Serializable |
2696 |
*/ |
*/ |
2697 |
<K, V> public static SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> m) |
public static <K, V> SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> m) |
2698 |
{ |
{ |
2699 |
return new SynchronizedSortedMap<K, V>(m); |
return new SynchronizedSortedMap<K, V>(m); |
2700 |
} |
} |
2936 |
* @return a read-only view of the collection |
* @return a read-only view of the collection |
2937 |
* @see Serializable |
* @see Serializable |
2938 |
*/ |
*/ |
2939 |
<T> public static Collection<T> unmodifiableCollection(Collection<T> c) |
public static <T> Collection<T> unmodifiableCollection(Collection<T> c) |
2940 |
{ |
{ |
2941 |
return new UnmodifiableCollection<T>(c); |
return new UnmodifiableCollection<T>(c); |
2942 |
} |
} |
3033 |
return c.toArray(); |
return c.toArray(); |
3034 |
} |
} |
3035 |
|
|
3036 |
<S> public S[] toArray(S[] a) |
public <S> S[] toArray(S[] a) |
3037 |
{ |
{ |
3038 |
return c.toArray(a); |
return c.toArray(a); |
3039 |
} |
} |
3098 |
* @see Serializable |
* @see Serializable |
3099 |
* @see RandomAccess |
* @see RandomAccess |
3100 |
*/ |
*/ |
3101 |
<T> public static List<T> unmodifiableList(List<T> l) |
public static <T> List<T> unmodifiableList(List<T> l) |
3102 |
{ |
{ |
3103 |
if (l instanceof RandomAccess) |
if (l instanceof RandomAccess) |
3104 |
return new UnmodifiableRandomAccessList<T>(l); |
return new UnmodifiableRandomAccessList<T>(l); |
3295 |
* @return a read-only view of the map |
* @return a read-only view of the map |
3296 |
* @see Serializable |
* @see Serializable |
3297 |
*/ |
*/ |
3298 |
<K, V> public static Map<K, V> unmodifiableMap(Map<K, V> m) |
public static <K, V> Map<K, V> unmodifiableMap(Map<K, V> m) |
3299 |
{ |
{ |
3300 |
return new UnmodifiableMap<K, V>(m); |
return new UnmodifiableMap<K, V>(m); |
3301 |
} |
} |
3507 |
* @return a read-only view of the set |
* @return a read-only view of the set |
3508 |
* @see Serializable |
* @see Serializable |
3509 |
*/ |
*/ |
3510 |
<T> public static Set<T> unmodifiableSet(Set<T> s) |
public static <T> Set<T> unmodifiableSet(Set<T> s) |
3511 |
{ |
{ |
3512 |
return new UnmodifiableSet<T>(s); |
return new UnmodifiableSet<T>(s); |
3513 |
} |
} |
3561 |
* @return a read-only view of the map |
* @return a read-only view of the map |
3562 |
* @see Serializable |
* @see Serializable |
3563 |
*/ |
*/ |
3564 |
<K, V> public static SortedMap<K, V> unmodifiableSortedMap(SortedMap<K, V> m) |
public static <K, V> SortedMap<K, V> unmodifiableSortedMap(SortedMap<K, V> m) |
3565 |
{ |
{ |
3566 |
return new UnmodifiableSortedMap<K, V>(m); |
return new UnmodifiableSortedMap<K, V>(m); |
3567 |
} |
} |
3644 |
* @return a read-only view of the set |
* @return a read-only view of the set |
3645 |
* @see Serializable |
* @see Serializable |
3646 |
*/ |
*/ |
3647 |
<T> public static SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) |
public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) |
3648 |
{ |
{ |
3649 |
return new UnmodifiableSortedSet<T>(s); |
return new UnmodifiableSortedSet<T>(s); |
3650 |
} |
} |