Example usage for java.lang Byte MAX_VALUE

List of usage examples for java.lang Byte MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Byte MAX_VALUE.

Prototype

byte MAX_VALUE

To view the source code for java.lang Byte MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value a byte can have, 27-1.

Usage

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java

@Test
public void testConfigurationXMLWithByteArray() {
    ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray();

    Byte byteValue = config.byteArray[0];

    assertEquals(Byte.class, byteValue.getClass());
    assertEquals(Byte.MAX_VALUE, byteValue.byteValue());
    assertEquals(8, config.byteArray.length);
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java

@Test
public void testConfigurationXMLWithByteList() {
    ConfigurationXMLWithList config = prepareConfigurationXMLWithList();

    Byte byteValue = config.byteList.get(0);

    assertEquals(Byte.class, byteValue.getClass());
    assertEquals(Byte.MAX_VALUE, byteValue.byteValue());
    assertEquals(8, config.byteList.size());
}

From source file:org.lwes.db.EventTemplateDB.java

/**
 * This method checks the type and range of a default value (from the ESF).
 * It returns the desired form, if allowed.
 *
 * @param type     which controls the desired object type of the value
 * @param esfValue which should be converted to fit 'type'
 * @return a value suitable for storing in a BaseType of this 'type'
 * @throws EventSystemException if the value is not acceptable for the type.
 *//*from  w w  w.j a  v a2s.c  om*/
@SuppressWarnings("cast")
private Object canonicalizeDefaultValue(String eventName, String attributeName, FieldType type, Object esfValue)
        throws EventSystemException {
    try {
        switch (type) {
        case BOOLEAN:
            return (Boolean) esfValue;
        case BYTE:
            checkRange(eventName, attributeName, esfValue, Byte.MIN_VALUE, Byte.MAX_VALUE);
            return ((Number) esfValue).byteValue();
        case INT16:
            checkRange(eventName, attributeName, esfValue, Short.MIN_VALUE, Short.MAX_VALUE);
            return ((Number) esfValue).shortValue();
        case INT32:
            checkRange(eventName, attributeName, esfValue, Integer.MIN_VALUE, Integer.MAX_VALUE);
            return ((Number) esfValue).intValue();
        case UINT16:
            checkRange(eventName, attributeName, esfValue, 0, 0x10000);
            return ((Number) esfValue).intValue() & 0xffff;
        case UINT32:
            checkRange(eventName, attributeName, esfValue, 0, 0x100000000L);
            return ((Number) esfValue).longValue() & 0xffffffff;
        case FLOAT:
            return ((Number) esfValue).floatValue();
        case DOUBLE:
            return ((Number) esfValue).doubleValue();
        case STRING:
            return ((String) esfValue);
        case INT64: {
            if (esfValue instanceof Long) {
                return esfValue;
            }
            final BigInteger bi = (BigInteger) esfValue;
            if (bi.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0
                    || bi.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
                throw new EventSystemException(
                        String.format("Field %s.%s value %s outside allowed range [%d,%d]", eventName,
                                attributeName, esfValue, Long.MIN_VALUE, Long.MAX_VALUE));
            }
            return bi.longValue();
        }
        case UINT64: {
            if (esfValue instanceof BigInteger) {
                return esfValue;
            }
            return BigInteger.valueOf(((Number) esfValue).longValue());
        }
        case IPADDR:
            return ((IPAddress) esfValue);
        case BOOLEAN_ARRAY:
        case BYTE_ARRAY:
        case DOUBLE_ARRAY:
        case FLOAT_ARRAY:
        case INT16_ARRAY:
        case INT32_ARRAY:
        case INT64_ARRAY:
        case IP_ADDR_ARRAY:
        case STRING_ARRAY:
        case UINT16_ARRAY:
        case UINT32_ARRAY:
        case UINT64_ARRAY:
        case NBOOLEAN_ARRAY:
        case NBYTE_ARRAY:
        case NDOUBLE_ARRAY:
        case NFLOAT_ARRAY:
        case NINT16_ARRAY:
        case NINT32_ARRAY:
        case NINT64_ARRAY:
        case NSTRING_ARRAY:
        case NUINT16_ARRAY:
        case NUINT32_ARRAY:
        case NUINT64_ARRAY:
            throw new EventSystemException("Unsupported default value type " + type);
        }
        throw new EventSystemException("Unrecognized type " + type + " for value " + esfValue);
    } catch (ClassCastException e) {
        throw new EventSystemException("Type " + type + " had an inappropriate default value " + esfValue);
    }
}

From source file:org.apache.flink.table.codegen.SortCodeGeneratorTest.java

private Object value3(InternalType type, Random rnd) {
    if (type.equals(InternalTypes.BOOLEAN)) {
        return true;
    } else if (type.equals(InternalTypes.BYTE)) {
        return Byte.MAX_VALUE;
    } else if (type.equals(InternalTypes.SHORT)) {
        return Short.MAX_VALUE;
    } else if (type.equals(InternalTypes.INT)) {
        return Integer.MAX_VALUE;
    } else if (type.equals(InternalTypes.LONG)) {
        return Long.MAX_VALUE;
    } else if (type.equals(InternalTypes.FLOAT)) {
        return Float.MAX_VALUE;
    } else if (type.equals(InternalTypes.DOUBLE)) {
        return Double.MAX_VALUE;
    } else if (type.equals(InternalTypes.STRING)) {
        return BinaryString.fromString(RandomStringUtils.random(100));
    } else if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        return Decimal.fromBigDecimal(new BigDecimal(Integer.MAX_VALUE), decimalType.precision(),
                decimalType.scale());//from ww  w. jav a 2  s  .c  om
    } else if (type instanceof ArrayType || type.equals(InternalTypes.BINARY)) {
        byte[] bytes = new byte[rnd.nextInt(100) + 100];
        rnd.nextBytes(bytes);
        return type.equals(InternalTypes.BINARY) ? bytes : BinaryArray.fromPrimitiveArray(bytes);
    } else if (type instanceof RowType) {
        RowType rowType = (RowType) type;
        if (rowType.getTypeAt(0).equals(InternalTypes.INT)) {
            return GenericRow.of(rnd.nextInt());
        } else {
            return GenericRow.of(GenericRow.of(rnd.nextInt()));
        }
    } else if (type instanceof GenericType) {
        return new BinaryGeneric<>(rnd.nextInt(), IntSerializer.INSTANCE);
    } else {
        throw new RuntimeException("Not support!");
    }
}

