ca.infoway.messagebuilder.util.iterator
Class EmptyIterable<T>

Package class diagram package EmptyIterable
java.lang.Object
  extended by ca.infoway.messagebuilder.util.iterator.EmptyIterable<T>
Type Parameters:
T - - the element type of the iterable.

public class EmptyIterable<T>
extends Object

A utility that performs nullness checking on an iterable. If an iterable is null, then an empty iterable is returned, preventing a NullPointerException.

A typical use of this class is as follows: import static ca.infoway.messagebuilder.util.iterator.EmptyIterable.nullSafeIterable; ... public void doMethod() { for (String text : nullSafeIterable(getTextCollection)) { ... } } ...

Author:
Intelliware Development

Constructor Summary
EmptyIterable()
           
 
Method Summary
static
<T> Iterable<T>
nullSafeIterable(Iterable<T> i)
          Check the incoming iterable type to see if it's null.
static
<T> Iterable<T>
nullSafeIterable(T[] i)
          Check the incoming array to see if it's null.
static
<K,V> Iterable<K>
nullSafeKeySetIterable(Map<K,V> map)
          Check the incoming map to see if it's null.
static
<K,V> Iterable<V>
nullSafeValuesIterable(Map<K,V> map)
          Check the incoming map to see if it's null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmptyIterable

public EmptyIterable()
Method Detail

nullSafeIterable

public static <T> Iterable<T> nullSafeIterable(Iterable<T> i)

Check the incoming iterable type to see if it's null.

Type Parameters:
T - - the type of object to iterate over
Parameters:
i - - the iterable type that might be null
Returns:
- the iterable types iterator if it's not null; an empty iterator otherwise

nullSafeIterable

public static <T> Iterable<T> nullSafeIterable(T[] i)

Check the incoming array to see if it's null.

Type Parameters:
T - - the element type of the array
Parameters:
i - - the array that might be null
Returns:
- an array iterator or an empty iterator

nullSafeKeySetIterable

public static <K,V> Iterable<K> nullSafeKeySetIterable(Map<K,V> map)

Check the incoming map to see if it's null. If not, return the keySet iterator, otherwise return an empty iterator.

Type Parameters:
K - - the key type of the map
V - - the value type of the map
Parameters:
map - - the map that might be null
Returns:
- the keyset iterator

nullSafeValuesIterable

public static <K,V> Iterable<V> nullSafeValuesIterable(Map<K,V> map)

Check the incoming map to see if it's null. If not, return the values iterator, otherwise return an empty iterator.

Type Parameters:
K - - the key type of the map
V - - the value type of the map
Parameters:
map - - the map that might be null
Returns:
- the values iterator


Copyright © 2013. All Rights Reserved.