@Test public void getServicesFromSingletonListWithArgument() { ServiceLoader<Throwable> loader = new ServiceLoader<>(Throwable.class, String.class); assertThat(loader.createList(NullPointerException.class.getName() + ": Hello World!")) .hasSize(1) .allSatisfy(element -> assertThat(element).isInstanceOf(NullPointerException.class)) .allSatisfy(element -> assertThat(element).hasMessage("Hello World!")); }
public List<T> createList(final String list) { List<T> instances = new ArrayList<T>(); for (String entry : list.split(",")) { entry = entry.trim(); if (!entry.isEmpty()) { T instance; int separator = entry.indexOf(':'); if (separator == -1) { instance = create(entry, (Object) null); } else { String name = entry.substring(0, separator).trim(); String argument = entry.substring(separator + 1).trim(); instance = create(name, argument); } if (instance != null) { instances.add(instance); } } } return instances; }
ServiceLoader { public List<T> createList(final String list) { List<T> instances = new ArrayList<T>(); for (String entry : list.split(",")) { entry = entry.trim(); if (!entry.isEmpty()) { T instance; int separator = entry.indexOf(':'); if (separator == -1) { instance = create(entry, (Object) null); } else { String name = entry.substring(0, separator).trim(); String argument = entry.substring(separator + 1).trim(); instance = create(name, argument); } if (instance != null) { instances.add(instance); } } } return instances; } }
ServiceLoader { public List<T> createList(final String list) { List<T> instances = new ArrayList<T>(); for (String entry : list.split(",")) { entry = entry.trim(); if (!entry.isEmpty()) { T instance; int separator = entry.indexOf(':'); if (separator == -1) { instance = create(entry, (Object) null); } else { String name = entry.substring(0, separator).trim(); String argument = entry.substring(separator + 1).trim(); instance = create(name, argument); } if (instance != null) { instances.add(instance); } } } return instances; } ServiceLoader(final Class<? extends T> service, final Class<?>... argumentTypes); }
ServiceLoader { public List<T> createList(final String list) { List<T> instances = new ArrayList<T>(); for (String entry : list.split(",")) { entry = entry.trim(); if (!entry.isEmpty()) { T instance; int separator = entry.indexOf(':'); if (separator == -1) { instance = create(entry, (Object) null); } else { String name = entry.substring(0, separator).trim(); String argument = entry.substring(separator + 1).trim(); instance = create(name, argument); } if (instance != null) { instances.add(instance); } } } return instances; } ServiceLoader(final Class<? extends T> service, final Class<?>... argumentTypes); T create(final String name, final Object... arguments); List<T> createList(final String list); Collection<T> createAll(final Object... arguments); String toSimpleClassName(final String name); }
ServiceLoader { public List<T> createList(final String list) { List<T> instances = new ArrayList<T>(); for (String entry : list.split(",")) { entry = entry.trim(); if (!entry.isEmpty()) { T instance; int separator = entry.indexOf(':'); if (separator == -1) { instance = create(entry, (Object) null); } else { String name = entry.substring(0, separator).trim(); String argument = entry.substring(separator + 1).trim(); instance = create(name, argument); } if (instance != null) { instances.add(instance); } } } return instances; } ServiceLoader(final Class<? extends T> service, final Class<?>... argumentTypes); T create(final String name, final Object... arguments); List<T> createList(final String list); Collection<T> createAll(final Object... arguments); String toSimpleClassName(final String name);  }