src/share/classes/com/sun/tools/javac/util/List.java

changeset 2000
4a6acc42c3a1
parent 1759
05ec778794d0
child 2047
5f915a0c9615
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/List.java	Fri Aug 30 17:36:47 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/List.java	Mon Sep 02 22:38:36 2013 +0100
     1.3 @@ -116,6 +116,19 @@
     1.4          return buf.toList();
     1.5      }
     1.6  
     1.7 +    /**
     1.8 +     * Create a new list from the first {@code n} elements of this list
     1.9 +     */
    1.10 +    public List<A> take(int n) {
    1.11 +        ListBuffer<A> buf = ListBuffer.lb();
    1.12 +        int count = 0;
    1.13 +        for (A el : this) {
    1.14 +            if (count++ == n) break;
    1.15 +            buf.append(el);
    1.16 +        }
    1.17 +        return buf.toList();
    1.18 +    }
    1.19 +
    1.20      /** Construct a list consisting of given element.
    1.21       */
    1.22      public static <A> List<A> of(A x1) {

mercurial