@SuppressWarnings("varargs")
    @SafeVarargs // Iterating over an array is safe.
    public static <K> Comparator<K> comparing(Function<K, ? extends Comparable<?>>... methods) {
        requireNonNull(methods);
        if (Stream.of(methods).anyMatch(Objects::isNull)) {
            throw new NullPointerException("One of the methods was null");
        }
        return (a, b) -> {
            for (Function<K, ? extends Comparable<?>> method : methods) {
                @SuppressWarnings(value = "unchecked")
                final Function<K, ? extends Comparable<Object>> m
                    = (Function<K, ? extends Comparable<Object>>) method;

                final Comparable<Object> ac = m.apply(a);
                final Comparable<Object> bc = m.apply(b);
                final int c = ac.compareTo(bc);

                if (c != 0) {
                    return c;
                }
            }

            return 0;
        };
    }
Utility method for creating a composed comparator that begins by 
comparing the first value and if it is equal, continues to the next one.

@param <K>      the type of the key to compare
@param methods  methods for comparing the key ordered by priority
@return         a composite comparator that checks the key using the
                supplied methods in order
@throws NullPointerException if any of the provided parameters are {@code null}
common-parent/mapstream/src/main/java/com/speedment/common/mapstream/MapStream.java