Ejemplo n.º 1
0
 /**
  * Call the closure once for each document in this corpus, loading and unloading documents as
  * appropriate in the case of a persistent corpus.
  *
  * @param self the corpus to traverse
  * @param closure the closure to call
  * @return the corpus.
  */
 public static <T> Object each(Corpus self, Closure<T> closure) {
   for (int i = 0; i < self.size(); i++) {
     boolean docWasLoaded = self.isDocumentLoaded(i);
     Document doc = self.get(i);
     closure.call(doc);
     if (!docWasLoaded) {
       self.unloadDocument(doc);
       Factory.deleteResource(doc);
     }
   }
   return self;
 }
Ejemplo n.º 2
0
 /**
  * Call the closure once for each document in this corpus, loading and unloading documents as
  * appropriate in the case of a persistent corpus, and adding the return values of each call to
  * the given collection.
  *
  * @param self the corpus to traverse
  * @param closure the closure to call
  * @return a list of the return values from each closure call.
  */
 public static <T> Collection<T> collect(Corpus self, Collection<T> coll, Closure<T> closure) {
   for (int i = 0; i < self.size(); i++) {
     boolean docWasLoaded = self.isDocumentLoaded(i);
     Document doc = self.get(i);
     coll.add(closure.call(doc));
     if (!docWasLoaded) {
       self.unloadDocument(doc);
       Factory.deleteResource(doc);
     }
   }
   return coll;
 }