diff --git a/rm-community/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtils.java b/rm-community/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtils.java index 1d3652170c..27c12be716 100644 --- a/rm-community/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtils.java +++ b/rm-community/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtils.java @@ -20,6 +20,7 @@ package org.alfresco.module.org_alfresco_module_rm.util; import static org.springframework.util.ObjectUtils.nullSafeEquals; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -98,6 +99,25 @@ public final class RMCollectionUtils } } + /** + * Returns a Serializable List containing all of the provided elements. + * + * @param elements the elements to put in a list. + * @param the element type. + * @return a Serializable List containing all the provided elements. + */ + @SafeVarargs + public static > + LIST asSerializableList(T... elements) + { + final LIST l = (LIST)new ArrayList<>(elements.length); + for (T element : elements) + { + l.add(element); + } + return l; + } + /** * Returns a Set containing all of the provided elements. Duplicate elements will be removed as per the * {@code Set} contract. diff --git a/rm-community/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtilsUnitTest.java b/rm-community/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtilsUnitTest.java index 1f5d596345..9cf269be30 100644 --- a/rm-community/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtilsUnitTest.java +++ b/rm-community/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMCollectionUtilsUnitTest.java @@ -23,6 +23,7 @@ import static com.google.common.collect.Sets.newHashSet; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils.expectedException; +import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.asSerializableList; import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.asSet; import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.diffKey; import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.head; @@ -30,6 +31,7 @@ import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils. import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -101,4 +103,13 @@ public class RMCollectionUtilsUnitTest assertEquals(newHashSet("hello", "world"), asSet("hello", "world")); assertEquals(newHashSet(3, 7, 31, 127), asSet(3, 7, 31, 127)); } + + @Test public void elementsAsSerializableList() + { + // If these lines compile, then we're good + Serializable s = asSerializableList("one", "two", "three"); + List l = asSerializableList("one", "two", "three"); + + assertEquals(s, l); + } }