private void rehydrateArray(final JCas jCas, final Map<Long, BaleenAnnotation> annotations) { Collection<Integer> list; if (references instanceof Collection) { list = (Collection<Integer>) references; } else { // Should never happen, but convert to list list = Collections.singletonList((Integer) references); } if (list == null || list.isEmpty()) { return; } // Note here we aren't checking that we have the right feature structure type! final List<BaleenAnnotation> derefernces = list.stream() .map(i -> annotations.get((long) i)) .filter(Objects::nonNull) .collect(Collectors.toList()); if (derefernces.isEmpty()) { return; } final FSArray fsArray = UimaTypesUtils.toFSArray(jCas, derefernces); annotation.setFeatureValue(feature, fsArray); }
@Test public void testToFSArrayCollection() { FSArray nullArray = UimaTypesUtils.toFSArray(jCas, (Collection<FeatureStructure>) null); assertNotNull(nullArray); assertEquals(0, nullArray.size()); FSArray emptyArray = UimaTypesUtils.toFSArray(jCas, new ArrayList<>()); assertNotNull(emptyArray); assertEquals(0, emptyArray.size()); Entity e = new Entity(jCas); FSArray fullArray = UimaTypesUtils.toFSArray(jCas, Arrays.asList(e)); assertNotNull(fullArray); assertEquals(1, fullArray.size()); assertSame(e, fullArray.get(0)); }
@Test public void testToFSArrayFeatureStructure() { FSArray nullArray = UimaTypesUtils.toFSArray(jCas, (FeatureStructure) null); assertNotNull(nullArray); assertEquals(1, nullArray.size()); FSArray emptyArray = UimaTypesUtils.toFSArray(jCas); assertNotNull(emptyArray); assertEquals(0, emptyArray.size()); Entity e = new Entity(jCas); FSArray fullArray = UimaTypesUtils.toFSArray(jCas, e); assertNotNull(fullArray); assertEquals(1, fullArray.size()); assertSame(e, fullArray.get(0)); }