RevisionVector implements Iterable<Revision>, Comparable<RevisionVector>, CacheValue { public RevisionVector update(@NotNull Revision revision) { checkNotNull(revision); Revision existing = null; int i; for (i = 0; i < revisions.length; i++) { Revision r = revisions[i]; if (r.getClusterId() == revision.getClusterId()) { existing = r; break; } } Revision[] newRevisions; boolean sort; if (existing != null) { if (revision.equals(existing)) { return this; } else { newRevisions = Arrays.copyOf(revisions, revisions.length); newRevisions[i] = revision; sort = false; } } else { newRevisions = new Revision[revisions.length + 1]; System.arraycopy(revisions, 0, newRevisions, 0, revisions.length); newRevisions[revisions.length] = revision; sort = true; } return new RevisionVector(newRevisions, false, sort); } private  RevisionVector(@NotNull Revision[] revisions,
                           boolean checkUniqueClusterIds,
                           boolean sort);  RevisionVector(@NotNull Revision... revisions);  RevisionVector(@NotNull Iterable<Revision> revisions);  RevisionVector(@NotNull Set<Revision> revisions); RevisionVector update(@NotNull Revision revision); RevisionVector remove(int clusterId); RevisionVector pmin(@NotNull RevisionVector vector); RevisionVector pmax(@NotNull RevisionVector vector); RevisionVector difference(RevisionVector vector); boolean isRevisionNewer(@NotNull Revision revision); boolean isBranch(); @NotNull Revision getBranchRevision(); Revision getRevision(int clusterId); String asString(); StringBuilder toStringBuilder(StringBuilder sb); static RevisionVector fromString(String s); RevisionVector asTrunkRevision(); RevisionVector asBranchRevision(int clusterId); int getDimensions(); @Override int getMemory(); @Override int compareTo(@NotNull RevisionVector other); @Override Iterator<Revision> iterator(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void update() { Revision rev1 = new Revision(1, 0, 1); RevisionVector rv = new RevisionVector(rev1); assertEquals(1, Iterables.size(rv)); assertSame(rv, rv.update(rev1)); Revision rev2 = new Revision(2, 0, 1); rv = rv.update(rev2); assertEquals(newHashSet(rev2), newHashSet(rv)); Revision rev3 = new Revision(3, 0, 2); rv = rv.update(rev3); assertEquals(newHashSet(rev2, rev3), newHashSet(rv)); rev3 = rev3.asBranchRevision(); rv = rv.update(rev3); assertEquals(newHashSet(rev2, rev3), newHashSet(rv)); }