public final class FlowControlUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> int |
addWithOverflowProtection(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> updater,
T owner,
int amount)
Increment an
integer referred by AtomicIntegerFieldUpdater atomically
and saturate to Integer.MAX_VALUE if overflow occurs. |
static <T> long |
addWithOverflowProtection(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater,
T owner,
long amount)
Increment a
long referred by AtomicLongFieldUpdater atomically
and saturate to Long.MAX_VALUE if overflow occurs. |
static int |
addWithOverflowProtection(int x,
int y)
Adds two positive ints and returns
Integer.MAX_VALUE if overflow occurs. |
static long |
addWithOverflowProtection(long x,
long y)
Adds two positive longs and returns
Long.MAX_VALUE if overflow occurs. |
static long |
addWithOverflowProtectionIfGtEqNegativeOne(long x,
long y)
|
static int |
addWithOverflowProtectionIfNotNegative(int x,
int y)
If
x is non-negative this method behaves the same as addWithOverflowProtection(int, int). |
static long |
addWithOverflowProtectionIfNotNegative(long x,
long y)
If
x is non-negative this method behaves the same as addWithOverflowProtection(long, long). |
static int |
addWithOverflowProtectionIfPositive(int x,
int y)
If
x is positive this method behaves the same as addWithOverflowProtection(int, int). |
static long |
addWithOverflowProtectionIfPositive(long x,
long y)
If
x is positive this method behaves the same as addWithOverflowProtection(long, long). |
static long |
subtractIfPositive(long x,
long y)
Subtract
y from x if x is positive. |
public static long addWithOverflowProtectionIfGtEqNegativeOne(long x,
long y)
x is >=-1 this method behaves the same as addWithOverflowProtection(long, long).
If x is <-1 then x is returned.x - first value (may be negative).y - second value (should be positive).x+y or Long.MAX_VALUE if overflow occurs, or x if x<-1.public static long addWithOverflowProtectionIfNotNegative(long x,
long y)
x is non-negative this method behaves the same as addWithOverflowProtection(long, long).
If x is negative then x is returned.x - first value (may be negative).y - second value (should be positive).x+y or Long.MAX_VALUE if overflow occurs, or x if x is
negative.public static int addWithOverflowProtectionIfNotNegative(int x,
int y)
x is non-negative this method behaves the same as addWithOverflowProtection(int, int).
If x is negative then x is returned.x - first value (may be negative).y - second value (should be positive).x+y or Integer.MAX_VALUE if overflow occurs, or x if x is
negative.public static int addWithOverflowProtectionIfPositive(int x,
int y)
x is positive this method behaves the same as addWithOverflowProtection(int, int).
If x is negative or zero then x is returned.x - first value (may be negative).y - second value (should be positive).x+y or Integer.MAX_VALUE if overflow occurs, or x if x is
negative.public static long addWithOverflowProtectionIfPositive(long x,
long y)
x is positive this method behaves the same as addWithOverflowProtection(long, long).
If x is negative or zero then x is returned.x - first value (may be negative).y - second value (should be positive).x+y or Long.MAX_VALUE if overflow occurs, or x if x is
negative.public static long subtractIfPositive(long x,
long y)
y from x if x is positive.x - first value (may be negative).y - second value (should be positive).x-y if x>0, or x.public static long addWithOverflowProtection(long x,
long y)
Long.MAX_VALUE if overflow occurs.x - first value (should be positive).y - second value (should be positive).x+y or Long.MAX_VALUE if overflow occurs.public static int addWithOverflowProtection(int x,
int y)
Integer.MAX_VALUE if overflow occurs.x - first value (should be positive).y - second value (should be positive).x+y or Integer.MAX_VALUE if overflow occurs.public static <T> int addWithOverflowProtection(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> updater,
T owner,
int amount)
integer referred by AtomicIntegerFieldUpdater atomically
and saturate to Integer.MAX_VALUE if overflow occurs.T - Type of the owner.updater - AtomicIntegerFieldUpdater used to atomically increment.owner - Owner class of AtomicIntegerFieldUpdater.amount - Amount to increment.int referred by AtomicIntegerFieldUpdater after the increment.public static <T> long addWithOverflowProtection(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater,
T owner,
long amount)
long referred by AtomicLongFieldUpdater atomically
and saturate to Long.MAX_VALUE if overflow occurs.T - Type of the owner.updater - AtomicLongFieldUpdater used to atomically increment.owner - Owner class of AtomicLongFieldUpdater.amount - Amount to increment.long referred by AtomicLongFieldUpdater after the increment.