From a012929bc7dda870e190a879a853a91d7eb3469b Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Mon, 17 Jul 2023 13:52:00 +0900 Subject: [PATCH] =?UTF-8?q?asList=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/foundation/util/ListSupport.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/cokr/xit/foundation/util/ListSupport.java b/src/main/java/cokr/xit/foundation/util/ListSupport.java index b19d315..4e2ad0c 100644 --- a/src/main/java/cokr/xit/foundation/util/ListSupport.java +++ b/src/main/java/cokr/xit/foundation/util/ListSupport.java @@ -1,6 +1,7 @@ package cokr.xit.foundation.util; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.function.Consumer; import java.util.stream.StreamSupport; @@ -25,14 +26,23 @@ public class ListSupport { return this; } + /**iterable을 List로 변환하여 반환한다. + * @param iterable Collection + * @return List + */ + public List asList(Iterable iterable) { + return iterable == null ? Collections.emptyList() : + iterable instanceof List ? + (List)iterable : + StreamSupport.stream(iterable.spliterator(), false).toList(); + } + /**List로 변환할 Collection을 설정한다. * @param iterable Collection * @return 현재 ListSupport */ public ListSupport setIterable(Iterable iterable) { - this.list = iterable instanceof List ? - (List)iterable : - StreamSupport.stream(iterable.spliterator(), false).toList(); + this.list = asList(iterable); return this; }