From source file:com.tasktop.c2c.server.common.service.tests.ajp.AjpProtocolTest.java

private byte[] createData(int size) {
    byte[] data = new byte[size];
    for (int x = 0; x < data.length; ++x) {
        data[x] = (byte) (Math.abs(random.nextInt()) % Byte.MAX_VALUE);
    }/*from  ww  w.j  ava  2s  . c o m*/
    return data;
}

From source file:sx.blah.discord.SpoofBot.java

/**
 * Gets a random number based on the number type provided.
 *
 * @param clazz The number type class./* w ww .j  a va 2  s  . c  om*/
 * @return The randomized number.
 */
public static Number getRandNumber(Class<? extends Number> clazz) {
    Long bound;
    try {
        Field max_value = clazz.getDeclaredField("MAX_VALUE");
        bound = (Long) max_value.get(null);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        bound = (long) Byte.MAX_VALUE; //Supports all possible number types
    }
    return rng.nextDouble() * bound;
}

From source file:org.lwes.EventTest.java

@Test
public void testIntBounds() {
    final Event evt = createEvent();
    evt.setEventName("Test");

    evt.setByte("byte_min", Byte.MIN_VALUE);
    evt.setByte("byte_zero", (byte) 0);
    evt.setByte("byte_one", (byte) 1);
    evt.setByte("byte_max", Byte.MAX_VALUE);

    evt.setInt16("int16_min", Short.MIN_VALUE);
    evt.setInt16("int16_zero", (short) 0);
    evt.setInt16("int16_one", (short) 1);
    evt.setInt16("int16_max", Short.MAX_VALUE);

    evt.setInt32("int32_min", Integer.MIN_VALUE);
    evt.setInt32("int32_zero", 0);
    evt.setInt32("int32_one", 1);
    evt.setInt32("int32_max", Integer.MAX_VALUE);

    evt.setInt64("int64_min", Long.MIN_VALUE);
    evt.setInt64("int64_zero", 0);
    evt.setInt64("int64_one", 1);
    evt.setInt64("int64_max", Long.MAX_VALUE);

    evt.setUInt16("uint16_zero", 0);
    evt.setUInt16("uint16_one", 1);
    evt.setUInt16("uint16_max", 0xffff);

    evt.setUInt32("uint32_zero", 0);
    evt.setUInt32("uint32_one", 1);
    evt.setUInt32("uint32_max", 0xffffffffL);

    evt.setUInt64("uint64_zero", BigInteger.ZERO);
    evt.setUInt64("uint64_one", BigInteger.ONE);
    evt.setUInt64("uint64_max", BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE));

    evt.setInt16Array("int16[]", new short[] { Short.MIN_VALUE, 0, 1, Short.MAX_VALUE });
    evt.setInt32Array("int32[]", new int[] { Integer.MIN_VALUE, 0, 1, Integer.MAX_VALUE });
    evt.setInt64Array("int64[]", new long[] { Long.MIN_VALUE, 0, 1, Long.MAX_VALUE });
    evt.setUInt16Array("uint16[]", new int[] { 0, 1, 0xffff });
    evt.setUInt32Array("uint32[]", new long[] { 0, 1, 0xffffffffL });
    evt.setUInt64Array("uint64[]", new BigInteger[] { BigInteger.ZERO, BigInteger.ONE,
            BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE) });
    evt.setUInt64Array("uint64[] prim", new long[] { 0, 1, -1 });

    final Event evt2 = createEvent();
    evt2.deserialize(evt.serialize());//from   w ww. j a  v  a  2s . c o  m
    //assertEquals(evt, evt2);

    assertEquals(Byte.MIN_VALUE, evt.getByte("byte_min").byteValue());
    assertEquals((byte) 0, evt.getByte("byte_zero").byteValue());
    assertEquals((byte) 1, evt.getByte("byte_one").byteValue());
    assertEquals(Byte.MAX_VALUE, evt.getByte("byte_max").byteValue());

    assertEquals(Short.MIN_VALUE, evt.getInt16("int16_min").shortValue());
    assertEquals((short) 0, evt.getInt16("int16_zero").shortValue());
    assertEquals((short) 1, evt.getInt16("int16_one").shortValue());
    assertEquals(Short.MAX_VALUE, evt.getInt16("int16_max").shortValue());

    assertEquals(Integer.MIN_VALUE, evt.getInt32("int32_min").intValue());
    assertEquals(0, evt.getInt32("int32_zero").intValue());
    assertEquals(1, evt.getInt32("int32_one").intValue());
    assertEquals(Integer.MAX_VALUE, evt.getInt32("int32_max").intValue());

    assertEquals(Long.MIN_VALUE, evt.getInt64("int64_min").longValue());
    assertEquals(0, evt.getInt64("int64_zero").longValue());
    assertEquals(1, evt.getInt64("int64_one").longValue());
    assertEquals(Long.MAX_VALUE, evt.getInt64("int64_max").longValue());

    assertEquals(0, evt.getUInt16("uint16_zero").intValue());
    assertEquals(1, evt.getUInt16("uint16_one").intValue());
    assertEquals(0xffff, evt.getUInt16("uint16_max").intValue());

    assertEquals(0, evt.getUInt32("uint32_zero").longValue());
    assertEquals(1, evt.getUInt32("uint32_one").longValue());
    assertEquals(0xffffffffL, evt.getUInt32("uint32_max").longValue());

    assertEquals(BigInteger.ZERO, evt.getUInt64("uint64_zero"));
    assertEquals(BigInteger.ONE, evt.getUInt64("uint64_one"));
    assertEquals(BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE), evt.getUInt64("uint64_max"));

    assertArrayEquals(new short[] { Short.MIN_VALUE, 0, 1, Short.MAX_VALUE }, evt.getInt16Array("int16[]"));
    assertArrayEquals(new int[] { Integer.MIN_VALUE, 0, 1, Integer.MAX_VALUE }, evt.getInt32Array("int32[]"));
    assertArrayEquals(new long[] { Long.MIN_VALUE, 0, 1, Long.MAX_VALUE }, evt.getInt64Array("int64[]"));
    assertArrayEquals(new int[] { 0, 1, 0xffff }, evt.getUInt16Array("uint16[]"));
    assertArrayEquals(new long[] { 0, 1, 0xffffffffL }, evt.getUInt32Array("uint32[]"));
    assertArrayEquals(new BigInteger[] { BigInteger.ZERO, BigInteger.ONE,
            BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE) }, evt.getUInt64Array("uint64[]"));
    assertArrayEquals(
            new BigInteger[] { BigInteger.ZERO, BigInteger.ONE,
                    BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE) },
            evt.getUInt64Array("uint64[] prim"));
}

