asList 추가

master
mjkhan21 1 year ago
parent 97df00b484
commit a012929bc7

@ -1,6 +1,7 @@
package cokr.xit.foundation.util; package cokr.xit.foundation.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
@ -25,14 +26,23 @@ public class ListSupport<T> {
return this; return this;
} }
/**iterable List .
* @param iterable Collection
* @return List
*/
public List<T> asList(Iterable<T> iterable) {
return iterable == null ? Collections.emptyList() :
iterable instanceof List<T> ?
(List<T>)iterable :
StreamSupport.stream(iterable.spliterator(), false).toList();
}
/**List Collection . /**List Collection .
* @param iterable Collection * @param iterable Collection
* @return ListSupport * @return ListSupport
*/ */
public ListSupport<T> setIterable(Iterable<T> iterable) { public ListSupport<T> setIterable(Iterable<T> iterable) {
this.list = iterable instanceof List<T> ? this.list = asList(iterable);
(List<T>)iterable :
StreamSupport.stream(iterable.spliterator(), false).toList();
return this; return this;
} }

Loading…
Cancel
Save