/[classpath]/classpath/java/util/Collections.java
ViewVC logotype

Diff of /classpath/java/util/Collections.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28.2.1 by tromey, Thu Aug 5 21:09:36 2004 UTC revision 1.28.2.2 by tromey, Sun Aug 8 06:38:26 2004 UTC
# Line 530  public class Collections Line 530  public class Collections
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    }    }
# Line 563  public class Collections Line 563  public class Collections
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;
# Line 624  public class Collections Line 624  public class Collections
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)
# Line 647  public class Collections Line 647  public class Collections
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>()
# Line 672  public class Collections Line 672  public class Collections
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)
# Line 736  public class Collections Line 736  public class Collections
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())
# Line 755  public class Collections Line 755  public class Collections
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    }    }
# Line 775  public class Collections Line 775  public class Collections
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();
# Line 801  public class Collections Line 801  public class Collections
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    }    }
# Line 821  public class Collections Line 821  public class Collections
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();
# Line 851  public class Collections Line 851  public class Collections
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    }    }
# Line 991  public class Collections Line 991  public class Collections
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;
# Line 1011  public class Collections Line 1011  public class Collections
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;
# Line 1038  public class Collections Line 1038  public class Collections
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    }    }
# Line 1256  public class Collections Line 1256  public class Collections
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    }    }
# Line 1389  public class Collections Line 1389  public class Collections
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    }    }
# Line 1529  public class Collections Line 1529  public class Collections
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    }    }
# Line 1678  public class Collections Line 1678  public class Collections
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    }    }
# Line 1700  public class Collections Line 1700  public class Collections
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);
# Line 1757  public class Collections Line 1757  public class Collections
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    }    }
# Line 1913  public class Collections Line 1913  public class Collections
1913          }          }
1914      }      }
1915    
1916      <T> public T[] toArray(T[] a)      public <T> T[] toArray(T[] a)
1917      {      {
1918        synchronized (mutex)        synchronized (mutex)
1919          {          {
# Line 2011  public class Collections Line 2011  public class Collections
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);
# Line 2307  public class Collections Line 2307  public class Collections
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    }    }
# Line 2606  public class Collections Line 2606  public class Collections
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    }    }
# Line 2694  public class Collections Line 2694  public class Collections
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    }    }
# Line 2936  public class Collections Line 2936  public class Collections
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    }    }
# Line 3033  public class Collections Line 3033  public class Collections
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      }      }
# Line 3098  public class Collections Line 3098  public class Collections
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);
# Line 3295  public class Collections Line 3295  public class Collections
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    }    }
# Line 3507  public class Collections Line 3507  public class Collections
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    }    }
# Line 3561  public class Collections Line 3561  public class Collections
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    }    }
# Line 3644  public class Collections Line 3644  public class Collections
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    }    }

Legend:
Removed from v.1.28.2.1  
changed lines
  Added in v.1.28.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26