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 likeupdate(Revision)
create a new instance as needed. This class implementsComparable
. WhilecompareTo(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
Constructors Constructor Description RevisionVector(@NotNull Iterable<Revision> revisions)
RevisionVector(@NotNull Set<Revision> revisions)
RevisionVector(@NotNull Revision... revisions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RevisionVector
asBranchRevision(int clusterId)
A clone of this revision vector with the revision for the given clusterId set to a branch revision.String
asString()
Returns a string representation of this revision vector, which can be parsed again byfromString(String)
.RevisionVector
asTrunkRevision()
Returns a revision vector where all revision elements are turned into trunk revisions.int
compareTo(@NotNull RevisionVector other)
RevisionVector
difference(RevisionVector vector)
Returns the difference of this and the other vector.boolean
equals(Object o)
static RevisionVector
fromString(String s)
Creates a revision vector from a string representation as returned byasString()
.@NotNull Revision
getBranchRevision()
int
getDimensions()
Returns the dimensions of this revision vector.int
getMemory()
The estimated amount of memory used by this object, in bytes.Revision
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<Revision>
iterator()
RevisionVector
pmax(@NotNull RevisionVector vector)
Calculates the parallel maximum of this and the givenvector
.RevisionVector
pmin(@NotNull RevisionVector vector)
Calculates the parallel minimum of this and the givenvector
.RevisionVector
remove(int clusterId)
Returns a RevisionVector without the revision element with the givenclusterId
.String
toString()
StringBuilder
toStringBuilder(StringBuilder sb)
Appends the string representation of this revision vector to the passedStringBuilder
.RevisionVector
update(@NotNull Revision revision)
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
-
-
-
-
Method Detail
-
update
public RevisionVector update(@NotNull @NotNull Revision revision)
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
public RevisionVector remove(int clusterId)
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
public RevisionVector pmin(@NotNull @NotNull RevisionVector vector)
Calculates the parallel minimum of this and the givenvector
.- Parameters:
vector
- the other vector.- Returns:
- the parallel minimum of the two.
-
pmax
public RevisionVector pmax(@NotNull @NotNull RevisionVector vector)
Calculates the parallel maximum of this and the givenvector
.- Parameters:
vector
- the other vector.- Returns:
- the parallel maximum of the two.
-
difference
public RevisionVector difference(RevisionVector vector)
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
public boolean isRevisionNewer(@NotNull @NotNull Revision revision)
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
@NotNull public @NotNull Revision getBranchRevision()
- Returns:
- the first branch revision in this vector.
- Throws:
IllegalStateException
- if this vector does not contain a branch revision.
-
getRevision
public Revision getRevision(int clusterId)
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
public String 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
public StringBuilder toStringBuilder(StringBuilder sb)
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
public static RevisionVector fromString(String s)
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
public RevisionVector asTrunkRevision()
Returns a revision vector where all revision elements are turned into trunk revisions.- Returns:
- a trunk representation of this revision vector.
-
asBranchRevision
public RevisionVector asBranchRevision(int clusterId)
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
public int compareTo(@NotNull @NotNull RevisionVector other)
- Specified by:
compareTo
in interfaceComparable<RevisionVector>
-
-