Here you can find the source of toByteValue(final int value)
Parameter | Description |
---|---|
value | The value to convert. |
Parameter | Description |
---|---|
IllegalArgumentException | If<code>value < Byte#MIN_VALUE</code> or<code>value > #UNSIGNED_MAX</code>. |
static byte toByteValue(final int value) throws IllegalArgumentException
//package com.java2s; //License from project: Apache License public class Main { /** Maximum value of an unsigned 8-bit integer. */ static final int UNSIGNED_MAX = 0xFF; /**/*from w ww .ja va 2s . c o m*/ * Converts a signed or unsigned 8-bit integer into a byte. * @param value The value to convert. * @return A byte value equal to {@code (byte)value}. * @throws IllegalArgumentException If * <code>value < {@link Byte#MIN_VALUE}</code> or * <code>value > {@link #UNSIGNED_MAX}</code>. */ static byte toByteValue(final int value) throws IllegalArgumentException { checkByteValue(value); return (byte) value; } /** * Checks the given value as a signed or unsigned 8-bit integer. * @param value The value to check. * @throws IllegalArgumentException If * <code>value < {@link Byte#MIN_VALUE}</code> or * <code>value > {@link #UNSIGNED_MAX}</code>. */ static void checkByteValue(int value) throws IllegalArgumentException { if (value < Byte.MIN_VALUE) { throw new IllegalArgumentException(String.format("value (%d) < minimum (%d)", value, Byte.MIN_VALUE)); } else if (value > UNSIGNED_MAX) { throw new IllegalArgumentException(String.format("value (%d) > maximum (%d)", value, UNSIGNED_MAX)); } } }