Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,12 +42,10 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S

public SolrInputDocument() {
_fields = new LinkedHashMap<String,SolrInputField>();
_childDocuments = new ArrayList<SolrInputDocument>();
}

public SolrInputDocument(Map<String,SolrInputField> fields) {
_fields = fields;
_childDocuments = new ArrayList<SolrInputDocument>();
}

/**
Expand Down Expand Up @@ -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() {
Expand All @@ -208,11 +211,13 @@ public SolrInputDocument deepCopy() {
clone._fields.put(fieldEntry.getKey(), fieldEntry.getValue().deepCopy());
}
clone._documentBoost = _documentBoost;

clone._childDocuments = new ArrayList<SolrInputDocument>(_childDocuments.size());
for (SolrInputDocument child : _childDocuments) {
clone._childDocuments.add(child.deepCopy());
}

if (hasChildDocuments()) {
clone._childDocuments = new ArrayList<SolrInputDocument>(_childDocuments.size());
for (SolrInputDocument child : _childDocuments) {
clone._childDocuments.add(child.deepCopy());
}
}

return clone;
}
Expand Down Expand Up @@ -277,11 +282,14 @@ public Collection<SolrInputField> values() {
}

public void addChildDocument(SolrInputDocument child) {
if (!hasChildDocuments()) {
_childDocuments = new ArrayList<SolrInputDocument>();
}
_childDocuments.add(child);
}

public void addChildDocuments(Collection<SolrInputDocument> childs) {
for (SolrInputDocument child : childs) {
public void addChildDocuments(Collection<SolrInputDocument> children) {
for (SolrInputDocument child : children) {
addChildDocument(child);
}
}
Expand All @@ -291,7 +299,6 @@ public List<SolrInputDocument> getChildDocuments() {
}

public boolean hasChildDocuments() {
boolean isEmpty = (_childDocuments == null || _childDocuments.isEmpty());
return !isEmpty;
return _childDocuments != null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might make sense to assert that there is no zero length list ever

}
}