langtools/src/share/classes/com/sun/tools/javac/util/List.java
changeset 22163 3651128c74eb
parent 20249 93f8eae31092
equal deleted inserted replaced
22162:3b3e23e67329 22163:3651128c74eb
   130     }
   130     }
   131 
   131 
   132     /** Construct a list consisting of given element.
   132     /** Construct a list consisting of given element.
   133      */
   133      */
   134     public static <A> List<A> of(A x1) {
   134     public static <A> List<A> of(A x1) {
   135         return new List<A>(x1, List.<A>nil());
   135         return new List<>(x1, List.<A>nil());
   136     }
   136     }
   137 
   137 
   138     /** Construct a list consisting of given elements.
   138     /** Construct a list consisting of given elements.
   139      */
   139      */
   140     public static <A> List<A> of(A x1, A x2) {
   140     public static <A> List<A> of(A x1, A x2) {
   141         return new List<A>(x1, of(x2));
   141         return new List<>(x1, of(x2));
   142     }
   142     }
   143 
   143 
   144     /** Construct a list consisting of given elements.
   144     /** Construct a list consisting of given elements.
   145      */
   145      */
   146     public static <A> List<A> of(A x1, A x2, A x3) {
   146     public static <A> List<A> of(A x1, A x2, A x3) {
   147         return new List<A>(x1, of(x2, x3));
   147         return new List<>(x1, of(x2, x3));
   148     }
   148     }
   149 
   149 
   150     /** Construct a list consisting of given elements.
   150     /** Construct a list consisting of given elements.
   151      */
   151      */
   152     @SuppressWarnings({"varargs", "unchecked"})
   152     @SuppressWarnings({"varargs", "unchecked"})
   153     public static <A> List<A> of(A x1, A x2, A x3, A... rest) {
   153     public static <A> List<A> of(A x1, A x2, A x3, A... rest) {
   154         return new List<A>(x1, new List<A>(x2, new List<A>(x3, from(rest))));
   154         return new List<>(x1, new List<>(x2, new List<>(x3, from(rest))));
   155     }
   155     }
   156 
   156 
   157     /**
   157     /**
   158      * Construct a list consisting all elements of given array.
   158      * Construct a list consisting all elements of given array.
   159      * @param array an array; if {@code null} return an empty list
   159      * @param array an array; if {@code null} return an empty list
   160      */
   160      */
   161     public static <A> List<A> from(A[] array) {
   161     public static <A> List<A> from(A[] array) {
   162         List<A> xs = nil();
   162         List<A> xs = nil();
   163         if (array != null)
   163         if (array != null)
   164             for (int i = array.length - 1; i >= 0; i--)
   164             for (int i = array.length - 1; i >= 0; i--)
   165                 xs = new List<A>(array[i], xs);
   165                 xs = new List<>(array[i], xs);
   166         return xs;
   166         return xs;
   167     }
   167     }
   168 
   168 
   169     public static <A> List<A> from(Iterable<? extends A> coll) {
   169     public static <A> List<A> from(Iterable<? extends A> coll) {
   170         ListBuffer<A> xs = new ListBuffer<>();
   170         ListBuffer<A> xs = new ListBuffer<>();
   179      *  @param init   The value of each element.
   179      *  @param init   The value of each element.
   180      */
   180      */
   181     @Deprecated
   181     @Deprecated
   182     public static <A> List<A> fill(int len, A init) {
   182     public static <A> List<A> fill(int len, A init) {
   183         List<A> l = nil();
   183         List<A> l = nil();
   184         for (int i = 0; i < len; i++) l = new List<A>(init, l);
   184         for (int i = 0; i < len; i++) l = new List<>(init, l);
   185         return l;
   185         return l;
   186     }
   186     }
   187 
   187 
   188     /** Does list have no elements?
   188     /** Does list have no elements?
   189      */
   189      */
   223 
   223 
   224     /** Prepend given element to front of list, forming and returning
   224     /** Prepend given element to front of list, forming and returning
   225      *  a new list.
   225      *  a new list.
   226      */
   226      */
   227     public List<A> prepend(A x) {
   227     public List<A> prepend(A x) {
   228         return new List<A>(x, this);
   228         return new List<>(x, this);
   229     }
   229     }
   230 
   230 
   231     /** Prepend given list of elements to front of list, forming and returning
   231     /** Prepend given list of elements to front of list, forming and returning
   232      *  a new list.
   232      *  a new list.
   233      */
   233      */
   259         if (isEmpty() || tail.isEmpty())
   259         if (isEmpty() || tail.isEmpty())
   260             return this;
   260             return this;
   261 
   261 
   262         List<A> rev = nil();
   262         List<A> rev = nil();
   263         for (List<A> l = this; l.nonEmpty(); l = l.tail)
   263         for (List<A> l = this; l.nonEmpty(); l = l.tail)
   264             rev = new List<A>(l.head, rev);
   264             rev = new List<>(l.head, rev);
   265         return rev;
   265         return rev;
   266     }
   266     }
   267 
   267 
   268     /** Append given element at length, forming and returning
   268     /** Append given element at length, forming and returning
   269      *  a new list.
   269      *  a new list.
   524 
   524 
   525     public java.util.List<A> subList(int fromIndex, int toIndex) {
   525     public java.util.List<A> subList(int fromIndex, int toIndex) {
   526         if  (fromIndex < 0 || toIndex > size() || fromIndex > toIndex)
   526         if  (fromIndex < 0 || toIndex > size() || fromIndex > toIndex)
   527             throw new IllegalArgumentException();
   527             throw new IllegalArgumentException();
   528 
   528 
   529         ArrayList<A> a = new ArrayList<A>(toIndex - fromIndex);
   529         ArrayList<A> a = new ArrayList<>(toIndex - fromIndex);
   530         int i = 0;
   530         int i = 0;
   531         for (List<A> l = this; l.tail != null; l = l.tail, i++) {
   531         for (List<A> l = this; l.tail != null; l = l.tail, i++) {
   532             if (i == toIndex)
   532             if (i == toIndex)
   533                 break;
   533                 break;
   534             if (i >= fromIndex)
   534             if (i >= fromIndex)