Example usage for java.lang Byte MIN_VALUE

List of usage examples for java.lang Byte MIN_VALUE

Introduction

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

Prototype

byte MIN_VALUE

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

Click Source Link

Document

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

Usage

From source file:com.moz.fiji.schema.FormattedEntityId.java

/**
 * Create an hbase row key, which is a byte array from the given formatted fijiRowKey.
 * This method requires that the fijiRowKey argument is the correct length for the specified
 * format.//w  w  w .j  a  va2s. c o  m
 * The following encoding will be used to ensure correct ordering:
 * Strings are UTF-8 encoded and terminated by a null byte. Strings cannot contain "\u0000".
 * Integers are exactly 4 bytes long.
 * Longs are exactly 8 bytes long.
 * Both integers and longs have the sign bit flipped so that their values are wrapped around to
 * create the correct lexicographic ordering. (i.e. after converting to byte array,
 * MIN_INT < 0 < MAX_INT).
 * Hashed components are exactly hash_size bytes long and are the first component of
 * the hbase key.
 * Except for the first, all components of a fijiRowKey can be null. However, to maintain
 * ordering, all components to the right of a null component must also be null. Nullable index
 * in the row key format specifies which component (and hence following components) are nullable.
 * By default, the hash only uses the first component, but this can be changed using the Range
 * Scan index.
 *
 * @param format The formatted row key format for this table.
 * @param fijiRowKey An ordered list of Objects of the key components.
 * @return A byte array representing the encoded Hbase row key.
 */
