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:org.cellprofiler.subimager.ImageWriterHandler.java

private byte[] convertImage(NDImage ndimage, PixelType pixelType, boolean toBigEndian) {
    double[] inputDouble = ndimage.getBuffer();
    switch (pixelType) {
    case INT8:/*from w  ww.  j a  va  2 s  .c  om*/
        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.");
    }
}

From source file:org.apache.pig.data.BinInterSedes.java

@Override
@SuppressWarnings("unchecked")
public void writeDatum(DataOutput out, Object val, byte type) throws IOException {
    switch (type) {
    case DataType.TUPLE:
        writeTuple(out, (Tuple) val);
        break;//from w w  w . java  2s.  c o m

    case DataType.BAG:
        writeBag(out, (DataBag) val);
        break;

    case DataType.MAP: {
        writeMap(out, (Map<String, Object>) val);
        break;
    }

    case DataType.INTERNALMAP: {
        out.writeByte(INTERNALMAP);
        Map<Object, Object> m = (Map<Object, Object>) val;
        out.writeInt(m.size());
        Iterator<Map.Entry<Object, Object>> i = m.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<Object, Object> entry = i.next();
            writeDatum(out, entry.getKey());
            writeDatum(out, entry.getValue());
        }
        break;
    }

    case DataType.INTEGER:
        int i = (Integer) val;
        if (i == 0) {
            out.writeByte(INTEGER_0);
        } else if (i == 1) {
            out.writeByte(INTEGER_1);
        } else if (Byte.MIN_VALUE <= i && i <= Byte.MAX_VALUE) {
            out.writeByte(INTEGER_INBYTE);
            out.writeByte(i);
        } else if (Short.MIN_VALUE <= i && i <= Short.MAX_VALUE) {
            out.writeByte(INTEGER_INSHORT);
            out.writeShort(i);
        } else {
            out.writeByte(INTEGER);
            out.writeInt(i);
        }
        break;

    case DataType.LONG:
        long lng = (Long) val;
        if (lng == 0) {
            out.writeByte(LONG_0);
        } else if (lng == 1) {
            out.writeByte(LONG_1);
        } else if (Byte.MIN_VALUE <= lng && lng <= Byte.MAX_VALUE) {
            out.writeByte(LONG_INBYTE);
            out.writeByte((int) lng);
        } else if (Short.MIN_VALUE <= lng && lng <= Short.MAX_VALUE) {
            out.writeByte(LONG_INSHORT);
            out.writeShort((int) lng);
        } else if (Integer.MIN_VALUE <= lng && lng <= Integer.MAX_VALUE) {
            out.writeByte(LONG_ININT);
            out.writeInt((int) lng);
        } else {
            out.writeByte(LONG);
            out.writeLong(lng);
        }
        break;

    case DataType.DATETIME:
        out.writeByte(DATETIME);
        out.writeLong(((DateTime) val).getMillis());
        out.writeShort(((DateTime) val).getZone().getOffset((DateTime) val) / ONE_MINUTE);
        break;

    case DataType.FLOAT:
        out.writeByte(FLOAT);
        out.writeFloat((Float) val);
        break;

    case DataType.BIGINTEGER:
        out.writeByte(BIGINTEGER);
        writeBigInteger(out, (BigInteger) val);
        break;

    case DataType.BIGDECIMAL:
        out.writeByte(BIGDECIMAL);
        writeBigDecimal(out, (BigDecimal) val);
        break;

    case DataType.DOUBLE:
        out.writeByte(DOUBLE);
        out.writeDouble((Double) val);
        break;

    case DataType.BOOLEAN:
        if ((Boolean) val)
            out.writeByte(BOOLEAN_TRUE);
        else
            out.writeByte(BOOLEAN_FALSE);
        break;

    case DataType.BYTE:
        out.writeByte(BYTE);
        out.writeByte((Byte) val);
        break;

    case DataType.BYTEARRAY: {
        DataByteArray bytes = (DataByteArray) val;
        SedesHelper.writeBytes(out, bytes.mData);
        break;

    }

    case DataType.CHARARRAY: {
        SedesHelper.writeChararray(out, (String) val);
        break;
    }
    case DataType.GENERIC_WRITABLECOMPARABLE:
        out.writeByte(GENERIC_WRITABLECOMPARABLE);
        // store the class name, so we know the class to create on read
        writeDatum(out, val.getClass().getName());
        Writable writable = (Writable) val;
        writable.write(out);
        break;

    case DataType.NULL:
        out.writeByte(NULL);
        break;

    default:
        throw new RuntimeException("Unexpected data type " + val.getClass().getName() + " found in stream. "
                + "Note only standard Pig type is supported when you output from UDF/LoadFunc");
    }
}

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

