SubjectIdentityDecider implements DeciderIF<T> { @Override public boolean ok(T object) { if (object instanceof TopicIF) { TopicIF topic = (TopicIF) object; if (topic.getSubjectIdentifiers().contains(subject_identifier)) return true; } if (object instanceof TypedIF) { TopicIF topic = ((TypedIF) object).getType(); if (topic == null) return false; return topic.getSubjectIdentifiers().contains(subject_identifier); } else if (object instanceof TopicIF) { Iterator<TopicIF> it = ((TopicIF) object).getTypes().iterator(); while (it.hasNext()) { TopicIF topic = it.next(); if (topic.getSubjectIdentifiers().contains(subject_identifier)) return true; } } return false; } SubjectIdentityDecider(LocatorIF subject_identifier); @Override boolean ok(T object);  }
@Test public void testSubjectIdentifiers() { LocatorIF locA = makeLocator("A"); LocatorIF locB = makeLocator("B"); TopicIF topicA = getTopic("A"); TopicIF topicB = getTopic("B"); SubjectIdentityDecider decider = new SubjectIdentityDecider(locA); Assert.assertTrue("Decider did not recognize topic", decider.ok(topicA)); Assert.assertTrue("Decider ok-d topic with wrong identifier", !decider.ok(topicB)); }
@Test public void testSubjectAddresses() { LocatorIF locA = makeLocator("A"); TopicIF topic = builder.makeTopic(); topic.addSubjectLocator(locA); SubjectIdentityDecider decider = new SubjectIdentityDecider(locA); Assert.assertTrue("Decider recognized topic which had locator as subject address", !decider.ok(topic)); }
@Test public void testInstances() { LocatorIF locC = makeLocator("C"); LocatorIF locD = makeLocator("D"); TopicIF topicA = getTopic("A"); TopicIF topicB = getTopic("B"); SubjectIdentityDecider decider = new SubjectIdentityDecider(locC); Assert.assertTrue("Decider did not recognize instance of topic", decider.ok(topicA)); Assert.assertTrue("Decider ok-d topic which was instance of topic with wrong identifier", !decider.ok(topicB)); }
@Test public void testNoType() { LocatorIF locD = makeLocator("D"); TopicIF otype = builder.makeTopic(); OccurrenceIF occC = builder.makeOccurrence(getTopic("C"), otype, locD); SubjectIdentityDecider decider = new SubjectIdentityDecider(locD); Assert.assertTrue("Decider recognized occurrence it shouldn't recognize", !decider.ok(occC)); }