mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-10-31 17:25:58 +01:00
Add NumberUtil.requireUShort16(int)
This commit is contained in:
parent
b3b242f397
commit
b834df65e9
1 changed files with 15 additions and 0 deletions
|
@ -43,4 +43,19 @@ public class NumberUtil {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue