class CollectionFunctions {

    public static <R, S, T> SortedMap<T, List<R>> toSortedMapWithList(List<S> orderedList, Function<S, T> keyTransform, Function<S, R> valueTransform) {
        SortedMap<T, List<R>> orderedMap = new TreeMap<>();
        if (orderedList != null) {
            orderedList.forEach(s -> {
                if (s != null) {
                    T key = keyTransform.apply(s);
                    R value = valueTransform.apply(s);
                    if (!orderedMap.containsKey(key)) {
                        orderedMap.put(key, new ArrayList<>());
                    }
                    orderedMap.get(key).add(value);
                }
            });
        }
        return orderedMap;
    }

    private  CollectionFunctions();

}