Skip to content
Snippets Groups Projects
Commit c59c7f47 authored by kaloyane's avatar kaloyane
Browse files

[LMS-2290] forgotten utility method commit

SVN: 21673
parent fc0dd6a1
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ package ch.systemsx.cisd.common.collections; ...@@ -19,6 +19,7 @@ package ch.systemsx.cisd.common.collections;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -327,4 +328,19 @@ public final class CollectionUtils ...@@ -327,4 +328,19 @@ public final class CollectionUtils
} }
return filtered; return filtered;
} }
/**
* For a given collection C returns
*
* <pre>
* 1) C when is not null
* 2) Empty collection when C is null
* </pre>
*
* This allows e.g. iterating over the collections elements without redundant null checks.
*/
public static <E> Collection<E> nullSafe(Collection<E> list)
{
return (list != null) ? list : Collections.<E> emptyList();
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment