@Test public void testFindBeanClassesDeployedInMultipleBeanArchives() { String beanClass = "com.foo.Bar"; BeanDeploymentArchive bda1 = new WeldBeanDeploymentArchive("foo", ImmutableList.of(beanClass), null); BeanDeploymentArchive bda2 = new WeldBeanDeploymentArchive("bar", ImmutableList.of(beanClass), null); Multimap<String, BeanDeploymentArchive> problems = BeanArchives.findBeanClassesDeployedInMultipleBeanArchives(Collections.singleton(bda1)); assertTrue(problems.isEmpty()); problems = BeanArchives.findBeanClassesDeployedInMultipleBeanArchives(ImmutableSet.of(bda1, bda2)); assertFalse(problems.isEmpty()); assertEquals(1, problems.size()); Entry<String, Collection<BeanDeploymentArchive>> entry = problems.entrySet().iterator().next(); assertEquals(beanClass, entry.getKey()); assertEquals(2, entry.getValue().size()); for (BeanDeploymentArchive bda : entry.getValue()) { if (!bda.getId().equals("foo") && !bda.getId().equals("bar")) { fail(); } } }
public static <B extends BeanDeploymentArchive> Multimap<String, BeanDeploymentArchive> findBeanClassesDeployedInMultipleBeanArchives(Set<B> beanArchives) { if (beanArchives.size() == 1) { return Multimaps.emptyMultimap(); } SetMultimap<String, BeanDeploymentArchive> problems = SetMultimap.newSetMultimap(); if (beanArchives.size() == 2) { Iterator<B> iterator = beanArchives.iterator(); BeanDeploymentArchive first = iterator.next(); BeanDeploymentArchive second = iterator.next(); Set<String> intersection = new HashSet<String>(first.getBeanClasses()); intersection.retainAll(second.getBeanClasses()); if (!intersection.isEmpty()) { List<BeanDeploymentArchive> bdas = ImmutableList.of(first, second); for (String beanClass : intersection) { problems.putAll(beanClass, bdas); } } } else if (beanArchives.size() > 2) { SetMultimap<String, BeanDeploymentArchive> beanClassOccurrences = SetMultimap.newSetMultimap(); for (BeanDeploymentArchive beanArchive : beanArchives) { for (String beanClass : beanArchive.getBeanClasses()) { beanClassOccurrences.put(beanClass, beanArchive); } } for (Entry<String, Collection<BeanDeploymentArchive>> entry : beanClassOccurrences.entrySet()) { if (entry.getValue().size() > 1) { problems.putAll(entry.getKey(), entry.getValue()); } } } return problems; }
BeanArchives { public static <B extends BeanDeploymentArchive> Multimap<String, BeanDeploymentArchive> findBeanClassesDeployedInMultipleBeanArchives(Set<B> beanArchives) { if (beanArchives.size() == 1) { return Multimaps.emptyMultimap(); } SetMultimap<String, BeanDeploymentArchive> problems = SetMultimap.newSetMultimap(); if (beanArchives.size() == 2) { Iterator<B> iterator = beanArchives.iterator(); BeanDeploymentArchive first = iterator.next(); BeanDeploymentArchive second = iterator.next(); Set<String> intersection = new HashSet<String>(first.getBeanClasses()); intersection.retainAll(second.getBeanClasses()); if (!intersection.isEmpty()) { List<BeanDeploymentArchive> bdas = ImmutableList.of(first, second); for (String beanClass : intersection) { problems.putAll(beanClass, bdas); } } } else if (beanArchives.size() > 2) { SetMultimap<String, BeanDeploymentArchive> beanClassOccurrences = SetMultimap.newSetMultimap(); for (BeanDeploymentArchive beanArchive : beanArchives) { for (String beanClass : beanArchive.getBeanClasses()) { beanClassOccurrences.put(beanClass, beanArchive); } } for (Entry<String, Collection<BeanDeploymentArchive>> entry : beanClassOccurrences.entrySet()) { if (entry.getValue().size() > 1) { problems.putAll(entry.getKey(), entry.getValue()); } } } return problems; } }
BeanArchives { public static <B extends BeanDeploymentArchive> Multimap<String, BeanDeploymentArchive> findBeanClassesDeployedInMultipleBeanArchives(Set<B> beanArchives) { if (beanArchives.size() == 1) { return Multimaps.emptyMultimap(); } SetMultimap<String, BeanDeploymentArchive> problems = SetMultimap.newSetMultimap(); if (beanArchives.size() == 2) { Iterator<B> iterator = beanArchives.iterator(); BeanDeploymentArchive first = iterator.next(); BeanDeploymentArchive second = iterator.next(); Set<String> intersection = new HashSet<String>(first.getBeanClasses()); intersection.retainAll(second.getBeanClasses()); if (!intersection.isEmpty()) { List<BeanDeploymentArchive> bdas = ImmutableList.of(first, second); for (String beanClass : intersection) { problems.putAll(beanClass, bdas); } } } else if (beanArchives.size() > 2) { SetMultimap<String, BeanDeploymentArchive> beanClassOccurrences = SetMultimap.newSetMultimap(); for (BeanDeploymentArchive beanArchive : beanArchives) { for (String beanClass : beanArchive.getBeanClasses()) { beanClassOccurrences.put(beanClass, beanArchive); } } for (Entry<String, Collection<BeanDeploymentArchive>> entry : beanClassOccurrences.entrySet()) { if (entry.getValue().size() > 1) { problems.putAll(entry.getKey(), entry.getValue()); } } } return problems; } private  BeanArchives(); }
BeanArchives { public static <B extends BeanDeploymentArchive> Multimap<String, BeanDeploymentArchive> findBeanClassesDeployedInMultipleBeanArchives(Set<B> beanArchives) { if (beanArchives.size() == 1) { return Multimaps.emptyMultimap(); } SetMultimap<String, BeanDeploymentArchive> problems = SetMultimap.newSetMultimap(); if (beanArchives.size() == 2) { Iterator<B> iterator = beanArchives.iterator(); BeanDeploymentArchive first = iterator.next(); BeanDeploymentArchive second = iterator.next(); Set<String> intersection = new HashSet<String>(first.getBeanClasses()); intersection.retainAll(second.getBeanClasses()); if (!intersection.isEmpty()) { List<BeanDeploymentArchive> bdas = ImmutableList.of(first, second); for (String beanClass : intersection) { problems.putAll(beanClass, bdas); } } } else if (beanArchives.size() > 2) { SetMultimap<String, BeanDeploymentArchive> beanClassOccurrences = SetMultimap.newSetMultimap(); for (BeanDeploymentArchive beanArchive : beanArchives) { for (String beanClass : beanArchive.getBeanClasses()) { beanClassOccurrences.put(beanClass, beanArchive); } } for (Entry<String, Collection<BeanDeploymentArchive>> entry : beanClassOccurrences.entrySet()) { if (entry.getValue().size() > 1) { problems.putAll(entry.getKey(), entry.getValue()); } } } return problems; } private  BeanArchives(); static Multimap<String, BeanDeploymentArchive> findBeanClassesDeployedInMultipleBeanArchives(Set<B> beanArchives); static String extractBeanArchiveId(String beanArchiveRef, String base, String separator); }
BeanArchives { public static <B extends BeanDeploymentArchive> Multimap<String, BeanDeploymentArchive> findBeanClassesDeployedInMultipleBeanArchives(Set<B> beanArchives) { if (beanArchives.size() == 1) { return Multimaps.emptyMultimap(); } SetMultimap<String, BeanDeploymentArchive> problems = SetMultimap.newSetMultimap(); if (beanArchives.size() == 2) { Iterator<B> iterator = beanArchives.iterator(); BeanDeploymentArchive first = iterator.next(); BeanDeploymentArchive second = iterator.next(); Set<String> intersection = new HashSet<String>(first.getBeanClasses()); intersection.retainAll(second.getBeanClasses()); if (!intersection.isEmpty()) { List<BeanDeploymentArchive> bdas = ImmutableList.of(first, second); for (String beanClass : intersection) { problems.putAll(beanClass, bdas); } } } else if (beanArchives.size() > 2) { SetMultimap<String, BeanDeploymentArchive> beanClassOccurrences = SetMultimap.newSetMultimap(); for (BeanDeploymentArchive beanArchive : beanArchives) { for (String beanClass : beanArchive.getBeanClasses()) { beanClassOccurrences.put(beanClass, beanArchive); } } for (Entry<String, Collection<BeanDeploymentArchive>> entry : beanClassOccurrences.entrySet()) { if (entry.getValue().size() > 1) { problems.putAll(entry.getKey(), entry.getValue()); } } } return problems; } private  BeanArchives(); static Multimap<String, BeanDeploymentArchive> findBeanClassesDeployedInMultipleBeanArchives(Set<B> beanArchives); static String extractBeanArchiveId(String beanArchiveRef, String base, String separator); static final String BEAN_ARCHIVE_ID_BASE_DELIMITER; }