equal
deleted
inserted
replaced
81 public boolean isEmpty() { |
81 public boolean isEmpty() { |
82 return true; |
82 return true; |
83 } |
83 } |
84 }; |
84 }; |
85 |
85 |
|
86 /** Returns the list obtained from 'l' after removing all elements 'elem' |
|
87 */ |
|
88 public static <A> List<A> filter(List<A> l, A elem) { |
|
89 Assert.checkNonNull(elem); |
|
90 List<A> res = List.nil(); |
|
91 for (A a : l) { |
|
92 if (a != null && !a.equals(elem)) { |
|
93 res = res.prepend(a); |
|
94 } |
|
95 } |
|
96 return res.reverse(); |
|
97 } |
|
98 |
86 /** Construct a list consisting of given element. |
99 /** Construct a list consisting of given element. |
87 */ |
100 */ |
88 public static <A> List<A> of(A x1) { |
101 public static <A> List<A> of(A x1) { |
89 return new List<A>(x1, List.<A>nil()); |
102 return new List<A>(x1, List.<A>nil()); |
90 } |
103 } |
115 public static <A> List<A> from(A[] array) { |
128 public static <A> List<A> from(A[] array) { |
116 List<A> xs = nil(); |
129 List<A> xs = nil(); |
117 if (array != null) |
130 if (array != null) |
118 for (int i = array.length - 1; i >= 0; i--) |
131 for (int i = array.length - 1; i >= 0; i--) |
119 xs = new List<A>(array[i], xs); |
132 xs = new List<A>(array[i], xs); |
|
133 return xs; |
|
134 } |
|
135 |
|
136 public static <A> List<A> from(Iterable<? extends A> coll) { |
|
137 List<A> xs = nil(); |
|
138 for (A a : coll) { |
|
139 xs = new List<A>(a, xs); |
|
140 } |
120 return xs; |
141 return xs; |
121 } |
142 } |
122 |
143 |
123 /** Construct a list consisting of a given number of identical elements. |
144 /** Construct a list consisting of a given number of identical elements. |
124 * @param len The number of elements in the list. |
145 * @param len The number of elements in the list. |