ClassInstanceUtils { public static Collection getInstancesOf(Collection typed, TopicIF type) { Collection result = new ArrayList(); Iterator iter = typed.iterator(); while (iter.hasNext()) { Object object = iter.next(); if (object instanceof TypedIF) { if (isInstanceOf((TypedIF)object, type)) result.add(object); } else { if (isInstanceOf((TopicIF)object, type)) result.add(object); } } return result; }  static void resolveAssociations1(TopicMapIF topicmap); static void resolveAssociations2(TopicMapIF topicmap); static boolean isInstanceOf(TypedIF typed, TopicIF type); static boolean isInstanceOf(TopicIF topic, TopicIF type); static Collection getInstancesOf(Collection typed, TopicIF type); static Collection getTypes(Collection typed); static Collection getTypes(Collection typed, Collection accumulated); static Map getTypeMap(Collection typed); static Map getTypeMap(Collection typed, Map accumulated);  }
@Test public void testGetInstancesOfEmpty() throws IOException { load(testdataDirectory, "small-test.ltm"); Collection instances = ClassInstanceUtils.getInstancesOf(Collections.EMPTY_SET, getTopicById("person")); Assert.assertTrue("found instances in empty set", instances.isEmpty()); }
@Test public void testGetInstancesOfTopic() throws IOException { load(testdataDirectory, "small-test.ltm"); Collection instances = ClassInstanceUtils.getInstancesOf(topicmap.getTopics(), getTopicById("person")); Assert.assertTrue("wrong number of instances", instances.size() == 3); Assert.assertTrue("instances does not contain 'lmg'", instances.contains(getTopicById("lmg"))); Assert.assertTrue("instances does not contain 'gra'", instances.contains(getTopicById("gra"))); Assert.assertTrue("instances does not contain 'grove'", instances.contains(getTopicById("grove"))); }