You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2018/07/24 20:48:32 UTC
[uima-uimafit] branch
feature/UIMA-5818-Use-List-instead-of-Collection-where-possible updated:
[UIMA-5818] Use List instead of Collection where possible
This is an automated email from the ASF dual-hosted git repository.
rec pushed a commit to branch feature/UIMA-5818-Use-List-instead-of-Collection-where-possible
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git
The following commit(s) were added to refs/heads/feature/UIMA-5818-Use-List-instead-of-Collection-where-possible by this push:
new 717333f [UIMA-5818] Use List instead of Collection where possible
717333f is described below
commit 717333f035bf70ba49c266abff94dd07e77a4d7a
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Tue Jul 24 22:48:28 2018 +0200
[UIMA-5818] Use List instead of Collection where possible
- Use more List even if it may be more inefficient in some cases. The inefficiency can be lifted once a few bug fixes in UIMA Core are in place in UIMA 3.0.1.
---
.../java/org/apache/uima/fit/util/CasUtil.java | 9 ++++++--
.../apache/uima/fit/util/FSCollectionFactory.java | 25 +++++++++++++++-------
.../java/org/apache/uima/fit/util/JCasUtil.java | 5 +++--
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java b/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
index b29a11f..8e93f3d 100644
--- a/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
@@ -73,7 +73,9 @@ public final class CasUtil {
* a type.
* @return a return value.
* @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
+ * @deprecated Use {@code cas.select(type).iterator()}
*/
+ @Deprecated
@SuppressWarnings("unchecked")
public static <T extends FeatureStructure> Iterator<T> iteratorFS(CAS cas, Type type) {
return (Iterator<T>) FSCollectionFactory.create(cas, type).iterator();
@@ -232,9 +234,12 @@ public final class CasUtil {
* the type.
* @return A collection of the selected type.
* @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
+ * @deprecated Use {@code cas.select(type).asList()}
*/
- public static Collection<FeatureStructure> selectFS(final CAS cas, final Type type) {
- return FSCollectionFactory.create(cas, type);
+ @SuppressWarnings("unchecked")
+ @Deprecated
+ public static <T extends FeatureStructure> List<T> selectFS(final CAS cas, final Type type) {
+ return (List<T>) FSCollectionFactory.create(cas, type);
}
/**
diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java b/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java
index 7585cf4..fe969e5 100644
--- a/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java
@@ -88,17 +88,21 @@ public abstract class FSCollectionFactory {
* the type of feature structures to select. All sub-types are returned as well.
* @return a {@link Collection} of the given type of feature structures backed live by the CAS.
* @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
+ * @deprecated Use {@code cas.select(type).asList()}
*/
+ @Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
- public static Collection<FeatureStructure> create(CAS cas, Type type) {
+ public static List<FeatureStructure> create(CAS cas, Type type) {
// If the type is an annotation type, we can use the annotation index, which directly
// provides us with its size. If not, we have to use getAllIndexedFS() which we have to
// scan from beginning to end in order to determine its size.
TypeSystem ts = cas.getTypeSystem();
if (ts.subsumes(cas.getAnnotationType(), type)) {
- return (Collection) create(cas.getAnnotationIndex(type));
+ return (List) create(cas.getAnnotationIndex(type));
} else {
- return create(cas.getIndexRepository().getAllIndexedFS(type));
+ Collection<FeatureStructure> result = create(cas.getIndexRepository().getAllIndexedFS(type));
+ return asList(result.toArray(new FeatureStructure[result.size()]));
+ // return (List) cas.select(type).asList(); - This call is still buggy in UIMA 3.0.0
}
}
@@ -125,9 +129,14 @@ public abstract class FSCollectionFactory {
* the index to convert.
* @return the wrapped index.
* @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
+ * @deprecated Use {@code index.select().asList()}
*/
- public static <T extends AnnotationFS> Collection<T> create(AnnotationIndex<T> aIndex) {
- return new AnnotationIndexAdapter<T>(aIndex);
+ @Deprecated
+ public static <T extends AnnotationFS> List<T> create(AnnotationIndex<T> aIndex) {
+ // Was: return new AnnotationIndexAdapter<T>(aIndex);
+ // return aIndex.select().asList(); // That call is still buggy in UIMA 3.0.0
+ Collection<T> result = new AnnotationIndexAdapter<T>(aIndex);
+ return (List<T>) asList(result.toArray());
}
/**
@@ -138,7 +147,7 @@ public abstract class FSCollectionFactory {
* @return a new collection containing the same feature structures as the provided array.
* @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
*/
- public static <T extends FeatureStructure> Collection<T> create(ArrayFS<T> aArray) {
+ public static <T extends FeatureStructure> List<T> create(ArrayFS<T> aArray) {
return create(aArray, (Type) null);
}
@@ -154,8 +163,8 @@ public abstract class FSCollectionFactory {
* @return a new collection of all feature structures of the given type.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
- public static <T extends TOP> Collection<T> create(ArrayFS aArray, Class<T> aType) {
- return (Collection) create(aArray, CasUtil.getType(aArray.getCAS(), aType));
+ public static <T extends TOP> List<T> create(ArrayFS aArray, Class<T> aType) {
+ return (List) create(aArray, CasUtil.getType(aArray.getCAS(), aType));
}
/**
diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/util/JCasUtil.java b/uimafit-core/src/main/java/org/apache/uima/fit/util/JCasUtil.java
index af0d5b8..9d0cbb2 100644
--- a/uimafit-core/src/main/java/org/apache/uima/fit/util/JCasUtil.java
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/util/JCasUtil.java
@@ -85,10 +85,11 @@ public final class JCasUtil {
* a type.
* @return a return value.
* @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
+ * @deprecated Use {@code jcas.select(type).iterator()}
*/
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Deprecated
public static <T extends TOP> Iterator<T> iterator(JCas jCas, Class<T> type) {
- return (Iterator) FSCollectionFactory.create(jCas.getCas(), getType(jCas, type)).iterator();
+ return jCas.select(type).iterator();
}
/**