src/org/kocakosm/pitaya/util/Comparators.java
public static <T> Comparator<T> withNullsFirst(final Comparator<T> comparator)
	{
		Parameters.checkNotNull(comparator);
		return new Comparator<T>()
		{
			@Override
			public int compare(T o1, T o2)
			{
				return o1 == o2 ? 0
					: o1 == null ? -1
					: o2 == null ? 1
					: comparator.compare(o1, o2);
			}
		};
	}
public static <T> Comparator<T> withNullsFirst(final Comparator<T> comparator)
	{
		Parameters.checkNotNull(comparator);
		return new Comparator<T>()
		{
			@Override
			public int compare(T o1, T o2)
			{
				return o1 == o2 ? 0
					: o1 == null ? -1
					: o2 == null ? 1
					: comparator.compare(o1, o2);
			}
		};
	}
Returns a new {@code Comparator} that considers {@code null} values
as less than all other values and compares non-{@code null} values
with the given {@code Comparator}.

@param <T> the parameters type of the {@code Comparator}.
@param comparator the non-{@code null} values {@code Comparator}

@return the created {@code Comparator}.

@throws NullPointerException if {@code comparator} is {@code null}.