UimaTypesUtils { public static StringArray toArray(JCas jCas, Collection<String> collection) { if (collection == null || collection.isEmpty()) { return new StringArray(jCas, 0); } else { int size = collection.size(); StringArray array = new StringArray(jCas, size); array.copyFromArray(collection.toArray(new String[size]), 0, 0, size); return array; } } private  UimaTypesUtils(); static StringArray toArray(JCas jCas, Collection<String> collection); static String[] toArray(StringArray array); @SuppressWarnings("unchecked") static List<T> toList(FSArray array); static List<String> toList(StringArray array); static FSArray toFSArray(JCas jCas, Collection<? extends FeatureStructure> collection); static FSArray toFSArray(JCas jCas, FeatureStructure... fses);  }
@Test public void testUimaToJava() { StringArray sa = new StringArray(jCas, 3); sa.set(0, "Foo"); sa.set(1, "Bar"); sa.set(2, "Baz"); String[] s = UimaTypesUtils.toArray(sa); assertEquals(3, s.length); assertEquals("Foo", s[0]); assertEquals("Bar", s[1]); assertEquals("Baz", s[2]); }
@Test public void testJavaToUima() { StringArray sa = UimaTypesUtils.toArray(jCas, Arrays.asList("Foo", "Bar", "Baz")); assertEquals(3, sa.size()); assertEquals("Foo", sa.get(0)); assertEquals("Bar", sa.get(1)); assertEquals("Baz", sa.get(2)); }
@Test public void testNulls() { String[] javaSa = UimaTypesUtils.toArray(null); assertEquals(0, javaSa.length); StringArray uimaSa = UimaTypesUtils.toArray(jCas, null); assertEquals(0, uimaSa.size()); uimaSa = UimaTypesUtils.toArray(jCas, Collections.emptyList()); assertEquals(0, uimaSa.size()); }