### Question:
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; } ReferenceSet(); boolean isEmpty(); void addReference(DocumentKey key, int targetOrBatchId); void addReferences(ImmutableSortedSet<DocumentKey> keys, int targetOrBatchId); void removeReference(DocumentKey key, int targetOrBatchId); void removeReferences(ImmutableSortedSet<DocumentKey> keys, int targetOrBatchId); ImmutableSortedSet<DocumentKey> removeReferencesForId(int targetId); void removeAllReferences(); ImmutableSortedSet<DocumentKey> referencesForId(int target); boolean containsKey(DocumentKey key);  }### Answer:
@Test public void testRemoveReferencesForId() { DocumentKey key1 = key("foo/bar"); DocumentKey key2 = key("foo/baz"); DocumentKey key3 = key("foo/blah"); ReferenceSet set = new ReferenceSet(); set.addReference(key1, 1); set.addReference(key2, 1); set.addReference(key3, 2); assertFalse(set.isEmpty()); assertTrue(set.containsKey(key1)); assertTrue(set.containsKey(key2)); assertTrue(set.containsKey(key3)); set.removeReferencesForId(1); assertFalse(set.isEmpty()); assertFalse(set.containsKey(key1)); assertFalse(set.containsKey(key2)); assertTrue(set.containsKey(key3)); set.removeReferencesForId(2); assertTrue(set.isEmpty()); assertFalse(set.containsKey(key1)); assertFalse(set.containsKey(key2)); assertFalse(set.containsKey(key3)); }