class ReferenceSet {

  public ImmutableSortedSet<DocumentKey> removeReferencesForId(int targetId) {
    DocumentKey emptyKey = DocumentKey.empty();
    DocumentReference startRef = new DocumentReference(emptyKey, targetId);
    Iterator<DocumentReference> it = referencesByTarget.iteratorFrom(startRef);
    ImmutableSortedSet<DocumentKey> keys = DocumentKey.emptyKeySet();
    while (it.hasNext()) {
      DocumentReference ref = it.next();
      if (ref.getId() == targetId) {
        keys = keys.insert(ref.getKey());
        removeReference(ref);
      } else {
        break;
      }
    }

    return keys;
  }

  public  ReferenceSet();

}