diff --git a/pom.xml b/pom.xml index b7812d8ab3..ab0ef42ad2 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,13 @@ 4.12 + + + org.apache.commons + commons-email + 1.5 + + diff --git a/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java new file mode 100644 index 0000000000..d9df81fc62 --- /dev/null +++ b/src/test/java/com/ossez/codebank/interview/tests/PillPackTest.java @@ -0,0 +1,57 @@ +package com.ossez.codebank.interview.tests; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.ossez.codebank.interview.KayakCountUpDown; +import com.ossez.codebank.interview.KayakRobotMovement; + +/** + * PillPack + * + *
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays
+ * 
+ * + * @author YuCheng + * + */ +public class PillPackTest { + + private final static Logger logger = LoggerFactory.getLogger(PillPackTest.class); + + List returnList = new ArrayList(); + + /** + * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays + * + * FlattenNestedArrays + */ + @Test + public void testFlattenNestedArrays() { + logger.debug("Test FlattenNestedArrays"); + + Object[] array = { 1, 2, new Object[] { 3, 4, new Object[] { 5 }, 6, 7 }, 8, 9, 10 }; + logger.debug("{} - > {}", Arrays.deepToString(array), Arrays.toString(java8Flatten(array).toArray())); + + } + + /** + * Java 8 Stream to Flatten array. + * + * @param array + * @return + */ + private static Stream java8Flatten(Object[] array) { + return Arrays.stream(array).flatMap(o -> o instanceof Object[] ? java8Flatten((Object[]) o) : Stream.of(o)); + } + +}