@Test
public void testPublishingByteXml() throws IOException {
    final EventBusMessageType messageType = EventBusMessageType.Byte;
    final Byte sentByte = Byte.MIN_VALUE;
    Map<String, String> expectations = createExpectations(generateUniqueAddress(),
            Base64.encodeAsString(sentByte.toString()), messageType);
    final AtomicInteger completedCount = new AtomicInteger(0);
    Handler<Message> messagePublishHandler = new MessagePublishHandler(sentByte, expectations, completedCount);
    registerListenersAndCheckForResponses(messagePublishHandler, expectations, NUMBER_OF_PUBLISH_HANDLERS,
            completedCount);/* w  ww  .  j  ava 2  s  . c om*/
    String body = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_XML, expectations);
    HttpRequestHelper.sendHttpPostRequest(url, body, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(),
            MediaType.APPLICATION_XML);
}

From source file:org.apache.rya.indexing.smarturi.duplication.DuplicateDataDetectorIT.java

@Test
public void testByteProperty() throws SmartUriException {
    System.out.println("Byte Property Test");
    final ImmutableList.Builder<TestInput> builder = ImmutableList.builder();
    // Tolerance 0.0
    Tolerance tolerance = new Tolerance(0.0, ToleranceType.DIFFERENCE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, false));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, false));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 1.0
    tolerance = new Tolerance(1.0, ToleranceType.DIFFERENCE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 2.0
    tolerance = new Tolerance(2.0, ToleranceType.DIFFERENCE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, true));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, true));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));

    // Tolerance 0.0%
    tolerance = new Tolerance(0.00, ToleranceType.PERCENTAGE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, false));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, false));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 50.0%
    tolerance = new Tolerance(0.50, ToleranceType.PERCENTAGE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 100.0%
    tolerance = new Tolerance(1.00, ToleranceType.PERCENTAGE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, true));
    builder.add(new TestInput((byte) 0xff, tolerance, true));
    builder.add(new TestInput((byte) 0x00, tolerance, true));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, true));
    builder.add(new TestInput((byte) 0x05, tolerance, true));
    builder.add(new TestInput((byte) 0x10, tolerance, true));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, true));

    final ImmutableList<TestInput> testInputs = builder.build();

    testProperty(testInputs, PERSON_TYPE_URI, HAS_NUMBER_OF_CHILDREN);
}

From source file:org.apache.rya.indexing.smarturi.duplication.DuplicateDataDetectorTest.java

