Allow BigInt/BigInteger increments/decrements for PNCounter #25543
This commit is contained in:
parent
4456d7752b
commit
18b2d85216
3 changed files with 85 additions and 3 deletions
|
|
@ -62,6 +62,12 @@ final class PNCounter private[akka] (
|
|||
*/
|
||||
def +(n: Long)(implicit node: Cluster): PNCounter = increment(node, n)
|
||||
|
||||
/**
|
||||
* Increment the counter with the delta `n` specified.
|
||||
* If the delta is negative then it will decrement instead of increment.
|
||||
*/
|
||||
def +(n: BigInt)(implicit node: Cluster): PNCounter = increment(node, n)
|
||||
|
||||
/**
|
||||
* Increment the counter with the delta `n` specified.
|
||||
* If the delta is negative then it will decrement instead of increment.
|
||||
|
|
@ -69,12 +75,32 @@ final class PNCounter private[akka] (
|
|||
def increment(node: Cluster, n: Long = 1): PNCounter =
|
||||
increment(node.selfUniqueAddress, n)
|
||||
|
||||
/**
|
||||
* Scala API: Increment the counter with the delta `n` specified.
|
||||
* If the delta is negative then it will decrement instead of increment.
|
||||
*/
|
||||
def increment(node: Cluster, n: BigInt): PNCounter =
|
||||
increment(node.selfUniqueAddress, n)
|
||||
|
||||
/**
|
||||
* Java API: Increment the counter with the delta `n` specified.
|
||||
* If the delta is negative then it will decrement instead of increment.
|
||||
*/
|
||||
def increment(node: Cluster, n: java.math.BigInteger): PNCounter =
|
||||
increment(node.selfUniqueAddress, n)
|
||||
|
||||
/**
|
||||
* Decrement the counter with the delta `n` specified.
|
||||
* If the delta is negative then it will increment instead of decrement.
|
||||
*/
|
||||
def -(n: Long)(implicit node: Cluster): PNCounter = decrement(node, n)
|
||||
|
||||
/**
|
||||
* Decrement the counter with the delta `n` specified.
|
||||
* If the delta is negative then it will increment instead of decrement.
|
||||
*/
|
||||
def -(n: BigInt)(implicit node: Cluster): PNCounter = decrement(node, n)
|
||||
|
||||
/**
|
||||
* Decrement the counter with the delta `n` specified.
|
||||
* If the delta `n` is negative then it will increment instead of decrement.
|
||||
|
|
@ -82,12 +108,26 @@ final class PNCounter private[akka] (
|
|||
def decrement(node: Cluster, n: Long = 1): PNCounter =
|
||||
decrement(node.selfUniqueAddress, n)
|
||||
|
||||
private[akka] def increment(key: UniqueAddress, n: Long): PNCounter = change(key, n)
|
||||
/**
|
||||
* Scala API: Decrement the counter with the delta `n` specified.
|
||||
* If the delta `n` is negative then it will increment instead of decrement.
|
||||
*/
|
||||
def decrement(node: Cluster, n: BigInt): PNCounter =
|
||||
decrement(node.selfUniqueAddress, n)
|
||||
|
||||
/**
|
||||
* Java API: Decrement the counter with the delta `n` specified.
|
||||
* If the delta `n` is negative then it will increment instead of decrement.
|
||||
*/
|
||||
def decrement(node: Cluster, n: java.math.BigInteger): PNCounter =
|
||||
decrement(node.selfUniqueAddress, n)
|
||||
|
||||
private[akka] def increment(key: UniqueAddress, n: BigInt): PNCounter = change(key, n)
|
||||
private[akka] def increment(key: UniqueAddress): PNCounter = increment(key, 1)
|
||||
private[akka] def decrement(key: UniqueAddress, n: Long): PNCounter = change(key, -n)
|
||||
private[akka] def decrement(key: UniqueAddress, n: BigInt): PNCounter = change(key, -n)
|
||||
private[akka] def decrement(key: UniqueAddress): PNCounter = decrement(key, 1)
|
||||
|
||||
private[akka] def change(key: UniqueAddress, n: Long): PNCounter =
|
||||
private[akka] def change(key: UniqueAddress, n: BigInt): PNCounter =
|
||||
if (n > 0) copy(increments = increments.increment(key, n))
|
||||
else if (n < 0) copy(decrements = decrements.increment(key, -n))
|
||||
else this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue