Unverified Commit b8c791ff authored by Mathieu Féry (Mathius)'s avatar Mathieu Féry (Mathius)
Browse files

Add ListUtils for joined list

parent 5b8d0176
package fr.iutnantes.miar.dndgenerator.api.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* ListUtils is a class with utils methods
*/
public class ListUtils {
/**
* Method for join data inside unique list
* @param list Base list used for join data
* @param data Data used for join inside list
* @param <T> Class of Data
* @return joinedList
*/
public static <T> List<T> joinList(List<T> list, T... data) {
return joinList(Arrays.asList(list, Arrays.asList(data)));
}
/**
* Method for join data inside unique list
* @param lists lists used for join data
* @param <T> Class of Data
* @return joinedList
*/
public static <T> List<T> joinList(List<List<T>> lists) {
List<T> out = new ArrayList<>();
for (List<T> list: lists)
out.addAll(list);
return out;
}
}
package fr.iutnantes.miar.dndgenerator.api.utils;
import org.junit.Test;
import java.util.Arrays;
import static fr.iutnantes.miar.dndgenerator.api.utils.ListUtils.joinList;
import static org.junit.Assert.assertEquals;
public class ListUtilsTest {
@Test
public void joinListTest() {
assertEquals(
Arrays.asList(1, 2, 3), joinList(Arrays.asList(1, 2), 3)
);
assertEquals(
Arrays.asList(1, 2, 3, 4),
joinList(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)))
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment