private static <T> Collection<T> toSet(final Collection<T> collection) {
    return (collection instanceof Set ? collection : new HashSet<>(collection));
  }
private static <T> Collection<T> toSet(final Collection<T> collection)