Class RevisionVector

  • All Implemented Interfaces:
    java.lang.Comparable<RevisionVector>, java.lang.Iterable<Revision>, CacheValue

    public final class RevisionVector
    extends java.lang.Object
    implements java.lang.Iterable<Revision>, java.lang.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 Detail

      • RevisionVector

        public RevisionVector​(@NotNull
                              @NotNull Revision... revisions)
      • RevisionVector

        public RevisionVector​(@NotNull
                              @NotNull java.lang.Iterable<Revision> revisions)
      • RevisionVector

        public RevisionVector​(@NotNull
                              @NotNull java.util.Set<Revision> revisions)
    • Method Detail

      • update

        public RevisionVector update​(@NotNull
                                     @NotNull Revision revision)
        Creates a new revision vector with based on this vector and the given revision. If this vector contains a revision with the same clusterId as revision, 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 given revision.
        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 given clusterId.
        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 given vector.
        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 given vector.
        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)
        Returns true 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:
        java.lang.IllegalStateException - if this vector does not contain a branch revision.
      • getRevision

        public Revision getRevision​(int clusterId)
        Returns the revision element with the given clusterId or null 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 java.lang.String asString()
        Returns a string representation of this revision vector, which can be parsed again by fromString(String).
        Returns:
        a string representation of this revision vector.
      • toStringBuilder

        public java.lang.StringBuilder toStringBuilder​(java.lang.StringBuilder sb)
        Appends the string representation of this revision vector to the passed StringBuilder. The string representation is the same as returned by asString().
        Parameters:
        sb - the StringBuilder this revision vector is appended to.
        Returns:
        the passed StringBuilder object.
      • fromString

        public static RevisionVector fromString​(java.lang.String s)
        Creates a revision vector from a string representation as returned by asString().
        Parameters:
        s - the string representation of a revision vector.
        Returns:
        the revision vector.
        Throws:
        java.lang.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:
        java.lang.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 interface CacheValue
        Returns:
        the estimated number of bytes
      • compareTo

        public int compareTo​(@NotNull
                             @NotNull RevisionVector other)
        Specified by:
        compareTo in interface java.lang.Comparable<RevisionVector>
      • iterator

        public java.util.Iterator<Revision> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Revision>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object