in uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java [615:645]
public static <T extends TOP> FSList<T> createFSList(CAS aCas, Collection<T> aValues) {
if (aValues == null) {
return null;
}
TypeSystem ts = aCas.getTypeSystem();
if (aValues.size() == 0) {
return aCas.emptyFSList();
}
Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);
FeatureStructure head = aCas.createFS(nonEmptyType);
FeatureStructure list = head;
Iterator<? extends FeatureStructure> i = aValues.iterator();
while (i.hasNext()) {
head.setFeatureValue(headFeature, i.next());
if (i.hasNext()) {
FeatureStructure tail = aCas.createFS(nonEmptyType);
head.setFeatureValue(tailFeature, tail);
head = tail;
} else {
head.setFeatureValue(tailFeature, aCas.emptyFSList());
}
}
return (FSList<T>) list;
}