Uwe Schindler commented on Improvement LUCENE-3312

I have one comment about the following methods in Document:

+  /** Obtains all indexed fields in document */
+  @Override
+  public Iterable<? extends IndexableField> indexableFields() {
+    Iterator<Field> it = indexedFieldsIterator();
+    
+    List<IndexableField> result = new ArrayList<IndexableField>();
+    while(it.hasNext()) {
+      result.add(it.next());
+    }
+    
+    return result;
+  }
+
+
+  /** Obtains all stored fields in document. */
+  @Override
+  public Iterable<? extends StorableField> storableFields() {
+    Iterator<Field> it = storedFieldsIterator();
+    
+    List<StorableField> result = new ArrayList<StorableField>();
+    while(it.hasNext()) {
+      result.add(it.next());
+    }
+    
+    return result;
+  }
+

In my opinion, this should not copy to an ArrayList, it shoudl simply return a anonymous Iterable<..> wrapping the iterator:

public Iterable<? extends StorableField> storableFields() {
 return new Iterable<? extends StorableField>() {
  @Override
  Iterator<? extends StorableField> iterator() {
    return Document.this.storedFieldsIterator();
  }
 }
}

Also it may not be needed to have <? extends Foo> a simple <Foo> is enough here (comment from Generics Policman)

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to