diff --git a/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java b/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java index 0fdf78b7a39..f84a4baf80f 100644 --- a/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java +++ b/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java @@ -20,7 +20,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -43,12 +42,10 @@ public class SolrInputDocument implements Map, Iterable(); - _childDocuments = new ArrayList(); } public SolrInputDocument(Map fields) { _fields = fields; - _childDocuments = new ArrayList(); } /** @@ -198,7 +195,13 @@ public void setDocumentBoost(float documentBoost) { @Override public String toString() { - return "SolrInputDocument(fields: " + _fields.values() + ", childs: " + _childDocuments + ")"; + String children; + if (hasChildDocuments()) { + children = ", children: " + _childDocuments; + } else { + children = ""; + } + return "SolrInputDocument(fields: " + _fields.values() + children + ")"; } public SolrInputDocument deepCopy() { @@ -208,11 +211,13 @@ public SolrInputDocument deepCopy() { clone._fields.put(fieldEntry.getKey(), fieldEntry.getValue().deepCopy()); } clone._documentBoost = _documentBoost; - - clone._childDocuments = new ArrayList(_childDocuments.size()); - for (SolrInputDocument child : _childDocuments) { - clone._childDocuments.add(child.deepCopy()); - } + + if (hasChildDocuments()) { + clone._childDocuments = new ArrayList(_childDocuments.size()); + for (SolrInputDocument child : _childDocuments) { + clone._childDocuments.add(child.deepCopy()); + } + } return clone; } @@ -277,11 +282,14 @@ public Collection values() { } public void addChildDocument(SolrInputDocument child) { + if (!hasChildDocuments()) { + _childDocuments = new ArrayList(); + } _childDocuments.add(child); } - public void addChildDocuments(Collection childs) { - for (SolrInputDocument child : childs) { + public void addChildDocuments(Collection children) { + for (SolrInputDocument child : children) { addChildDocument(child); } } @@ -291,7 +299,6 @@ public List getChildDocuments() { } public boolean hasChildDocuments() { - boolean isEmpty = (_childDocuments == null || _childDocuments.isEmpty()); - return !isEmpty; + return _childDocuments != null; } }