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:net.sf.json.TestJSONObject.java

public void testFromObject_use_wrappers() {
    JSONObject json = JSONObject.fromObject(Boolean.TRUE);
    assertTrue(json.isEmpty());/*www  .  j av a  2 s  .co m*/
    json = JSONObject.fromObject(new Byte(Byte.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Short(Short.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Integer(Integer.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Long(Long.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Float(Float.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Double(Double.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Character('A'));
    assertTrue(json.isEmpty());
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

/**
 * @param baseArrayClass/*  w  w  w  .  ja v  a  2s  . c o  m*/
 * @param objectList     -> for primitive type array conversion we assume the content to be
 *                       strings!
 * @return Returns Object.
 */
public static Object convertToArray(Class baseArrayClass, List objectList) {
    int listSize = objectList.size();
    Object returnArray = null;
    if (int.class.equals(baseArrayClass)) {
        int[] array = new int[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Integer.parseInt(o.toString());
            } else {
                array[i] = Integer.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (float.class.equals(baseArrayClass)) {
        float[] array = new float[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Float.parseFloat(o.toString());
            } else {
                array[i] = Float.NaN;
            }
        }
        returnArray = array;
    } else if (short.class.equals(baseArrayClass)) {
        short[] array = new short[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Short.parseShort(o.toString());
            } else {
                array[i] = Short.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (byte.class.equals(baseArrayClass)) {
        byte[] array = new byte[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Byte.parseByte(o.toString());
            } else {
                array[i] = Byte.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (long.class.equals(baseArrayClass)) {
        long[] array = new long[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Long.parseLong(o.toString());
            } else {
                array[i] = Long.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (boolean.class.equals(baseArrayClass)) {
        boolean[] array = new boolean[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = o.toString().equalsIgnoreCase("true");
            }
        }
        returnArray = array;
    } else if (char.class.equals(baseArrayClass)) {
        char[] array = new char[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = o.toString().toCharArray()[0];
            }
        }
        returnArray = array;
    } else if (double.class.equals(baseArrayClass)) {
        double[] array = new double[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Double.parseDouble(o.toString());
            } else {
                array[i] = Double.NaN;
            }
        }
        returnArray = array;
    } else if (Calendar.class.equals(baseArrayClass)) {
        Calendar[] array = new Calendar[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                if (o instanceof String) {
                    array[i] = ConverterUtil.convertToDateTime(o.toString());
                } else if (o instanceof Calendar) {
                    array[i] = (Calendar) o;
                }
            }
        }
        returnArray = array;
    } else if (Date.class.equals(baseArrayClass)) {
        Date[] array = new Date[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                if (o instanceof String) {
                    array[i] = ConverterUtil.convertToDate(o.toString());
                } else if (o instanceof Date) {
                    array[i] = (Date) o;
                }
            }
        }
        returnArray = array;
    } else {
        returnArray = Array.newInstance(baseArrayClass, listSize);
        ConvertToArbitraryObjectArray(returnArray, baseArrayClass, objectList);
    }
    return returnArray;
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static void writeDSFIDHeader(int dsfid, DataOutput out) throws IOException {
    if (dsfid == DataSerializableFixedID.ILLEGAL) {
        throw new IllegalStateException(
                LocalizedStrings.InternalDataSerializer_ATTEMPTED_TO_SERIALIZE_ILLEGAL_DSFID
                        .toLocalizedString());
    }//from  ww  w  .j a v a2  s.co  m
    if (dsfid <= Byte.MAX_VALUE && dsfid >= Byte.MIN_VALUE) {
        out.writeByte(DS_FIXED_ID_BYTE);
        out.writeByte(dsfid);
    } else if (dsfid <= Short.MAX_VALUE && dsfid >= Short.MIN_VALUE) {
        out.writeByte(DS_FIXED_ID_SHORT);
        out.writeShort(dsfid);
    } else {
        out.writeByte(DS_FIXED_ID_INT);
        out.writeInt(dsfid);
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

/**
 * Data serializes an instance of a "user class" (that is, a class that can be handled by a
 * registered {@code DataSerializer}) to the given {@code DataOutput}.
 *
 * @return {@code true} if {@code o} was written to {@code out}.
 *//*from w ww  . j  a va2  s  . com*/
private static boolean writeUserObject(Object o, DataOutput out, boolean ensurePdxCompatibility)
        throws IOException {

    final Class<?> c = o.getClass();
    final DataSerializer serializer = InternalDataSerializer.getSerializer(c);
    if (serializer != null) {
        int id = serializer.getId();
        if (id != 0) {
            checkPdxCompatible(o, ensurePdxCompatibility);
            // id will be 0 if it is a WellKnowDS
            if (id <= Byte.MAX_VALUE && id >= Byte.MIN_VALUE) {
                out.writeByte(USER_CLASS);
                out.writeByte((byte) id);
            } else if (id <= Short.MAX_VALUE && id >= Short.MIN_VALUE) {
                out.writeByte(USER_CLASS_2);
                out.writeShort(id);
            } else {
                out.writeByte(USER_CLASS_4);
                out.writeInt(id);
            }
        } else {
            if (ensurePdxCompatibility) {
                if (!(serializer instanceof WellKnownPdxDS)) {
                    checkPdxCompatible(o, ensurePdxCompatibility);
                }
            }
        }
        boolean toDataResult;
        try {
            toDataResult = serializer.toData(o, out);
        } catch (IOException io) {
            if (serializer instanceof WellKnownDS) {
                // this is not user code so throw IOException
                throw io; // see bug 44659
            } else {
                // We no longer rethrow IOException here
                // because if user code throws an IOException we want
                // to create a ToDataException to report it as a problem
                // with the plugin code.
                throw new ToDataException("toData failed on DataSerializer with id=" + id + " for class " + c,
                        io);
            }
        } catch (CancelException | ToDataException | GemFireRethrowable ex) {
            // Serializing a PDX can result in a cache closed exception. Just rethrow
            throw ex;
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // If this ever returns, rethrow the error. We're poisoned
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            throw new ToDataException("toData failed on DataSerializer with id=" + id + " for class " + c, t);
        }
        if (toDataResult) {
            return true;
        } else {
            throw new ToDataException(
                    LocalizedStrings.DataSerializer_SERIALIZER_0_A_1_SAID_THAT_IT_COULD_SERIALIZE_AN_INSTANCE_OF_2_BUT_ITS_TODATA_METHOD_RETURNED_FALSE
                            .toLocalizedString(serializer.getId(), serializer.getClass().getName(),
                                    o.getClass().getName()));
        }
        // Do byte[][] and Object[] here to fix bug 44060
    } else if (o instanceof byte[][]) {
        byte[][] byteArrays = (byte[][]) o;
        out.writeByte(ARRAY_OF_BYTE_ARRAYS);
        writeArrayOfByteArrays(byteArrays, out);
        return true;
    } else if (o instanceof Object[]) {
        Object[] array = (Object[]) o;
        out.writeByte(OBJECT_ARRAY);
        writeObjectArray(array, out, ensurePdxCompatibility);
        return true;
    } else if (is662SerializationEnabled()
            && (o.getClass().isEnum()/* for bug 52271 */ || (o.getClass().getSuperclass() != null
                    && o.getClass().getSuperclass().isEnum()))) {
        if (isPdxSerializationInProgress()) {
            writePdxEnum((Enum<?>) o, out);
        } else {
            checkPdxCompatible(o, ensurePdxCompatibility);
            writeGemFireEnum((Enum<?>) o, out);
        }
        return true;
    } else {
        PdxSerializer pdxSerializer = TypeRegistry.getPdxSerializer();
        return pdxSerializer != null && writePdx(out, null, o, pdxSerializer);
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static void writeUserDataSerializableHeader(int classId, DataOutput out) throws IOException {
    if (classId <= Byte.MAX_VALUE && classId >= Byte.MIN_VALUE) {
        out.writeByte(USER_DATA_SERIALIZABLE);
        out.writeByte(classId);/* w ww . j a v a2s.  c  o  m*/
    } else if (classId <= Short.MAX_VALUE && classId >= Short.MIN_VALUE) {
        out.writeByte(USER_DATA_SERIALIZABLE_2);
        out.writeShort(classId);
    } else {
        out.writeByte(USER_DATA_SERIALIZABLE_4);
        out.writeInt(classId);
    }
}

From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java

/**
 * Determines if the given value is within the range of the specified type.
 * @param type The type to determine the range of. Valid types can be byte or short.
 * @param val The value to check the range of.
 * @return True if the given int value is within the range of the specified type, false otherwise.
 *///from  w  w w.jav  a 2  s. co  m
public static boolean insideRange(Type type, int val) {
    switch (type) {
    case BYTE: {
        return !(val < (int) Byte.MIN_VALUE || val > (int) Byte.MAX_VALUE);
    }
    case SHORT: {
        return !(val < (int) Short.MIN_VALUE || val > (int) Short.MAX_VALUE);
    }
    default:
        throw new UnsupportedOperationException("This operation is not supported for the type " + type);
    }
}