You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/10/28 14:14:44 UTC

svn commit: r1767028 - in /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas: FSArray.java SelectViaCopyToArray.java

Author: schor
Date: Fri Oct 28 14:14:43 2016
New Revision: 1767028

URL: http://svn.apache.org/viewvc?rev=1767028&view=rev
Log:
no Jira - refactor select API to use common approach

Added:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/SelectViaCopyToArray.java
Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSArray.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSArray.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSArray.java?rev=1767028&r1=1767027&r2=1767028&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSArray.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSArray.java Fri Oct 28 14:14:43 2016
@@ -31,7 +31,7 @@ import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.JCasRegistry;
 
 /** Java Class model for Cas FSArray type */
-public final class FSArray extends TOP implements CommonArray, ArrayFS {
+public final class FSArray extends TOP implements CommonArray, ArrayFS, SelectViaCopyToArray {
 
   /**
    * each cover class when loaded sets an index. used in the JCas typeArray to go from the cover
@@ -69,7 +69,7 @@ public final class FSArray extends TOP i
     _casView.validateArraySize(length);
     theArray = new TOP[length];
 
-    if (CASImpl.traceFSs) {
+    if (CASImpl.traceFSs) { // tracing done after array setting, skipped in super class
       _casView.traceFSCreate(this);
     }
     if (CASImpl.IS_USE_V2_IDS) {
@@ -89,7 +89,7 @@ public final class FSArray extends TOP i
     _casView.validateArraySize(length);
     theArray = new TOP[length];
     
-    if (CASImpl.traceFSs) {
+    if (CASImpl.traceFSs) { // tracing done after array setting, skipped in super class
       _casView.traceFSCreate(this);
     }
     if (CASImpl.IS_USE_V2_IDS) {
@@ -219,49 +219,11 @@ public final class FSArray extends TOP i
   }
   
   /**
-   * Treat an FSArray as a source for SelectFSs. 
-   * @return a new instance of SelectFSs
+   * Convenience - create a FSArray from an existing FeatureStructure[]
+   * @param jcas -
+   * @param a -
+   * @return -
    */
-  public <T extends FeatureStructure> SelectFSs<T> select() {
-    return new SelectFSs_impl<>(this);
-  }
-
-  /**
-   * Treat an FSArray as a source for SelectFSs. 
-   * @param filterByType only includes elements of this type
-   * @return a new instance of SelectFSs
-   */
-  public <T extends FeatureStructure> SelectFSs<T> select(Type filterByType) {
-    return new SelectFSs_impl<>(this).type(filterByType);
-  }
-
-  /**
-   * Treat an FSArray as a source for SelectFSs.  
-   * @param filterByType only includes elements of this JCas class
-   * @return a new instance of SelectFSs
-   */
-  public <T extends FeatureStructure> SelectFSs<T> select(Class<T> filterByType) {
-    return new SelectFSs_impl<>(this).type(filterByType);
-  }
-  
-  /**
-   * Treat an FSArray as a source for SelectFSs. 
-   * @param filterByType only includes elements of this JCas class's type
-   * @return a new instance of SelectFSs
-   */
-  public <T extends FeatureStructure> SelectFSs<T> select(int filterByType) {
-    return new SelectFSs_impl<>(this).type(filterByType);
-  }
-  
-  /**
-   * Treat an FSArray as a source for SelectFSs. 
-   * @param filterByType only includes elements of this type (fully qualifined type name)
-   * @return a new instance of SelectFSs
-   */
-  public <T extends FeatureStructure> SelectFSs<T> select(String filterByType) {
-    return new SelectFSs_impl<>(this).type(filterByType);
-  }
-
   public static FSArray create(JCas jcas, FeatureStructure[] a) {
     FSArray fsa = new FSArray(jcas, a.length);
     fsa.copyFromArray(a, 0, 0, a.length);

Added: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/SelectViaCopyToArray.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/SelectViaCopyToArray.java?rev=1767028&view=auto
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/SelectViaCopyToArray.java (added)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/SelectViaCopyToArray.java Fri Oct 28 14:14:43 2016
@@ -0,0 +1,62 @@
+package org.apache.uima.jcas.cas;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.SelectFSs;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.SelectFSs_impl;
+
+/** 
+ * Classes which provide a toArray() method that returns 
+ * a FeatureStructure[] can implement this to enable the 
+ * class to be used as a "select" source
+ */
+
+
+
+public interface SelectViaCopyToArray {
+  
+  FeatureStructure[] toArray();
+  CASImpl _getView(); 
+  
+  default <T extends FeatureStructure> SelectFSs_impl<T> select() {
+    return new SelectFSs_impl<T>(toArray(), this._getView());
+  }
+
+  /**
+   * Treat an FSArray as a source for SelectFSs. 
+   * @param filterByType only includes elements of this type
+   * @return a new instance of SelectFSs
+   */
+  default <T extends FeatureStructure> SelectFSs<T> select(Type filterByType) {
+    return select().type(filterByType);
+  }
+
+  /**
+   * Treat an FSArray as a source for SelectFSs.  
+   * @param filterByType only includes elements of this JCas class
+   * @return a new instance of SelectFSs
+   */
+  default <T extends FeatureStructure> SelectFSs<T> select(Class<T> filterByType) {
+    return select().type(filterByType);
+  }
+  
+  /**
+   * Treat an FSArray as a source for SelectFSs. 
+   * @param filterByType only includes elements of this JCas class's type
+   * @return a new instance of SelectFSs
+   */
+  default <T extends FeatureStructure> SelectFSs<T> select(int filterByType) {
+    return select().type(filterByType);
+  }
+  
+  /**
+   * Treat an FSArray as a source for SelectFSs. 
+   * @param filterByType only includes elements of this type (fully qualifined type name)
+   * @return a new instance of SelectFSs
+   */
+  default <T extends FeatureStructure> SelectFSs<T> select(String filterByType) {
+    return select().type(filterByType);
+  }
+}