
package kr.jm.utils.destory;

import java.util.Arrays;
import java.util.List;

import kr.jm.utils.exception.JMExceptionManager;
import kr.jm.utils.helper.JMThread;

/**
 * The Class Destroyer.
 */
public class Destroyer {

	private static final org.slf4j.Logger log =
			org.slf4j.LoggerFactory.getLogger(Destroyer.class);

	/**
	 * Clean up.
	 *
	 * @param <D>
	 *            the generic type
	 * @param destorys
	 *            the destorys
	 */
	public static <D extends DestroyInterface> void
			cleanUp(@SuppressWarnings("unchecked") D... destorys) {
		cleanUp(Arrays.asList(destorys));
	}

	/**
	 * Clean up.
	 *
	 * @param <D>
	 *            the generic type
	 * @param destroyList
	 *            the destroy list
	 */
	public static <D extends DestroyInterface> void
			cleanUp(List<D> destroyList) {
		for (DestroyInterface destroy : destroyList) {
			try {
				JMThread.sleep(10);
				log.info("Start Clean Up - {}", destroy);
				destroy.cleanUp();
				log.info("Complete Clean Up - {}", destroy);
			} catch (Exception e) {
				log.error("Fail Clean Up - {}", destroy);
				JMExceptionManager.logException(log, e, "cleanUp", destroy);
				continue;
			}
		}
	}

}

@@ -122,16 +122,54 @@
 anager;%0A
+import kr.jm.utils.helper.JMOptional;%0A
 import k
@@ -196,16 +196,16 @@
 Thread;%0A
-
 %0A/**%0A * 
@@ -593,22 +593,51 @@
 %7B%0A%09%09
-cleanU
+JMOptional.getOptional(destorys).ma
 p(Arrays
 .asL
@@ -636,25 +636,51 @@
 rays
-.
+::
 asList
-(destorys)
+)%0A%09%09%09%09.ifPresent(Destroyer::cleanUp
 );%0A%09
@@ -901,64 +901,244 @@
 %7B%0A%09%09
-for (DestroyInterface destroy : destroyList
+JMOptional.getOptional(destroyList)%0A%09%09%09%09.ifPresent(list -%3E list.forEach(Destroyer::cleanUp));%0A%09%7D%0A%0A%09/**%0A%09 * Clean up.%0A%09 *%0A%09 * @param destroy%0A%09 *            the destroy%0A%09 */%0A%09public static void cleanUp(DestroyInterface destroy
 ) %7B%0A
-%09
 %09%09try %7B%0A
 %09%09%09%09
@@ -1133,17 +1133,16 @@
 %09%09try %7B%0A
-%09
 %09%09%09JMThr
@@ -1156,17 +1156,16 @@
 ep(10);%0A
-%09
 %09%09%09log.i
@@ -1201,17 +1201,16 @@
 stroy);%0A
-%09
 %09%09%09destr
@@ -1222,25 +1222,24 @@
 eanUp();%0A%09%09%09
-%09
 log.info(%22Co
@@ -1271,17 +1271,16 @@
 stroy);%0A
-%09
 %09%09%7D catc
@@ -1300,17 +1300,16 @@
 e) %7B%0A%09%09%09
-%09
 log.erro
@@ -1342,17 +1342,16 @@
 stroy);%0A
-%09
 %09%09%09JMExc
@@ -1413,23 +1413,15 @@
 %0A%09%09%09
-%09continue;%0A%09%09%09%7D
+return;
 %0A%09%09%7D

handle null or empty