From source file:org.vertx.java.http.eventbusbridge.integration.MessageSendTest.java

@Test
public void testSendingByteXml() throws IOException {
    final EventBusMessageType messageType = EventBusMessageType.Byte;
    final Byte sentByte = Byte.MAX_VALUE;
    Map<String, String> expectations = createExpectations("someaddress",
            Base64.encodeAsString(sentByte.toString()), messageType);
    Handler<Message> messageConsumerHandler = new MessageSendHandler(sentByte, expectations);
    vertx.eventBus().registerHandler(expectations.get("address"), messageConsumerHandler);
    String body = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_XML, expectations);
    HttpRequestHelper.sendHttpPostRequest(url, body, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(),
            MediaType.APPLICATION_XML);//  w  ww  .  ja  v  a2  s . co  m
}

From source file:edu.pdi2.visual.ThresholdSignature.java

/**
 * Devuelve un vector que indica el tope de valores que puede tener una
 * firma para ser considerada como "similar".
 *///from   w w w .j  av a  2 s.c  o  m
public byte[] getTopSignature() {
    byte[] top = new byte[signature.length];

    for (int i = 0; i < top.length; ++i)
        top[i] = (byte) Math.min(Byte.MAX_VALUE, signature[i] + banda[i]);

    return top;
}

