Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/RevisionSet.java @ 649:e79cf9a8130b
Push: phase4 - update local and remote phase information
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 26 Jun 2013 20:52:38 +0200 |
parents | 690e71d29bf6 |
children | 3b275cc2d2aa |
rev | line source |
---|---|
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
19 import java.util.ArrayList; |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.util.Collection; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.Collections; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.HashSet; |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
23 import java.util.Iterator; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
24 import java.util.List; |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.util.Set; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.core.Nodeid; |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgChangelog; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgParentChildMap; |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 /** |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 * Unmodifiable collection of revisions with handy set operations |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 * @author Artem Tikhomirov |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 * @author TMate Software Ltd. |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 */ |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
37 public final class RevisionSet implements Iterable<Nodeid> { |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 private final Set<Nodeid> elements; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 public RevisionSet(Collection<Nodeid> revisions) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 this(revisions == null ? new HashSet<Nodeid>() : new HashSet<Nodeid>(revisions)); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private RevisionSet(HashSet<Nodeid> revisions) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 if (revisions.isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 elements = Collections.<Nodeid>emptySet(); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 } else { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 elements = revisions; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
53 /** |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
54 * elements of the set with no parents or parents not from the same set |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
55 */ |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
56 public RevisionSet roots(HgParentChildMap<HgChangelog> ph) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
57 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
58 for (Nodeid n : elements) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
59 assert ph.knownNode(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
60 Nodeid p1 = ph.firstParent(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
61 if (p1 != null && elements.contains(p1)) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
62 copy.remove(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
63 continue; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
64 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
65 Nodeid p2 = ph.secondParent(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
66 if (p2 != null && elements.contains(p2)) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
67 copy.remove(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
68 continue; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
69 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
70 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
71 return copy.size() == elements.size() ? this : new RevisionSet(copy); |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
74 /** |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
75 * elements of the set that has no children in this set |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
76 */ |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
77 public RevisionSet heads(HgParentChildMap<HgChangelog> ph) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
78 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
79 // can't do copy.removeAll(ph.childrenOf(asList())); as actual heads are indeed children of some other node |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
80 for (Nodeid n : elements) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
81 assert ph.knownNode(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
82 Nodeid p1 = ph.firstParent(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
83 Nodeid p2 = ph.secondParent(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
84 if (p1 != null && elements.contains(p1)) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
85 copy.remove(p1); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
86 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
87 if (p2 != null && elements.contains(p2)) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
88 copy.remove(p2); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
89 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
90 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
91 return copy.size() == elements.size() ? this : new RevisionSet(copy); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
92 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
93 |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
94 /** |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
95 * Immediate parents of the supplied children set found in this one. |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
96 */ |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
97 public RevisionSet parentsOf(RevisionSet children, HgParentChildMap<HgChangelog> parentHelper) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
98 if (isEmpty()) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
99 return this; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
100 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
101 if (children.isEmpty()) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
102 return children; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
103 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
104 RevisionSet chRoots = children.roots(parentHelper); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
105 HashSet<Nodeid> parents = new HashSet<Nodeid>(); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
106 for (Nodeid n : chRoots.elements) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
107 Nodeid p1 = parentHelper.firstParent(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
108 Nodeid p2 = parentHelper.secondParent(n); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
109 if (p1 != null && elements.contains(p1)) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
110 parents.add(p1); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
111 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
112 if (p2 != null && elements.contains(p2)) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
113 parents.add(p2); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
114 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
115 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
116 return new RevisionSet(parents); |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 public RevisionSet intersect(RevisionSet other) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 if (isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 return this; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 if (other.isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 return other; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 copy.retainAll(other.elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 return copy.size() == elements.size() ? this : new RevisionSet(copy); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 public RevisionSet subtract(RevisionSet other) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 if (isEmpty() || other.isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 return this; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 copy.removeAll(other.elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 return copy.size() == elements.size() ? this : new RevisionSet(copy); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 public RevisionSet union(RevisionSet other) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 if (isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 return other; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 if (other.isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 return this; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 copy.addAll(other.elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 return new RevisionSet(copy); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 /** |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 * A ^ B := (A\B).union(B\A) |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 * A ^ B := A.union(B) \ A.intersect(B) |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 */ |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 public RevisionSet symmetricDifference(RevisionSet other) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 if (isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 return this; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 if (other.isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 return other; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 HashSet<Nodeid> copyA = new HashSet<Nodeid>(elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 HashSet<Nodeid> copyB = new HashSet<Nodeid>(other.elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 copyA.removeAll(other.elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 copyB.removeAll(elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 copyA.addAll(copyB); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 return new RevisionSet(copyA); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 public boolean isEmpty() { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 return elements.isEmpty(); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
175 |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
176 public List<Nodeid> asList() { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
177 return new ArrayList<Nodeid>(elements); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
178 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
179 |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
180 public Iterator<Nodeid> iterator() { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
181 return elements.iterator(); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
182 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
183 |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 @Override |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 public String toString() { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 StringBuilder sb = new StringBuilder(); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 sb.append('<'); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 if (!isEmpty()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 sb.append(elements.size()); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 sb.append(':'); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 for (Nodeid n : elements) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 sb.append(n.shortNotation()); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 sb.append(','); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 if (sb.length() > 1) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 sb.setCharAt(sb.length() - 1, '>'); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 } else { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
199 sb.append('>'); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 return sb.toString(); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 @Override |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 public boolean equals(Object obj) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
206 if (false == obj instanceof RevisionSet) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 return false; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
208 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
209 return elements.equals(((RevisionSet) obj).elements); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
210 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
212 @Override |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
213 public int hashCode() { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
214 return elements.hashCode(); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
215 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 } |