NameGrabber implements GrabberIF<TopicIF, NameIF> { @Override public NameIF grab(TopicIF topic) { if (topic == null) return null; List<TopicNameIF> basenames = new ArrayList<TopicNameIF>(topic.getTopicNames()); if (basenames.isEmpty()) return null; if (themeIndicator != null) { TopicMapIF tm = topic.getTopicMap(); if (tm != null) { TopicIF theme = tm.getTopicBySubjectIdentifier(themeIndicator); if (theme != null) { if (indicatorVariant) variantScope = Collections.singleton(theme); else scope = Collections.singleton(theme); } } } Collections.sort(basenames, new TopicNameComparator(scope)); VariantNameGrabber vngrabber = new VariantNameGrabber(variantScope); NameIF name = null; VariantNameIF vn = null; for (TopicNameIF current : basenames) { if (name == null) name = current; if (!variantScope.isEmpty()) { vn = vngrabber.grab(current); if (vn != null) { Collection<TopicIF> interSection = new HashSet<TopicIF>(vn.getScope()); interSection.retainAll(variantScope); if (!interSection.isEmpty()) break; else vn = null; } } } if (vn != null) { if (grabOnlyTopicName) name = vn.getTopicName(); else name = vn; } return name; } NameGrabber(LocatorIF themeIndicator);  NameGrabber(LocatorIF themeIndicator, boolean variant);  NameGrabber(Collection<TopicIF> scope);  NameGrabber(Collection<TopicIF> basenameScope, Collection<TopicIF> variantScope);  NameGrabber(Collection<TopicIF> basenameScope, Collection<TopicIF> variantScope,
                     boolean grabOnlyTopicName); void setGrabOnlyTopicName(boolean grabOnlyTopicName); boolean getGrabOnlyTopicName(); @Override NameIF grab(TopicIF topic);  }
@Test public void testNameGrabber5A() { List basenameScope = new ArrayList(); basenameScope.add(topicPlay); List variantScope = new ArrayList(); variantScope.add(topicSort); GrabberIF grabber = new NameGrabber(basenameScope, variantScope); Assert.assertTrue("wrong base name grabbed", ((TopicNameIF) grabber.grab(topic5)).equals(basename5A)); }
@Test public void testNameGrabber5B() { GrabberIF grabber = new NameGrabber(Collections.EMPTY_LIST); Assert.assertTrue("wrong base name grabbed", ((TopicNameIF) grabber.grab(topic5)).equals(basename5B)); }
@Test public void testNameGrabber5C() { List variantScope = new ArrayList(); variantScope.add(topicSort); GrabberIF grabber = new NameGrabber(Collections.EMPTY_LIST, variantScope); Assert.assertTrue("wrong base name grabbed", ((TopicNameIF) grabber.grab(topic5)).equals(basename5A)); }