From source file:org.cellprofiler.subimager.ImageWriterHandler.java

private byte[] convertImage(NDImage ndimage, PixelType pixelType, boolean toBigEndian) {
    double[] inputDouble = ndimage.getBuffer();
    switch (pixelType) {
    case INT8:/*www  .  j av  a 2s. co m*/
        return convertToIntegerType(inputDouble, Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.SIZE / 8, toBigEndian);
    case UINT8:
        return convertToIntegerType(inputDouble, 0, (1L << Byte.SIZE) - 1, Byte.SIZE / 8, toBigEndian);
    case INT16:
        return convertToIntegerType(inputDouble, Short.MIN_VALUE, Short.MAX_VALUE, Short.SIZE / 8, toBigEndian);
    case UINT16:
        return convertToIntegerType(inputDouble, 0, (1L << Short.SIZE) - 1, Short.SIZE / 8, toBigEndian);
    case INT32:
        return convertToIntegerType(inputDouble, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.SIZE / 8,
                toBigEndian);
    case UINT32:
        return convertToIntegerType(inputDouble, 0, (1L << Integer.SIZE) - 1, Integer.SIZE / 8, toBigEndian);
    case FLOAT: {
        int bpp = Float.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Float.floatToIntBits((float) inputDouble[i]), buffer, i * bpp, bpp,
                    !toBigEndian);
        }
        return buffer;
    }
    case DOUBLE: {
        int bpp = Double.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Double.doubleToLongBits(inputDouble[i]), buffer, i * bpp, bpp, !toBigEndian);
        }
        return buffer;
    }
    default:
        throw new UnsupportedOperationException("The pixel type, " + pixelType.getValue()
                + ", should have been explicitly handled by the caller and an error should have been reported to the web client.");
    }
}