private static byte[] makeHbaseRowKey(RowKeyFormat2 format, List<Object> fijiRowKey) {

    ArrayList<byte[]> hbaseKey = new ArrayList<byte[]>();
    final byte zeroDelim = 0;

    int pos;
    for (pos = 0; pos < fijiRowKey.size(); pos++) {
        // we have already done the validation check for null cascades.
        if (null == fijiRowKey.get(pos)) {
            continue;
        }
        byte[] tempBytes;
        switch (getType(fijiRowKey.get(pos))) {
        case STRING:
            if (((String) fijiRowKey.get(pos)).contains("\u0000")) {
                throw new EntityIdException("String component cannot contain \u0000");
            }
            try {
                hbaseKey.add(((String) fijiRowKey.get(pos)).getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                LOG.error(e.toString());
                throw new EntityIdException(String.format("UnsupportedEncoding for component %d", pos));
            }
            break;
        case INTEGER:
            int temp = (Integer) fijiRowKey.get(pos);
            tempBytes = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt(temp).array();
            tempBytes[0] = (byte) ((int) tempBytes[0] ^ (int) Byte.MIN_VALUE);
            hbaseKey.add(tempBytes);
            break;
        case LONG:
            long templong = (Long) fijiRowKey.get(pos);
            tempBytes = ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(templong).array();
            tempBytes[0] = (byte) ((int) tempBytes[0] ^ (int) Byte.MIN_VALUE);
            hbaseKey.add(tempBytes);
            break;
        default:
            throw new RuntimeException("Invalid code path");
        }
    }

    // hash stuff
    int hashUpto = format.getRangeScanStartIndex() - 1;
    ByteArrayOutputStream tohash = new ByteArrayOutputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (pos = 0; pos <= hashUpto && pos < hbaseKey.size(); pos++) {
        tohash.write(hbaseKey.get(pos), 0, hbaseKey.get(pos).length);
    }
    byte[] hashed = Arrays.copyOfRange(Hasher.hash(tohash.toByteArray()), 0, format.getSalt().getHashSize());
    baos.write(hashed, 0, hashed.length);

    // to materialize or not to materialize that is the question
    if (format.getSalt().getSuppressKeyMaterialization()) {
        return baos.toByteArray();
    } else {
        for (pos = 0; pos < hbaseKey.size(); pos++) {
            baos.write(hbaseKey.get(pos), 0, hbaseKey.get(pos).length);
            if (format.getComponents().get(pos).getType() == ComponentType.STRING
                    || format.getComponents().get(pos) == null) {
                // empty strings will be encoded as null, hence we need to delimit them too
                baos.write(zeroDelim);
            }
        }
        return baos.toByteArray();
    }
}

From source file:com.jcwhatever.nucleus.internal.managed.commands.Arguments.java

@Override
public byte getByte(String parameterName) throws InvalidArgumentException {
    return getByte(parameterName, Byte.MIN_VALUE, Byte.MAX_VALUE);
}

From source file:net.ymate.platform.core.lang.TreeObject.java

public TreeObject(Byte b) {
    _object = b != null ? b : Byte.MIN_VALUE;
    _type = TYPE_BYTE;
}

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 ww .ja va2 s .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.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  ww w. j  a v a2s  .  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:net.ymate.platform.commons.lang.TreeObject.java

/**
 * 
 *
 * @param b
 */
public TreeObject(Byte b) {
    _object = b != null ? b.byteValue() : Byte.MIN_VALUE;
    _type = TYPE_BYTE;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.ByteDataset.java

private void allocateArray(final int... nshape) {
    if (data == null) {
        throw new IllegalStateException("Data buffer in dataset is null");
    }/*from w w w  .  j a  v a 2s. c  o m*/

    if (dataShape != null) {
        // see if reserved space is sufficient
        if (isShapeInDataShape(nshape)) {
            shape = nshape;
            size = calcSize(shape);
            if (Arrays.equals(shape, dataShape)) {
                dataShape = null; // no reserved space
            }
            return;
        }
    }

    final IndexIterator iter = getIterator();

    // not enough room so need to expand the allocated memory
    if (dataShape == null)
        dataShape = shape.clone();
    expandDataShape(nshape);
    dataSize = calcSize(dataShape);

    final byte[] ndata = createArray(dataSize); // PRIM_TYPE
    final int[] oshape = shape;

    // now this object has the new dimensions so specify them correctly
    shape = nshape;
    size = calcSize(nshape);

    // make sure that all the data is set to NaN, minimum value or false
    Arrays.fill(ndata, Byte.MIN_VALUE); // CLASS_TYPE // DEFAULT_VAL

    // now copy the data back to the correct positions
    final IndexIterator niter = getSliceIterator(null, oshape, null);

    while (niter.hasNext() && iter.hasNext())
        ndata[niter.index] = data[iter.index];

    odata = data = ndata;

    // if fully expanded then reset the reserved space dimensions
    if (dataSize == size) {
        dataShape = null;
    }
}

From source file:org.apache.sysml.runtime.util.UtilFunctions.java

public static byte max(byte[] array) {
    byte ret = Byte.MIN_VALUE;
    for (int i = 0; i < array.length; i++)
        ret = (array[i] > ret) ? array[i] : ret;
    return ret;/*from   w  w w  . j  ava2  s .  com*/
}

From source file:org.kiji.schema.FormattedEntityId.java

/**
 * Decode a byte array containing an hbase row key into an ordered list corresponding to
 * the key format in the layout file./*ww w . j  a  v a  2 s  .  co  m*/
 *
 * @param format The row key format as specified in the layout file.
 * @param hbaseRowKey A byte array containing the hbase row key.
 * @return An ordered list of component values in the key.
 */
private static List<Object> makeKijiRowKey(RowKeyFormat2 format, byte[] hbaseRowKey) {
    if (hbaseRowKey.length == 0) {
        throw new EntityIdException("Invalid hbase row key");
    }
    List<Object> kijiRowKey = new ArrayList<Object>();
    // skip over the hash
    int pos = format.getSalt().getHashSize();
    // we are suppressing materialization, so the components cannot be retrieved.
    int kijiRowElem = 0;
    if (format.getSalt().getSuppressKeyMaterialization()) {
        if (pos < hbaseRowKey.length) {
            throw new EntityIdException("Extra bytes in key after hash when materialization is" + "suppressed");
        }
        return null;
    }
    ByteBuffer buf;

    while (kijiRowElem < format.getComponents().size() && pos < hbaseRowKey.length) {
        switch (format.getComponents().get(kijiRowElem).getType()) {
        case STRING:
            // Read the row key until we encounter a Null (0) byte or end.
            int endpos = pos;
            while (endpos < hbaseRowKey.length && (hbaseRowKey[endpos] != (byte) 0)) {
                endpos += 1;
            }
            String str = null;
            try {
                str = new String(hbaseRowKey, pos, endpos - pos, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                LOG.error(e.toString());
                throw new EntityIdException(String.format("UnsupportedEncoding for component %d", kijiRowElem));
            }
            kijiRowKey.add(str);
            pos = endpos + 1;
            break;
        case INTEGER:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Integer.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            kijiRowKey.add(Integer.valueOf(buf.getInt()));
            pos = pos + Integer.SIZE / Byte.SIZE;
            break;
        case LONG:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Long.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            kijiRowKey.add(Long.valueOf(buf.getLong()));
            pos = pos + Long.SIZE / Byte.SIZE;
            break;
        default:
            throw new RuntimeException("Invalid code path");
        }
        kijiRowElem += 1;
    }

    // Fail if there are extra bytes in hbase row key.
    if (pos < hbaseRowKey.length) {
        throw new EntityIdException("Extra bytes in hbase row key cannot be mapped to any " + "component");
    }

    // Fail if we encounter nulls before it is legal to do so.
    if (kijiRowElem < format.getNullableStartIndex()) {
        throw new EntityIdException("Too few components decoded from hbase row key. Component " + "number "
                + kijiRowElem + " cannot be null");
    }

    // finish up with nulls for everything that wasn't in the key
    for (; kijiRowElem < format.getComponents().size(); kijiRowElem++) {
        kijiRowKey.add(null);
    }

    return kijiRowKey;
}

From source file:com.moz.fiji.schema.FormattedEntityId.java

/**
 * Decode a byte array containing an hbase row key into an ordered list corresponding to
 * the key format in the layout file.//  ww w  . j  a v  a  2s.  c o m
 *
 * @param format The row key format as specified in the layout file.
 * @param hbaseRowKey A byte array containing the hbase row key.
 * @return An ordered list of component values in the key.
 */
private static List<Object> makeFijiRowKey(RowKeyFormat2 format, byte[] hbaseRowKey) {
    if (hbaseRowKey.length == 0) {
        throw new EntityIdException("Invalid hbase row key");
    }
    List<Object> fijiRowKey = new ArrayList<Object>();
    // skip over the hash
    int pos = format.getSalt().getHashSize();
    // we are suppressing materialization, so the components cannot be retrieved.
    int fijiRowElem = 0;
    if (format.getSalt().getSuppressKeyMaterialization()) {
        if (pos < hbaseRowKey.length) {
            throw new EntityIdException("Extra bytes in key after hash when materialization is" + "suppressed");
        }
        return null;
    }
    ByteBuffer buf;

    while (fijiRowElem < format.getComponents().size() && pos < hbaseRowKey.length) {
        switch (format.getComponents().get(fijiRowElem).getType()) {
        case STRING:
            // Read the row key until we encounter a Null (0) byte or end.
            int endpos = pos;
            while (endpos < hbaseRowKey.length && (hbaseRowKey[endpos] != (byte) 0)) {
                endpos += 1;
            }
            String str = null;
            try {
                str = new String(hbaseRowKey, pos, endpos - pos, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                LOG.error(e.toString());
                throw new EntityIdException(String.format("UnsupportedEncoding for component %d", fijiRowElem));
            }
            fijiRowKey.add(str);
            pos = endpos + 1;
            break;
        case INTEGER:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Integer.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            fijiRowKey.add(Integer.valueOf(buf.getInt()));
            pos = pos + Integer.SIZE / Byte.SIZE;
            break;
        case LONG:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Long.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            fijiRowKey.add(Long.valueOf(buf.getLong()));
            pos = pos + Long.SIZE / Byte.SIZE;
            break;
        default:
            throw new RuntimeException("Invalid code path");
        }
        fijiRowElem += 1;
    }

    // Fail if there are extra bytes in hbase row key.
    if (pos < hbaseRowKey.length) {
        throw new EntityIdException("Extra bytes in hbase row key cannot be mapped to any " + "component");
    }

    // Fail if we encounter nulls before it is legal to do so.
    if (fijiRowElem < format.getNullableStartIndex()) {
        throw new EntityIdException("Too few components decoded from hbase row key. Component " + "number "
                + fijiRowElem + " cannot be null");
    }

    // finish up with nulls for everything that wasn't in the key
    for (; fijiRowElem < format.getComponents().size(); fijiRowElem++) {
        fijiRowKey.add(null);
    }

    return fijiRowKey;
}