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<>(); |
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) |