is there anything similar in JDK or Apache Commons (or in another bank)?
/** * Return the integer positive value of the byte. (eg -128 will return * 128; -127 will return 129; -126 will return 130...) */ public static int toPositiveInt(byte b) { int intV = b; if (intV < 0) { intV = -intV; int diff = ((Byte.MAX_VALUE + 1) - intV) + 1; intV = Byte.MAX_VALUE + diff; } return intV; }
Usually some basic bit manipulations are used for this:
public static int toPositiveInt(byte b) { return b & 0xFF; }
And since it is so short, it is usually built-in and not called as a method.
https://fooobar.com/questions/1253829/materialize-framework-validation-of-required-field-not-working