@Test
public void testByteProperty() throws SmartUriException {
    System.out.println("Byte Property Test");
    final ImmutableList.Builder<TestInput> builder = ImmutableList.<TestInput>builder();
    // Tolerance 0.0
    Tolerance tolerance = new Tolerance(0.0, ToleranceType.DIFFERENCE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, false));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, false));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 1.0
    tolerance = new Tolerance(1.0, ToleranceType.DIFFERENCE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 2.0
    tolerance = new Tolerance(2.0, ToleranceType.DIFFERENCE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, true));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, true));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));

    // Tolerance 0.0%
    tolerance = new Tolerance(0.00, ToleranceType.PERCENTAGE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, false));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, false));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 50.0%
    tolerance = new Tolerance(0.50, ToleranceType.PERCENTAGE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, false));
    builder.add(new TestInput((byte) 0xff, tolerance, false));
    builder.add(new TestInput((byte) 0x00, tolerance, false));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, false));
    builder.add(new TestInput((byte) 0x05, tolerance, false));
    builder.add(new TestInput((byte) 0x10, tolerance, false));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, false));
    // Tolerance 100.0%
    tolerance = new Tolerance(1.00, ToleranceType.PERCENTAGE);
    builder.add(new TestInput(Byte.MIN_VALUE, tolerance, true));
    builder.add(new TestInput((byte) 0xff, tolerance, true));
    builder.add(new TestInput((byte) 0x00, tolerance, true));
    builder.add(new TestInput((byte) 0x01, tolerance, true));
    builder.add(new TestInput((byte) 0x02, tolerance, true)); // Equals value
    builder.add(new TestInput((byte) 0x03, tolerance, true));
    builder.add(new TestInput((byte) 0x04, tolerance, true));
    builder.add(new TestInput((byte) 0x05, tolerance, true));
    builder.add(new TestInput((byte) 0x10, tolerance, true));
    builder.add(new TestInput(Byte.MAX_VALUE, tolerance, true));

    final ImmutableList<TestInput> testInputs = builder.build();

    testProperty(testInputs, PERSON_TYPE_URI, HAS_NUMBER_OF_CHILDREN);
}

From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java

protected boolean isInRange(Number value, String stringValue, Class toType) {
    Number bigValue = null;/*from  w  w w. j  a  va 2  s . c om*/
    Number lowerBound = null;
    Number upperBound = null;

    try {
        if (double.class == toType || Double.class == toType) {
            bigValue = new BigDecimal(stringValue);
            // Double.MIN_VALUE is the smallest positive non-zero number
            lowerBound = BigDecimal.valueOf(Double.MAX_VALUE).negate();
            upperBound = BigDecimal.valueOf(Double.MAX_VALUE);
        } else if (float.class == toType || Float.class == toType) {
            bigValue = new BigDecimal(stringValue);
            // Float.MIN_VALUE is the smallest positive non-zero number
            lowerBound = BigDecimal.valueOf(Float.MAX_VALUE).negate();
            upperBound = BigDecimal.valueOf(Float.MAX_VALUE);
        } else if (byte.class == toType || Byte.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Byte.MIN_VALUE);
            upperBound = BigInteger.valueOf(Byte.MAX_VALUE);
        } else if (char.class == toType || Character.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Character.MIN_VALUE);
            upperBound = BigInteger.valueOf(Character.MAX_VALUE);
        } else if (short.class == toType || Short.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Short.MIN_VALUE);
            upperBound = BigInteger.valueOf(Short.MAX_VALUE);
        } else if (int.class == toType || Integer.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Integer.MIN_VALUE);
            upperBound = BigInteger.valueOf(Integer.MAX_VALUE);
        } else if (long.class == toType || Long.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Long.MIN_VALUE);
            upperBound = BigInteger.valueOf(Long.MAX_VALUE);
        }
    } catch (NumberFormatException e) {
        //shoult it fail here? BigInteger doesnt seem to be so nice parsing numbers as NumberFormat
        return true;
    }

    return ((Comparable) bigValue).compareTo(lowerBound) >= 0
            && ((Comparable) bigValue).compareTo(upperBound) <= 0;
}

From source file:org.apache.hive.hcatalog.pig.HCatBaseStorer.java

/**
 * Convert from Pig value object to Hive value object
 * This method assumes that {@link #validateSchema(org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema, org.apache.hive.hcatalog.data.schema.HCatFieldSchema, org.apache.pig.impl.logicalLayer.schema.Schema, org.apache.hive.hcatalog.data.schema.HCatSchema, int)}
 * which checks the types in Pig schema are compatible with target Hive table, has been called.
 *///from   w  ww . ja  v a  2  s  . c  om
