public static <I, R> Map<I, R> buildMultiple(Iterable<? extends R> values, Function<? super R, ? extends Iterable<? extends I>> indexFunction) {
        Objects.requireNonNull(values, "values");
        Objects.requireNonNull(indexFunction, "indexFunction");

        Map<I, R> map = new HashMap<>();
        for (R value : values) {
            Iterable<? extends I> indexes = indexFunction.apply(value);
            for (I index : indexes) {
                R prev = map.put(index, value);
                if (prev != null) {
                    throw new IllegalStateException("An index for " + value + " (" + index + ") was already associated with " + prev);
                }
            }
        }
        return ImmutableMap.copyOf(map);
    }
Builds an index for the given values, using the indexing function.

@param values the values to index
@param indexFunction the index function
@param <I> the index type
@param <R> the actual (value) type
@return the index
helper/src/main/java/me/lucko/helper/utils/Indexing.java