class IOChannelUtils {

  @VisibleForTesting
  static void checkDuplicateScheme(Set<IOChannelFactoryRegistrar> registrars) {
    Multimap<String, IOChannelFactoryRegistrar> registrarsBySchemes =
        TreeMultimap.create(Ordering.<String>natural(), Ordering.arbitrary());

    for (IOChannelFactoryRegistrar registrar : registrars) {
      registrarsBySchemes.put(registrar.getScheme(), registrar);
    }
    for (Entry<String, Collection<IOChannelFactoryRegistrar>> entry
        : registrarsBySchemes.asMap().entrySet()) {
      if (entry.getValue().size() > 1) {
        String conflictingRegistrars = Joiner.on(", ").join(
            FluentIterable.from(entry.getValue())
                .transform(new Function<IOChannelFactoryRegistrar, String>() {
                  @Override
                  public String apply(@Nonnull IOChannelFactoryRegistrar input) {
                    return input.getClass().getName();
                  }})
                .toSortedList(Ordering.<String>natural()));
        throw new IllegalStateException(String.format(
            "Scheme: [%s] has conflicting registrars: [%s]",
            entry.getKey(),
            conflictingRegistrars));
      }
    }
  }

}