private Object getJavaObj(Object pigObj, HCatFieldSchema hcatFS) throws HCatException, BackendException {
    try {
        if (pigObj == null)
            return null;
        // The real work-horse. Spend time and energy in this method if there is
        // need to keep HCatStorer lean and go fast.
        Type type = hcatFS.getType();
        switch (type) {
        case BINARY:
            return ((DataByteArray) pigObj).get();

        case STRUCT:
            HCatSchema structSubSchema = hcatFS.getStructSubSchema();
            // Unwrap the tuple.
            List<Object> all = ((Tuple) pigObj).getAll();
            ArrayList<Object> converted = new ArrayList<Object>(all.size());
            for (int i = 0; i < all.size(); i++) {
                converted.add(getJavaObj(all.get(i), structSubSchema.get(i)));
            }
            return converted;

        case ARRAY:
            // Unwrap the bag.
            DataBag pigBag = (DataBag) pigObj;
            HCatFieldSchema tupFS = hcatFS.getArrayElementSchema().get(0);
            boolean needTuple = tupFS.getType() == Type.STRUCT;
            List<Object> bagContents = new ArrayList<Object>((int) pigBag.size());
            Iterator<Tuple> bagItr = pigBag.iterator();

            while (bagItr.hasNext()) {
                // If there is only one element in tuple contained in bag, we throw away the tuple.
                bagContents.add(getJavaObj(needTuple ? bagItr.next() : bagItr.next().get(0), tupFS));

            }
            return bagContents;
        case MAP:
            Map<?, ?> pigMap = (Map<?, ?>) pigObj;
            Map<Object, Object> typeMap = new HashMap<Object, Object>();
            for (Entry<?, ?> entry : pigMap.entrySet()) {
                // the value has a schema and not a FieldSchema
                typeMap.put(
                        // Schema validation enforces that the Key is a String
                        (String) entry.getKey(),
                        getJavaObj(entry.getValue(), hcatFS.getMapValueSchema().get(0)));
            }
            return typeMap;
        case STRING:
        case INT:
        case BIGINT:
        case FLOAT:
        case DOUBLE:
            return pigObj;
        case SMALLINT:
            if ((Integer) pigObj < Short.MIN_VALUE || (Integer) pigObj > Short.MAX_VALUE) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return ((Integer) pigObj).shortValue();
        case TINYINT:
            if ((Integer) pigObj < Byte.MIN_VALUE || (Integer) pigObj > Byte.MAX_VALUE) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return ((Integer) pigObj).byteValue();
        case BOOLEAN:
            if (pigObj instanceof String) {
                if (((String) pigObj).trim().compareTo("0") == 0) {
                    return Boolean.FALSE;
                }
                if (((String) pigObj).trim().compareTo("1") == 0) {
                    return Boolean.TRUE;
                }
                throw new BackendException("Unexpected type " + type + " for value " + pigObj + " of class "
                        + pigObj.getClass().getName(), PigHCatUtil.PIG_EXCEPTION_CODE);
            }
            return Boolean.parseBoolean(pigObj.toString());
        case DECIMAL:
            BigDecimal bd = (BigDecimal) pigObj;
            DecimalTypeInfo dti = (DecimalTypeInfo) hcatFS.getTypeInfo();
            if (bd.precision() > dti.precision() || bd.scale() > dti.scale()) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return HiveDecimal.create(bd);
        case CHAR:
            String charVal = (String) pigObj;
            CharTypeInfo cti = (CharTypeInfo) hcatFS.getTypeInfo();
            if (charVal.length() > cti.getLength()) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return new HiveChar(charVal, cti.getLength());
        case VARCHAR:
            String varcharVal = (String) pigObj;
            VarcharTypeInfo vti = (VarcharTypeInfo) hcatFS.getTypeInfo();
            if (varcharVal.length() > vti.getLength()) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return new HiveVarchar(varcharVal, vti.getLength());
        case TIMESTAMP:
            DateTime dt = (DateTime) pigObj;
            return new Timestamp(dt.getMillis());//getMillis() returns UTC time regardless of TZ
        case DATE:
            /**
             * We ignore any TZ setting on Pig value since java.sql.Date doesn't have it (in any
             * meaningful way).  So the assumption is that if Pig value has 0 time component (midnight)
             * we assume it reasonably 'fits' into a Hive DATE.  If time part is not 0, it's considered
             * out of range for target type.
             */
            DateTime dateTime = ((DateTime) pigObj);
            if (dateTime.getMillisOfDay() != 0) {
                handleOutOfRangeValue(pigObj, hcatFS,
                        "Time component must be 0 (midnight) in local timezone; Local TZ val='" + pigObj + "'");
                return null;
            }
            /*java.sql.Date is a poorly defined API.  Some (all?) SerDes call toString() on it
            [e.g. LazySimpleSerDe, uses LazyUtils.writePrimitiveUTF8()],  which automatically adjusts
              for local timezone.  Date.valueOf() also uses local timezone (as does Date(int,int,int).
              Also see PigHCatUtil#extractPigObject() for corresponding read op.  This way a DATETIME from Pig,
              when stored into Hive and read back comes back with the same value.*/
            return new Date(dateTime.getYear() - 1900, dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth());
        default:
            throw new BackendException("Unexpected HCat type " + type + " for value " + pigObj + " of class "
                    + pigObj.getClass().getName(), PigHCatUtil.PIG_EXCEPTION_CODE);
        }
    } catch (BackendException e) {
        // provide the path to the field in the error message
        throw new BackendException((hcatFS.getName() == null ? " " : hcatFS.getName() + ".") + e.getMessage(),
                e);
    }
}

