class DocumentSet implements Iterable<Document> {

  @Override
  public boolean equals(Object other) {
    if (this == other) {
      return true;
    }
    if (other == null || getClass() != other.getClass()) {
      return false;
    }

    DocumentSet documentSet = (DocumentSet) other;

    if (size() != documentSet.size()) {
      return false;
    }

    Iterator<Document> thisIterator = iterator();
    Iterator<Document> otherIterator = documentSet.iterator();
    while (thisIterator.hasNext()) {
      Document thisDoc = thisIterator.next();
      Document otherDoc = otherIterator.next();
      if (!thisDoc.equals(otherDoc)) {
        return false;
      }
    }

    return true;
  }

  private  DocumentSet(
      ImmutableSortedMap<DocumentKey, Document> keyIndex, ImmutableSortedSet<Document> sortedSet);

}