RevisionVector implements Iterable<Revision>, Comparable<RevisionVector>, CacheValue { public RevisionVector pmax(@NotNull RevisionVector vector) { if (revisions.length == 1 && vector.revisions.length == 1) { if (revisions[0].getClusterId() == vector.revisions[0].getClusterId()) { return revisions[0].compareRevisionTime(vector.revisions[0]) > 0 ? this : vector; } else { return new RevisionVector(revisions[0], vector.revisions[0]); } } int capacity = Math.max(revisions.length, vector.revisions.length); List<Revision> pmax = newArrayListWithCapacity(capacity); PeekingIterator<Revision> it = peekingIterator(vector.iterator()); for (Revision r : revisions) { while (it.hasNext() && it.peek().getClusterId() < r.getClusterId()) { pmax.add(it.next()); } Revision other = peekRevision(it, r.getClusterId()); if (other != null && other.getClusterId() == r.getClusterId()) { pmax.add(Utils.max(r, other)); it.next(); } else { pmax.add(r); } } Iterators.addAll(pmax, it); return new RevisionVector(toArray(pmax, Revision.class), false, false); } 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 pmax() { RevisionVector rv1 = new RevisionVector(); RevisionVector rv2 = new RevisionVector(); assertEquals(newHashSet(), newHashSet(rv1.pmax(rv2))); Revision rev11 = new Revision(1, 0, 1); Revision rev21 = new Revision(2, 0, 1); Revision rev12 = new Revision(1, 0, 2); Revision rev22 = new Revision(2, 0, 2); rv1 = rv1.update(rev11); assertEquals(newHashSet(rev11), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev11), newHashSet(rv2.pmax(rv1))); rv2 = rv2.update(rev12); assertEquals(newHashSet(rev11, rev12), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev11, rev12), newHashSet(rv2.pmax(rv1))); rv1 = rv1.update(rev12); assertEquals(newHashSet(rev11, rev12), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev11, rev12), newHashSet(rv2.pmax(rv1))); rv2 = rv2.update(rev22); assertEquals(newHashSet(rev11, rev22), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev11, rev22), newHashSet(rv2.pmax(rv1))); rv2 = rv2.update(rev11); assertEquals(newHashSet(rev11, rev22), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev11, rev22), newHashSet(rv2.pmax(rv1))); rv1 = rv1.update(rev21); assertEquals(newHashSet(rev21, rev22), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev21, rev22), newHashSet(rv2.pmax(rv1))); rv1 = rv1.update(rev22); assertEquals(newHashSet(rev21, rev22), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev21, rev22), newHashSet(rv2.pmax(rv1))); rv2 = rv2.update(rev21); assertEquals(newHashSet(rev21, rev22), newHashSet(rv1.pmax(rv2))); assertEquals(newHashSet(rev21, rev22), newHashSet(rv2.pmax(rv1))); }