From source file:net.sf.json.TestJSONObject.java

public void testFromBean_use_wrappers() {
    JSONObject json = JSONObject.fromObject(Boolean.TRUE);
    assertTrue(json.isEmpty());/*from ww w  . j a va  2 s  .  c  o 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:nl.systemsgenetics.simplegeneticriskscorecalculator.Main.java

private static void writeMatrixToFile(DoubleMatrixDataset<String, String> geneticRiskScoreMatrix,
        File outputFolder) throws IOException {

    String outputF = outputFolder + File.separator + "TT";
    if (!(new File(outputF).exists())) {
        Gpio.createDir(outputF);//from  w ww . j  a  v a  2  s .  c o m
    } else if (!(new File(outputF).isDirectory())) {
        System.out.println("Error file is already there but not a directory, writing to TT1");
        outputF = outputFolder + File.separator + "TT1";
        Gpio.createDir(outputF);

        System.exit(0);
    }
    geneticRiskScoreMatrix.save(outputF + File.separator + "rawScoreMatrix.txt");
    try {
        System.out.println("Writing SNPMappings.txt & SNPs.txt to file:");

        java.io.BufferedWriter outSNPMappings = new java.io.BufferedWriter(
                new java.io.FileWriter(new File(outputF + File.separator + "SNPMappings.txt")));
        java.io.BufferedWriter outSNPs = new java.io.BufferedWriter(
                new java.io.FileWriter(new File(outputF + File.separator + "SNPs.txt")));

        for (String var : geneticRiskScoreMatrix.getRowObjects()) {
            outSNPMappings.write("1\t1000000\t" + var + '\n');
            outSNPs.write(var + '\n');
        }

        outSNPMappings.close();
        outSNPs.close();
    } catch (Exception e) {
        System.out.println("Error:\t" + e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }

    geneticRiskScoreMatrix
            .setMatrix(ConvertDoubleMatrixDataToTriTyper.rankRows(geneticRiskScoreMatrix.getMatrix()));

    geneticRiskScoreMatrix.setMatrix(
            ConvertDoubleMatrixDataToTriTyper.rescaleValue(geneticRiskScoreMatrix.getMatrix(), 200.0d));
    //geneticRiskScoreMatrix.save(outputF + File.separator + "Step2_ScoreMatrix.txt");

    try {
        System.out.println("\nWriting Individuals.txt and Phenotype.txt to file:");
        BufferedWriter outIndNew = new BufferedWriter(
                new FileWriter(outputF + File.separator + "Individuals.txt"));
        BufferedWriter outPhenoNew = new BufferedWriter(
                new FileWriter(outputF + File.separator + "PhenotypeInformation.txt"));
        for (String ind : geneticRiskScoreMatrix.getColObjects()) {
            outIndNew.write(ind + '\n');
            outPhenoNew.write(ind + "\tcontrol\tinclude\tmale\n");
        }
        outIndNew.close();
        outPhenoNew.close();
    } catch (Exception e) {
        System.out.println("Error:\t" + e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }

    int nrSNPs = geneticRiskScoreMatrix.rows();
    int nrSamples = geneticRiskScoreMatrix.columns();

    WGAFileMatrixGenotype fileMatrixGenotype = new WGAFileMatrixGenotype(nrSNPs, nrSamples,
            new File(outputF + File.separator + "GenotypeMatrix.dat"), false);
    WGAFileMatrixImputedDosage fileMatrixDosage = new WGAFileMatrixImputedDosage(nrSNPs, nrSamples,
            new File(outputF + File.separator + "ImputedDosageMatrix.dat"), false);
    byte[] alleles = new byte[2];
    alleles[0] = 84;
    alleles[1] = 67;

    for (int snp = 0; snp < nrSNPs; snp++) {
        DoubleMatrix1D snpRow = geneticRiskScoreMatrix.getMatrix().viewRow(snp);

        byte[] allele1 = new byte[nrSamples];
        byte[] allele2 = new byte[nrSamples];
        byte[] dosageValues = new byte[nrSamples];
        for (int ind = 0; ind < nrSamples; ind++) {
            if (snpRow.get(ind) > 100) {
                allele1[ind] = alleles[1];
                allele2[ind] = alleles[1];
            } else {
                allele1[ind] = alleles[0];
                allele2[ind] = alleles[0];
            }

            int dosageInt = (int) Math.round(snpRow.get(ind));
            byte value = (byte) (Byte.MIN_VALUE + dosageInt);
            dosageValues[ind] = value;
        }
        fileMatrixGenotype.setAllele1(snp, 0, allele1);
        fileMatrixGenotype.setAllele2(snp, 0, allele2);
        fileMatrixDosage.setDosage(snp, 0, dosageValues);
    }
    fileMatrixGenotype.close();
    fileMatrixDosage.close();
}

From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap.java

/**
 * Fill the measures min values with minimum , this is needed for backward version compatability
 * as older versions don't store min values for measures
 *///from ww w .j  a  v a2s.co m
private byte[][] updateMinValues(byte[][] minValues, int[] minMaxLen) {
    byte[][] updatedValues = minValues;
    if (minValues.length < minMaxLen.length) {
        updatedValues = new byte[minMaxLen.length][];
        System.arraycopy(minValues, 0, updatedValues, 0, minValues.length);
        List<CarbonMeasure> measures = segmentProperties.getMeasures();
        ByteBuffer buffer = ByteBuffer.allocate(8);
        for (int i = 0; i < measures.size(); i++) {
            buffer.rewind();
            DataType dataType = measures.get(i).getDataType();
            if (dataType == DataTypes.BYTE) {
                buffer.putLong(Byte.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (dataType == DataTypes.SHORT) {
                buffer.putLong(Short.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (dataType == DataTypes.INT) {
                buffer.putLong(Integer.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (dataType == DataTypes.LONG) {
                buffer.putLong(Long.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (DataTypes.isDecimal(dataType)) {
                updatedValues[minValues.length + i] = DataTypeUtil
                        .bigDecimalToByte(BigDecimal.valueOf(Long.MIN_VALUE));
            } else {
                buffer.putDouble(Double.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            }
        }
    }
    return updatedValues;
}