Class RevisionVector
java.lang.Object
org.apache.jackrabbit.oak.plugins.document.RevisionVector
- All Implemented Interfaces:
Comparable<RevisionVector>
,Iterable<Revision>
,CacheValue
public final class RevisionVector
extends Object
implements Iterable<Revision>, Comparable<RevisionVector>, CacheValue
A vector of revisions. Instances of this class are immutable and methods
like
update(Revision)
create a new instance as needed.
This class implements Comparable
. While
compareTo(RevisionVector)
provides a total order of revision
vector instances, this order is unrelated to when changes are visible in
a DocumentNodeStore cluster. Do not use this method to determine whether
a given revision vector happened before or after another!-
Constructor Summary
ConstructorsConstructorDescriptionRevisionVector
(@NotNull Iterable<Revision> revisions) RevisionVector
(@NotNull Set<Revision> revisions) RevisionVector
(@NotNull Revision... revisions) -
Method Summary
Modifier and TypeMethodDescriptionasBranchRevision
(int clusterId) A clone of this revision vector with the revision for the given clusterId set to a branch revision.asString()
Returns a string representation of this revision vector, which can be parsed again byfromString(String)
.Returns a revision vector where all revision elements are turned into trunk revisions.int
compareTo
(@NotNull RevisionVector other) difference
(RevisionVector vector) Returns the difference of this and the other vector.boolean
static RevisionVector
fromString
(String s) Creates a revision vector from a string representation as returned byasString()
.@NotNull Revision
int
Returns the dimensions of this revision vector.int
The estimated amount of memory used by this object, in bytes.getRevision
(int clusterId) Returns the revision element with the given clusterId ornull
if there is no such revision in this vector.int
hashCode()
boolean
isBranch()
boolean
isRevisionNewer
(@NotNull Revision revision) Returnstrue
if the given revision is newer than the revision element with the same clusterId in the vector.iterator()
pmax
(@NotNull RevisionVector vector) Calculates the parallel maximum of this and the givenvector
.pmin
(@NotNull RevisionVector vector) Calculates the parallel minimum of this and the givenvector
.remove
(int clusterId) Returns a RevisionVector without the revision element with the givenclusterId
.toString()
Appends the string representation of this revision vector to the passedStringBuilder
.Creates a new revision vector with based on this vector and the givenrevision
.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
RevisionVector
-
RevisionVector
-
RevisionVector
-
-
Method Details
-
update
Creates a new revision vector with based on this vector and the givenrevision
. If this vector contains a revision with the same clusterId asrevision
, the returned vector will have the revision updated with the given one. Otherwise the returned vector will have all elements of this vector plus the givenrevision
.- Parameters:
revision
- the revision set to use for the new vector.- Returns:
- the resulting revision vector.
-
remove
Returns a RevisionVector without the revision element with the givenclusterId
.- Parameters:
clusterId
- the clusterId of the revision to remove.- Returns:
- RevisionVector without the revision element.
-
pmin
Calculates the parallel minimum of this and the givenvector
.- Parameters:
vector
- the other vector.- Returns:
- the parallel minimum of the two.
-
pmax
Calculates the parallel maximum of this and the givenvector
.- Parameters:
vector
- the other vector.- Returns:
- the parallel maximum of the two.
-
difference
Returns the difference of this and the other vector. The returned vector contains all revisions of this vector that are not contained in the other vector.- Parameters:
vector
- the other vector.- Returns:
- the difference of the two vectors.
-
isRevisionNewer
Returnstrue
if the given revision is newer than the revision element with the same clusterId in the vector. The given revision is also considered newer if there is no revision element with the same clusterId in this vector.- Parameters:
revision
- the revision to check.- Returns:
true
if considered newer,false
otherwise.
-
isBranch
public boolean isBranch()- Returns:
true
if any of the revisions in this vector is a branch revision,false
otherwise.
-
getBranchRevision
- Returns:
- the first branch revision in this vector.
- Throws:
IllegalStateException
- if this vector does not contain a branch revision.
-
getRevision
Returns the revision element with the given clusterId ornull
if there is no such revision in this vector.- Parameters:
clusterId
- a clusterId.- Returns:
- the revision element with the given clusterId or
null
if none exists.
-
asString
Returns a string representation of this revision vector, which can be parsed again byfromString(String)
.- Returns:
- a string representation of this revision vector.
-
toStringBuilder
Appends the string representation of this revision vector to the passedStringBuilder
. The string representation is the same as returned byasString()
.- Parameters:
sb
- theStringBuilder
this revision vector is appended to.- Returns:
- the passed
StringBuilder
object.
-
fromString
Creates a revision vector from a string representation as returned byasString()
.- Parameters:
s
- the string representation of a revision vector.- Returns:
- the revision vector.
- Throws:
IllegalArgumentException
- if the string is malformed
-
asTrunkRevision
Returns a revision vector where all revision elements are turned into trunk revisions.- Returns:
- a trunk representation of this revision vector.
-
asBranchRevision
A clone of this revision vector with the revision for the given clusterId set to a branch revision.- Parameters:
clusterId
- the clusterId of the revision to be turned into a branch revision.- Returns:
- the revision vector with the branch revision.
- Throws:
IllegalArgumentException
- if there is no revision element with the given clusterId.
-
getDimensions
public int getDimensions()Returns the dimensions of this revision vector. That is, the number of revision elements in this vector.- Returns:
- the number of revision elements in this vector.
-
getMemory
public int getMemory()Description copied from interface:CacheValue
The estimated amount of memory used by this object, in bytes.- Specified by:
getMemory
in interfaceCacheValue
- Returns:
- the estimated number of bytes
-
compareTo
- Specified by:
compareTo
in interfaceComparable<RevisionVector>
-
iterator
-
toString
-
equals
-
hashCode
public int hashCode()
-