1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 06:12:05 +01:00

Add NumberUtil.requireUShort16(int)

This commit is contained in:
Florian Schmaus 2019-06-10 17:37:20 +02:00
parent b3b242f397
commit b834df65e9

View file

@ -43,4 +43,19 @@ public class NumberUtil {
throw new IllegalArgumentException("unsigned 32-bit integers can't be greater then 2^32 - 1"); throw new IllegalArgumentException("unsigned 32-bit integers can't be greater then 2^32 - 1");
} }
} }
/**
* Checks if the given int is within the range of an unsigned 16-bit integer, the XML type "xs:unsignedShort".
*
* @param value
*/
public static int requireUShort16(int value) {
if (value < 0) {
throw new IllegalArgumentException("unsigned 16-bit integers can't be negative");
}
if (value > ((1 << 16) - 1)) {
throw new IllegalArgumentException("unsigned 16-bit integers can't be greater than 2^16 - 1");
}
return value;
}
} }