Interface PNCounter

  • All Superinterfaces:
    Crdt

    public interface PNCounter
    extends Crdt
    A Positive-Negative Counter.

    A Positive-Negative Counter is a counter that allows both incrementing, and decrementing. It is based on two GCounter's, a positive one that is incremented for every increment, and a negative one that is incremented for every decrement. The current value of the counter is calculated by subtracting the negative counter from the positive counter.

    • Method Detail

      • getValue

        long getValue()
        Get the current value of the counter.
        Returns:
        The current value of the counter.
      • increment

        long increment​(long by)
        Increment the counter.

        If by is negative, then the counter will be decremented by that much instead.

        Parameters:
        by - The amount to increment the counter by.
        Returns:
        The new value of the counter.
      • decrement

        long decrement​(long by)
        Decrement the counter.

        If by is negative, then the counter will be incremented by that much instead.

        Parameters:
        by - The amount to decrement the counter by.
        Returns:
        The new value of the counter.