FeatureUtils { public static Object[] featureToArray(Feature f, Annotation a) { Object[] ret; if (a.getFeatureValue(f) == null) { ret = new Object[0]; } else { ret = toArray(f, a); } return ret; } private  FeatureUtils(); static Object featureToObject(Feature f, Annotation a); static Object[] featureToArray(Feature f, Annotation a); static List<Object> featureToList(Feature f, Annotation a);  }
@Test public void testNullArrayValue() { DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setDocumentReleasability(null); Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY); Object[] o = FeatureUtils.featureToArray(f, da); assertEquals(0, o.length); }
@Test public void testStringArray() { DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); StringArray rel = new StringArray(jCas, 3); rel.set(0, "ENG"); rel.set(1, "WAL"); rel.set(2, "SCO"); da.setDocumentReleasability(rel); Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY); Object[] o = FeatureUtils.featureToArray(f, da); assertEquals(3, o.length); assertTrue(o[0] instanceof String); assertEquals("ENG", (String) o[0]); assertTrue(o[1] instanceof String); assertEquals("WAL", (String) o[1]); assertTrue(o[2] instanceof String); assertEquals("SCO", (String) o[2]); }
@Test public void testStringArrayToObject() { DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); StringArray rel = new StringArray(jCas, 3); rel.set(0, "true"); rel.set(1, "2"); rel.set(2, "0.45"); da.setDocumentReleasability(rel); Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY); Object[] o = FeatureUtils.featureToArray(f, da); assertEquals(3, o.length); assertTrue(o[0] instanceof Boolean); assertTrue((Boolean) o[0]); assertTrue(o[1] instanceof Integer); assertEquals(new Integer(2), (Integer) o[1]); assertTrue(o[2] instanceof Double); assertEquals(new Double(0.45), (Double) o[2]); }