Returns an immutable empty <code>Iterator</code> if the specified Iterator is <code>null</code>, otherwise itself is returned.

@param iter
@return
509305
public static <T> Iterator<T> nullToEmpty(final Iterator<T> iter) {
        return iter == null ? N.<T> emptyIterator() : iter;
    }
1329074
public static <T> Iterable<T> nullToEmpty(Iterable<T> iterable) {
        return iterable == null ? Collections.<T>emptyList() : iterable;
    }
746375
@SuppressWarnings("rawtypes")
    private static Object findFirstNonNull(Iterator it) {
        Object result = null;
        while(it.hasNext()) {
            result = it.next();
            if(result != null) {
                break;
            }
        }
        return result;
    }
282326
public static <E> ImmutableIterator<E> makeImmutable(final Iterator<E> iterator) {
        return new ImmutableIterator<E>() {
            @Override
            public boolean hasNext() {
                return iterator.hasNext();
            }

            @Override
            public E next() {
                return iterator.next();
            }
        };
    }
1017774
public static <T> List<T> collect(Iterator<T> iterator) {
        List<T> list = new ArrayList<T>();
        while (iterator.hasNext()) {
            list.add(iterator.next());
        }
        return list;
    }
1014291
public Iterator<T> iterator() {

        if (input == null)
            return null;

        if (outputIterator == null)
            outputIterator = new SinkIterator<T>(input.iterator());

        return outputIterator;
    }
1200442
@SequentialOnly
    public BiIterator<K, V> iterator() {
        final ObjIterator<Entry<K, V>> iter = s.iterator();

        final BooleanSupplier hasNext = new BooleanSupplier() {
            @Override
            public boolean getAsBoolean() {
                return iter.hasNext();
            }
        };

        final Consumer<Pair<K, V>> output = new Consumer<Pair<K, V>>() {
            private Entry<K, V> entry = null;

            @Override
            public void accept(Pair<K, V> t) {
                entry = iter.next();
                t.set(entry.getKey(), entry.getValue());
            }
        };

        return BiIterator.generate(hasNext, output);
    }
175283
@SuppressWarnings({"unchecked"})
    public static <T> Iterator<T> cast(Iterator<? extends T> itr) {
        return (Iterator)itr;
    }
975873
public static <T> Iterator<T> getRandomIterator (Iterator<T> itr)
    {
        ArrayList<T> list = new ArrayList<T>();
        CollectionUtil.addAll(list, itr);
        java.util.Collections.shuffle(list);
        return getUnmodifiableIterator(list);
    }
1339330
public <T extends Evaluation> T evaluate(DataSetIterator iterator) {
        return (T)evaluate(iterator, null);
    }
1164479
@ReplacedBy("com.google.common.collect.Iterators#unmodifiableIterator()")
    public static <T> Iterator<T> getUnmodifiableIterator (final Iterator<T> itr)
    {
        return new Iterator<T>() {
            public boolean hasNext () {
                return itr.hasNext();
            }
            public T next () {
                return itr.next();
            }
            public void remove () {
                throw new UnsupportedOperationException(
                    "Cannot remove from an UnmodifiableIterator!");
            }
        };
    }
1040216
public static @Nonnull <T> Iterable<T> enumerationToIterable(@Nullable Enumeration<T> enumeration) {
        if (enumeration == null) {
            return Collections.emptyList();
        }

        return () -> new Iterator<T>() {
            @Override
            public boolean hasNext() {
                return enumeration.hasMoreElements();
            }

            @Override
            public T next() {
                return enumeration.nextElement();
            }
        };
    }
407790
@Nonnull
  public static <ELEMENTTYPE> Enumeration <ELEMENTTYPE> getEnumeration (@Nullable final Iterator <ELEMENTTYPE> aIter)
  {
    if (aIter == null)
      return new EmptyEnumeration <> ();
    return new EnumerationFromIterator <> (aIter);
  }
911090
@SuppressWarnings("unchecked")
  public static Iterator<Object> iterator(Object iterable) {
    Assert.state(isIterable(iterable.getClass()));
    return iterable.getClass().isArray() ? new ArrayIterator(iterable)
        : ((Iterable<Object>) iterable).iterator();
  }
802482
public static <T> Iterator<T> readOnly(final Iterator<T> itr) {
        return new Iterator<T>() {
            public boolean hasNext() {
                return itr.hasNext();
            }

            public T next() {
                return itr.next();
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
845830
public static boolean isAllNull(Iterator<?> iter) {
		if (null == iter) {
			return true;
		}

		while (iter.hasNext()) {
			if (null != iter.next()) {
				return false;
			}
		}
		return true;
	}
1023773
public static <T> List<T> list(boolean isLinked, Iterator<T> iter) {
		final List<T> list = list(isLinked);
		if (null != iter) {
			while (iter.hasNext()) {
				list.add(iter.next());
			}
		}
		return list;
	}