/** * Gets the all the annotation type and all the other annotations which have a referent target * which is the referent target for an annotation of this type. * * @param <T> the generic type * @param jCas the j cas * @param clazz the clazz * @param referentMap the referent map * @return the all and referents */ @SuppressWarnings("unlikely-arg-type") public static <T extends Base> List<Base> getAllAndReferents( JCas jCas, Class<T> clazz, Map<ReferenceTarget, T> referentMap) { final List<Base> list = new ArrayList<>(); // Add all of the original class list.addAll(JCasUtil.select(jCas, clazz)); // Now find all the referents which point to the same entity streamReferent(jCas, referentMap) // Filter out any existing classes .filter(p -> clazz.isAssignableFrom(p.getClass())) .map(referentMap::get) .forEach(list::add); return list; }
/** * Gets the all the annotation type and all the other annotations which have a referent target * which is the referent target for an annotation of this type. * * @param <T> the generic type * @param jCas the j cas * @param clazz the clazz * @param referentMap the referent map * @return the all and referents */ @SuppressWarnings("unlikely-arg-type") public static <T extends Base> List<Base> getAllAndReferents( JCas jCas, Class<T> clazz, Map<ReferenceTarget, T> referentMap) { final List<Base> list = new ArrayList<>(); // Add all of the original class list.addAll(JCasUtil.select(jCas, clazz)); // Now find all the referents which point to the same entity streamReferent(jCas, referentMap) // Filter out any existing classes .filter(p -> clazz.isAssignableFrom(p.getClass())) .map(referentMap::get) .forEach(list::add); return list; }
@Test public void testStreamReferent() { final Map<ReferenceTarget, Entity> referentMap = new HashMap<>(); referentMap.put(chrisRT, chris); referentMap.put(londonRT, london); final Stream<Base> stream = ReferentUtils.streamReferent(jCas, referentMap); assertEquals(4, stream.count()); }