Class ByteValue
This class extends Value<Byte> and adds convenience methods for incrementing,
decrementing, and testing byte values, which are useful in lambdas and byte manipulation operations.
Notes:
- This class is not thread-safe. For concurrent access, use synchronization or atomic classes.
Example:
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the specified value to the current value.Adds the specified value to the current value and returns the new value.static ByteValuecreate()Creates a new byte value initialized to0 .Decrements the value by 1.Decrements the value by 1 and returns the new value.Increments the value by 1.Increments the value by 1 and returns the new value.booleanChecks if the current value is equal to the specified value.booleanChecks if the current value matches any of the specified values.static ByteValueCreates a new byte value with the specified initial value.
-
Constructor Details
-
ByteValue
public ByteValue()Constructor. -
ByteValue
Constructor.- Parameters:
value- The initial value.
-
-
Method Details
-
create
Creates a new byte value initialized to0 .Example:
ByteValue
counter = ByteValue.create ();assertEquals (0,counter .get());- Returns:
- A new byte value.
-
of
Creates a new byte value with the specified initial value.Example:
ByteValue
value = ByteValue.of ((byte )42);assertEquals (42,value .get());- Parameters:
value- The initial value.- Returns:
- A new byte value.
-
add
Adds the specified value to the current value.Example:
ByteValue
value = ByteValue.of ((byte )10);value .add((byte )5);assertEquals (15,value .get());- Parameters:
x- The value to add.- Returns:
- This object.
-
addAndGet
Adds the specified value to the current value and returns the new value.Example:
ByteValue
value = ByteValue.of ((byte )10);byte result =value .addAndGet((byte )5);// Returns 15 assertEquals (15,value .get());- Parameters:
x- The value to add.- Returns:
- The new value after addition.
-
decrement
Decrements the value by 1.Example:
ByteValue
counter = ByteValue.of ((byte )5);counter .decrement();assertEquals (4,counter .get());- Returns:
- This object.
-
decrementAndGet
Decrements the value by 1 and returns the new value.Example:
ByteValue
counter = ByteValue.of ((byte )5);byte result =counter .decrementAndGet();// Returns 4 assertEquals (4,counter .get());- Returns:
- The decremented value.
-
increment
Increments the value by 1.Example:
ByteValue
counter = ByteValue.of ((byte )5);counter .increment();assertEquals (6,counter .get());- Returns:
- This object.
-
incrementAndGet
Increments the value by 1 and returns the new value.Example:
ByteValue
counter = ByteValue.of ((byte )5);byte result =counter .incrementAndGet();// Returns 6 assertEquals (6,counter .get());- Returns:
- The incremented value.
-
is
Checks if the current value is equal to the specified value.Uses
Utils.eq(Object, Object)for deep equality comparison, which handles nulls safely.Example:
ByteValue
value = ByteValue.of ((byte )42);assertTrue (value .is((byte )42));assertFalse (value .is((byte )43)); -
isAny
Checks if the current value matches any of the specified values.Uses
Utils.eq(Object, Object)for deep equality comparison of each value.Example:
ByteValue
value = ByteValue.of ((byte )5);assertTrue (value .isAny((byte )3, (byte )5, (byte )7));assertFalse (value .isAny((byte )1, (byte )2));- Parameters:
values- The values to compare to.- Returns:
true if the current value matches any of the specified values.
-