@Test public void get_multiple_facet_implementations() { List<Plugin> plugins = new ArrayList<>(); OneFacetPlugin oneFacetPlugin = new OneFacetPlugin(); TwoFacetPlugin twoFacetPlugin = new TwoFacetPlugin(); plugins.add(oneFacetPlugin); plugins.add(twoFacetPlugin); FacetRegistry registry = new FacetRegistry(plugins); List<Facet1> facet1s = registry.getFacets(Facet1.class); Assertions.assertThat(facet1s).hasSize(2); Assertions.assertThat(facet1s.get(0)).isEqualTo(oneFacetPlugin); Assertions.assertThat(facet1s.get(0)).isInstanceOf(OneFacetPlugin.class); Assertions.assertThat(facet1s.get(1)).isEqualTo(twoFacetPlugin); Assertions.assertThat(facet1s.get(1)).isInstanceOf(TwoFacetPlugin.class); List<Facet2> facet2s = registry.getFacets(Facet2.class); Assertions.assertThat(facet2s).hasSize(1); }
@SuppressWarnings("unchecked") <T> List<T> getFacets(@Nullable Class<T> facet) { if (facet != null && Plugin.class.isAssignableFrom(facet)) { List<T> ts = new ArrayList<>(); Plugin plugin = pluginsByClass.get(facet); if (plugin != null) { ts.add((T) plugin); } return ts; } return (List<T>) pluginsByFacet.get(facet); }
FacetRegistry { @SuppressWarnings("unchecked") <T> List<T> getFacets(@Nullable Class<T> facet) { if (facet != null && Plugin.class.isAssignableFrom(facet)) { List<T> ts = new ArrayList<>(); Plugin plugin = pluginsByClass.get(facet); if (plugin != null) { ts.add((T) plugin); } return ts; } return (List<T>) pluginsByFacet.get(facet); } }
FacetRegistry { @SuppressWarnings("unchecked") <T> List<T> getFacets(@Nullable Class<T> facet) { if (facet != null && Plugin.class.isAssignableFrom(facet)) { List<T> ts = new ArrayList<>(); Plugin plugin = pluginsByClass.get(facet); if (plugin != null) { ts.add((T) plugin); } return ts; } return (List<T>) pluginsByFacet.get(facet); } FacetRegistry(final Collection<Plugin> plugins); }
FacetRegistry { @SuppressWarnings("unchecked") <T> List<T> getFacets(@Nullable Class<T> facet) { if (facet != null && Plugin.class.isAssignableFrom(facet)) { List<T> ts = new ArrayList<>(); Plugin plugin = pluginsByClass.get(facet); if (plugin != null) { ts.add((T) plugin); } return ts; } return (List<T>) pluginsByFacet.get(facet); } FacetRegistry(final Collection<Plugin> plugins);  }
FacetRegistry { @SuppressWarnings("unchecked") <T> List<T> getFacets(@Nullable Class<T> facet) { if (facet != null && Plugin.class.isAssignableFrom(facet)) { List<T> ts = new ArrayList<>(); Plugin plugin = pluginsByClass.get(facet); if (plugin != null) { ts.add((T) plugin); } return ts; } return (List<T>) pluginsByFacet.get(facet); } FacetRegistry(final Collection<Plugin> plugins);   }