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 RevisionVectorasBranchRevision(int clusterId)A clone of this revision vector with the revision for the given clusterId set to a branch revision.StringasString()Returns a string representation of this revision vector, which can be parsed again byfromString(String).RevisionVectorasTrunkRevision()Returns a revision vector where all revision elements are turned into trunk revisions.intcompareTo(@NotNull RevisionVector other)RevisionVectordifference(RevisionVector vector)Returns the difference of this and the other vector.booleanequals(Object o)static RevisionVectorfromString(String s)Creates a revision vector from a string representation as returned byasString().@NotNull RevisiongetBranchRevision()intgetDimensions()Returns the dimensions of this revision vector.intgetMemory()The estimated amount of memory used by this object, in bytes.RevisiongetRevision(int clusterId)Returns the revision element with the given clusterId ornullif there is no such revision in this vector.inthashCode()booleanisBranch()booleanisRevisionNewer(@NotNull Revision revision)Returnstrueif the given revision is newer than the revision element with the same clusterId in the vector.Iterator<Revision>iterator()RevisionVectorpmax(@NotNull RevisionVector vector)Calculates the parallel maximum of this and the givenvector.RevisionVectorpmin(@NotNull RevisionVector vector)Calculates the parallel minimum of this and the givenvector.RevisionVectorremove(int clusterId)Returns a RevisionVector without the revision element with the givenclusterId.StringtoString()StringBuildertoStringBuilder(StringBuilder sb)Appends the string representation of this revision vector to the passedStringBuilder.RevisionVectorupdate(@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)Returnstrueif 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:
trueif considered newer,falseotherwise.
-
isBranch
public boolean isBranch()
- Returns:
trueif any of the revisions in this vector is a branch revision,falseotherwise.
-
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 ornullif there is no such revision in this vector.- Parameters:
clusterId- a clusterId.- Returns:
- the revision element with the given clusterId or
nullif 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- theStringBuilderthis revision vector is appended to.- Returns:
- the passed
StringBuilderobject.
-
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:CacheValueThe estimated amount of memory used by this object, in bytes.- Specified by:
getMemoryin interfaceCacheValue- Returns:
- the estimated number of bytes
-
compareTo
public int compareTo(@NotNull @NotNull RevisionVector other)- Specified by:
compareToin interfaceComparable<RevisionVector>
-
-