mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'feature/RM-5841_EmptyReasonId_cg' into 'master'
RM-5481 Handle empty string as a reason or exemption id. See merge request !431
This commit is contained in:
@@ -37,6 +37,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various common helper methods for Collections. This class is probably only appropriate for use with relatively
|
* Various common helper methods for Collections. This class is probably only appropriate for use with relatively
|
||||||
* small collections as it has not been optimised for dealing with large collections.
|
* small collections as it has not been optimised for dealing with large collections.
|
||||||
@@ -201,4 +203,27 @@ public final class RMCollectionUtils
|
|||||||
else { return Difference.UNCHANGED; }
|
else { return Difference.UNCHANGED; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a collection to an immutable set. Any instances of null in the original collection will be removed.
|
||||||
|
*
|
||||||
|
* @param collection The original collection.
|
||||||
|
* @param <T> The type of the object in the collection.
|
||||||
|
* @return The immutable set.
|
||||||
|
*/
|
||||||
|
public static <T> ImmutableSet<T> toImmutableSet(Collection<T> collection)
|
||||||
|
{
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Guava immutable collections can't contain null.
|
||||||
|
if (collection.contains(null))
|
||||||
|
{
|
||||||
|
// Make sure we're not changing the original collection (which might not be editable anyway).
|
||||||
|
collection = new HashSet<>(collection);
|
||||||
|
collection.remove(null);
|
||||||
|
}
|
||||||
|
return ImmutableSet.copyOf(collection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,6 +46,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.Difference;
|
import org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.Difference;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -122,4 +123,21 @@ public class RMCollectionUtilsUnitTest
|
|||||||
|
|
||||||
assertEquals(s, l);
|
assertEquals(s, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void toImmutableSet_nullInput()
|
||||||
|
{
|
||||||
|
Set<String> output = RMCollectionUtils.toImmutableSet(null);
|
||||||
|
assertNull("toImmutableSet should pass through with null.", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void toImmutableSet_nullElement()
|
||||||
|
{
|
||||||
|
Set<String> input = newHashSet("One", null, "Three");
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
Set<String> output = RMCollectionUtils.toImmutableSet(input);
|
||||||
|
|
||||||
|
assertEquals("Unexpected handling of null input element", output, newHashSet("One", "Three"));
|
||||||
|
assertEquals("Input should not have been changed.", input, newHashSet("One", null, "Three"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user