Example usage for java.lang Byte byteValue

List of usage examples for java.lang Byte byteValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public byte byteValue() 

Source Link

Document

Returns the value of this Byte as a byte .

Usage

From source file:org.apache.hadoop.hive.ql.udf.UDFOPNotEqual.java

public Boolean evaluate(Byte a, Byte b) {
    Boolean r = null;//from w w w .  ja  va 2  s  .c  o  m
    if ((a == null) || (b == null)) {
        r = null;
    } else {
        r = Boolean.valueOf(a.byteValue() != b.byteValue());
    }
    // LOG.info("evaluate(" + a + "," + b + ")=" + r);
    return r;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFOPLessThan.java

public Boolean evaluate(Byte a, Byte b) {
    Boolean r = null;//ww w  . j a v  a 2 s.  c om
    if ((a == null) || (b == null)) {
        r = null;
    } else {
        r = Boolean.valueOf(a.byteValue() < b.byteValue());
    }
    // LOG.info("evaluate(" + a + "," + b + ")=" + r);
    return r;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFOPEqual.java

public Boolean evaluate(Byte a, Byte b) {
    Boolean r = null;/*from w  w  w  . j  ava  2 s  .  c  o  m*/
    if ((a == null) || (b == null)) {
        r = null;
    } else {
        r = Boolean.valueOf(a.byteValue() == b.byteValue());
    }
    // LOG.info("evaluate(" + a + "," + b + ")=" + r);
    return r;
}

From source file:org.openbravo.base.MultipartRequest.java

protected void readSubmittedFile(InputStream in) throws IOException {

    Vector<FieldProvider> vector = new Vector<FieldProvider>();
    int result = 0;
    String linea = "";
    Vector<Byte> vectorInt = new Vector<Byte>();
    boolean isFirstRow = true;
    while ((result = in.read()) != -1) {
        if (result == 13 || result == 10) {
            if (vectorInt.size() > 0) {
                byte[] b = new byte[vectorInt.size()];
                for (int i = 0; i < vectorInt.size(); i++) {
                    Byte bAux = vectorInt.elementAt(i);
                    b[i] = bAux.byteValue();
                }/*  w  w  w .j a va  2  s .  c o m*/
                vectorInt = new Vector<Byte>();
                linea = new String(b, "UTF-8");
                if (!isFirstRow || !firstRowHeads) {
                    FieldProvider fieldProvider = setFieldProvider(linea);
                    vector.addElement(fieldProvider);
                }
            }
            isFirstRow = false;
        } else {
            byte aux = new Integer(result).byteValue();
            vectorInt.addElement(new Byte(aux));
        }
    }
    if (vectorInt.size() > 0 && (!isFirstRow || !firstRowHeads)) {
        byte[] b = new byte[vectorInt.size()];
        for (int i = 0; i < vectorInt.size(); i++) {
            Byte bAux = vectorInt.elementAt(i);
            b[i] = bAux.byteValue();
        }
        vectorInt = new Vector<Byte>();
        linea = new String(b);
        FieldProvider fieldProvider = setFieldProvider(linea);
        vector.addElement(fieldProvider);
    }
    objectFieldProvider = new FieldProvider[vector.size()];
    vector.copyInto(objectFieldProvider);
}

From source file:z.tool.util.ToStringBuilder.java

public ToStringBuilder add(String key, Byte value) {
    if (null != key && null != value) {
        getOrTryInitBuff().append(key).append(":").append(value.byteValue()).append(SEP);
    }//from   w  w w .  j a  va  2 s.co  m
    return this;
}

From source file:com.magnet.android.mms.request.GenericResponseParserPrimitiveTest.java

@SmallTest
public void testNumberResponse() throws MobileException, JSONException {
    GenericResponseParser<Integer> parser = new GenericResponseParser<Integer>(Integer.class);
    String response = Integer.toString(Integer.MIN_VALUE);

    Integer result = (Integer) parser.parseResponse(response.toString().getBytes());
    assertEquals(Integer.MIN_VALUE, result.intValue());

    Object nullresult = parser.parseResponse((byte[]) null);
    assertEquals(null, nullresult);//from w w  w  .j  a  v  a2  s .  c  o m

    long longvalue = new Random().nextLong();
    GenericResponseParser<Long> lparser = new GenericResponseParser<Long>(Long.class);
    long longresult = (Long) lparser.parseResponse(Long.toString(longvalue).getBytes());
    assertEquals(longvalue, longresult);

    short shortvalue = Short.MAX_VALUE;
    GenericResponseParser<Short> sparser = new GenericResponseParser<Short>(short.class);
    short shortresult = (Short) sparser.parseResponse(Short.toString(shortvalue).getBytes());
    assertEquals(shortvalue, shortresult);

    float floatvalue = new Random().nextFloat();
    GenericResponseParser<Float> fparser = new GenericResponseParser<Float>(Float.class);
    float floatresult = (Float) fparser.parseResponse(Float.toString(floatvalue).getBytes());
    assertEquals(String.valueOf(floatvalue), String.valueOf(floatresult));
    // use string as the value of the float

    double doublevalue = new Random().nextDouble();
    GenericResponseParser<Double> dparser = new GenericResponseParser<Double>(double.class);
    Double doubleresult = (Double) dparser.parseResponse(Double.toString(doublevalue).getBytes());
    assertEquals(String.valueOf(doublevalue), String.valueOf(doubleresult));

    byte bytevalue = Byte.MIN_VALUE + 10;
    GenericResponseParser<Byte> bparser = new GenericResponseParser<Byte>(Byte.class);
    Byte byteresult = (Byte) bparser.parseResponse(Byte.toString(bytevalue).getBytes());
    assertEquals(bytevalue, byteresult.byteValue());

}

From source file:org.apache.hadoop.hive.ql.optimizer.MapJoinProcessor.java

public static MapJoinDesc getMapJoinDesc(HiveConf hconf, JoinOperator op, boolean leftInputJoin,
        String[] baseSrc, List<String> mapAliases, int mapJoinPos, boolean noCheckOuterJoin,
        boolean adjustParentsChildren) throws SemanticException {
    JoinDesc desc = op.getConf();//  www  .  ja va  2 s .  c  o m
    JoinCondDesc[] condns = desc.getConds();
    Byte[] tagOrder = desc.getTagOrder();

    // outer join cannot be performed on a table which is being cached
    if (!noCheckOuterJoin) {
        if (checkMapJoin(mapJoinPos, condns) < 0) {
            throw new SemanticException(ErrorMsg.NO_OUTER_MAPJOIN.getMsg());
        }
    }

    Map<String, ExprNodeDesc> colExprMap = op.getColumnExprMap();
    List<ColumnInfo> schema = new ArrayList<ColumnInfo>(op.getSchema().getSignature());
    Map<Byte, List<ExprNodeDesc>> valueExprs = op.getConf().getExprs();
    Map<Byte, List<ExprNodeDesc>> newValueExprs = new HashMap<Byte, List<ExprNodeDesc>>();

    ObjectPair<List<ReduceSinkOperator>, Map<Byte, List<ExprNodeDesc>>> pair = getKeys(leftInputJoin, baseSrc,
            op);
    List<ReduceSinkOperator> oldReduceSinkParentOps = pair.getFirst();
    for (Map.Entry<Byte, List<ExprNodeDesc>> entry : valueExprs.entrySet()) {
        byte tag = entry.getKey();
        Operator<?> terminal = oldReduceSinkParentOps.get(tag);

        List<ExprNodeDesc> values = entry.getValue();
        List<ExprNodeDesc> newValues = ExprNodeDescUtils.backtrack(values, op, terminal);
        newValueExprs.put(tag, newValues);
        for (int i = 0; i < schema.size(); i++) {
            ColumnInfo column = schema.get(i);
            if (column == null) {
                continue;
            }
            ExprNodeDesc expr = colExprMap.get(column.getInternalName());
            int index = ExprNodeDescUtils.indexOf(expr, values);
            if (index >= 0) {
                colExprMap.put(column.getInternalName(), newValues.get(index));
                schema.set(i, null);
            }
        }
    }

    // rewrite value index for mapjoin
    Map<Byte, int[]> valueIndices = new HashMap<Byte, int[]>();

    // get the join keys from old parent ReduceSink operators
    Map<Byte, List<ExprNodeDesc>> keyExprMap = pair.getSecond();

    if (!adjustParentsChildren) {
        // Since we did not remove reduce sink parents, keep the original value expressions
        newValueExprs = valueExprs;

        // Join key exprs are represented in terms of the original table columns,
        // we need to convert these to the generated column names we can see in the Join operator
        Map<Byte, List<ExprNodeDesc>> newKeyExprMap = new HashMap<Byte, List<ExprNodeDesc>>();
        for (Map.Entry<Byte, List<ExprNodeDesc>> mapEntry : keyExprMap.entrySet()) {
            Byte pos = mapEntry.getKey();
            ReduceSinkOperator rsParent = oldReduceSinkParentOps.get(pos.byteValue());
            List<ExprNodeDesc> keyExprList = ExprNodeDescUtils.resolveJoinKeysAsRSColumns(mapEntry.getValue(),
                    rsParent);
            if (keyExprList == null) {
                throw new SemanticException("Error resolving join keys");
            }
            newKeyExprMap.put(pos, keyExprList);
        }
        keyExprMap = newKeyExprMap;
    }

    // construct valueTableDescs and valueFilteredTableDescs
    List<TableDesc> valueTableDescs = new ArrayList<TableDesc>();
    List<TableDesc> valueFilteredTableDescs = new ArrayList<TableDesc>();
    int[][] filterMap = desc.getFilterMap();
    for (byte pos = 0; pos < op.getParentOperators().size(); pos++) {
        List<ExprNodeDesc> valueCols = newValueExprs.get(pos);
        if (pos != mapJoinPos) {
            // remove values in key exprs for value table schema
            // value expression for hashsink will be modified in
            // LocalMapJoinProcessor
            int[] valueIndex = new int[valueCols.size()];
            List<ExprNodeDesc> valueColsInValueExpr = new ArrayList<ExprNodeDesc>();
            for (int i = 0; i < valueIndex.length; i++) {
                ExprNodeDesc expr = valueCols.get(i);
                int kindex = ExprNodeDescUtils.indexOf(expr, keyExprMap.get(pos));
                if (kindex >= 0) {
                    valueIndex[i] = kindex;
                } else {
                    valueIndex[i] = -valueColsInValueExpr.size() - 1;
                    valueColsInValueExpr.add(expr);
                }
            }
            if (needValueIndex(valueIndex)) {
                valueIndices.put(pos, valueIndex);
            }
            valueCols = valueColsInValueExpr;
        }
        // deep copy expr node desc
        List<ExprNodeDesc> valueFilteredCols = ExprNodeDescUtils.clone(valueCols);
        if (filterMap != null && filterMap[pos] != null && pos != mapJoinPos) {
            ExprNodeColumnDesc isFilterDesc = new ExprNodeColumnDesc(
                    TypeInfoFactory.getPrimitiveTypeInfo(serdeConstants.SMALLINT_TYPE_NAME), "filter", "filter",
                    false);
            valueFilteredCols.add(isFilterDesc);
        }

        TableDesc valueTableDesc = PlanUtils
                .getMapJoinValueTableDesc(PlanUtils.getFieldSchemasFromColumnList(valueCols, "mapjoinvalue"));
        TableDesc valueFilteredTableDesc = PlanUtils.getMapJoinValueTableDesc(
                PlanUtils.getFieldSchemasFromColumnList(valueFilteredCols, "mapjoinvalue"));

        valueTableDescs.add(valueTableDesc);
        valueFilteredTableDescs.add(valueFilteredTableDesc);
    }

    Map<Byte, List<ExprNodeDesc>> filters = desc.getFilters();
    Map<Byte, List<ExprNodeDesc>> newFilters = new HashMap<Byte, List<ExprNodeDesc>>();
    for (Map.Entry<Byte, List<ExprNodeDesc>> entry : filters.entrySet()) {
        byte srcTag = entry.getKey();
        List<ExprNodeDesc> filter = entry.getValue();

        Operator<?> terminal = oldReduceSinkParentOps.get(srcTag);
        newFilters.put(srcTag, ExprNodeDescUtils.backtrack(filter, op, terminal));
    }
    desc.setFilters(filters = newFilters);

    // create dumpfile prefix needed to create descriptor
    String dumpFilePrefix = "";
    if (mapAliases != null) {
        for (String mapAlias : mapAliases) {
            dumpFilePrefix = dumpFilePrefix + mapAlias;
        }
        dumpFilePrefix = dumpFilePrefix + "-" + PlanUtils.getCountForMapJoinDumpFilePrefix();
    } else {
        dumpFilePrefix = "mapfile" + PlanUtils.getCountForMapJoinDumpFilePrefix();
    }

    List<ExprNodeDesc> keyCols = keyExprMap.get((byte) mapJoinPos);

    List<String> outputColumnNames = op.getConf().getOutputColumnNames();
    TableDesc keyTableDesc = PlanUtils.getMapJoinKeyTableDesc(hconf,
            PlanUtils.getFieldSchemasFromColumnList(keyCols, MAPJOINKEY_FIELDPREFIX));
    JoinCondDesc[] joinCondns = op.getConf().getConds();
    MapJoinDesc mapJoinDescriptor = new MapJoinDesc(keyExprMap, keyTableDesc, newValueExprs, valueTableDescs,
            valueFilteredTableDescs, outputColumnNames, mapJoinPos, joinCondns, filters,
            op.getConf().getNoOuterJoin(), dumpFilePrefix);
    mapJoinDescriptor.setStatistics(op.getConf().getStatistics());
    mapJoinDescriptor.setTagOrder(tagOrder);
    mapJoinDescriptor.setNullSafes(desc.getNullSafes());
    mapJoinDescriptor.setFilterMap(desc.getFilterMap());
    if (!valueIndices.isEmpty()) {
        mapJoinDescriptor.setValueIndices(valueIndices);
    }

    return mapJoinDescriptor;
}

From source file:org.apache.vxquery.runtime.functions.index.VXQueryIndexReader.java

public void addValue(StringBuilder stb) {
    byte[] indexBytes = new byte[indexSeq.get(0).length];
    int i = 0;/*from w w  w .j  a v  a  2 s.c  o  m*/
    for (Byte b : indexSeq.get(0)) {
        indexBytes[i++] = b.byteValue();

    }
    TaggedValuePointable tvp = new TaggedValuePointable();
    tvp.set(ArrayUtils.toPrimitive(indexSeq.get(0)), 0, ArrayUtils.toPrimitive(indexSeq.get(0)).length);
    if (tvp.getTag() == ValueTag.XS_STRING_TAG) {
        childLocalName[childLocalName.length - 1] = FunctionHelper
                .getStringFromBytes(Arrays.copyOfRange(indexBytes, 1, indexBytes.length));
    } else {
        LongPointable intPoint = (LongPointable) LongPointable.FACTORY.createPointable();
        intPoint.set(indexBytes, 1, indexBytes.length);
        childLocalName[childLocalName.length - 1] = String.valueOf(intPoint.longValue());
    }
    stb.append(childLocalName[childLocalName.length - 1]);
}

From source file:com.igormaznitsa.jhexed.hexmap.HexFieldLayer.java

@Override
public void setValueAt(final int col, final int row, final Byte value) {
    if (this.isPositionValid(col, row)) {
        this.array[col + row * this.columns] = value.byteValue();
    }//from w  w  w. j  av  a  2  s  .  c om
}

From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java

@SuppressWarnings("unused")
private static void writeCell(Cell cell, Object val, boolean userTemplate,
        ExcelWriteFieldMappingAttribute attribute, Object bean) {
    if (attribute != null && attribute.getLinkField() != null) {
        String addressFieldName = attribute.getLinkField();
        String address = null;/*from ww  w.  ja  v  a  2s .co m*/
        if (bean != null) {
            address = (String) getFieldValue(bean, addressFieldName, true);
        }
        Workbook wb = cell.getRow().getSheet().getWorkbook();

        Hyperlink link = wb.getCreationHelper().createHyperlink(attribute.getLinkType());
        link.setAddress(address);
        cell.setHyperlink(link);
        // Its style can't inherit from cell.
        CellStyle style = wb.createCellStyle();
        Font hlinkFont = wb.createFont();
        hlinkFont.setUnderline(Font.U_SINGLE);
        hlinkFont.setColor(IndexedColors.BLUE.getIndex());
        style.setFont(hlinkFont);
        if (cell.getCellStyle() != null) {
            style.setFillBackgroundColor(cell.getCellStyle().getFillBackgroundColor());
        }
        cell.setCellStyle(style);
    }
    if (val == null) {
        cell.setCellValue((String) null);
        return;
    }
    Class<?> clazz = val.getClass();
    if (val instanceof Byte) {// Double
        Byte temp = (Byte) val;
        cell.setCellValue((double) temp.byteValue());
    } else if (val instanceof Short) {
        Short temp = (Short) val;
        cell.setCellValue((double) temp.shortValue());
    } else if (val instanceof Integer) {
        Integer temp = (Integer) val;
        cell.setCellValue((double) temp.intValue());
    } else if (val instanceof Long) {
        Long temp = (Long) val;
        cell.setCellValue((double) temp.longValue());
    } else if (val instanceof Float) {
        Float temp = (Float) val;
        cell.setCellValue((double) temp.floatValue());
    } else if (val instanceof Double) {
        Double temp = (Double) val;
        cell.setCellValue((double) temp.doubleValue());
    } else if (val instanceof Date) {// Date
        Date dateVal = (Date) val;
        long time = dateVal.getTime();
        // read is based on 1899/12/31 but DateUtil.getExcelDate is base on
        // 1900/01/01
        if (time >= TIME_1899_12_31_00_00_00_000 && time < TIME_1900_01_01_00_00_00_000) {
            Date incOneDay = new Date(time + 24 * 60 * 60 * 1000);
            double d = DateUtil.getExcelDate(incOneDay);
            cell.setCellValue(d - 1);
        } else {
            cell.setCellValue(dateVal);
        }

        if (!userTemplate) {
            Workbook wb = cell.getRow().getSheet().getWorkbook();
            CellStyle cellStyle = cell.getCellStyle();
            if (cellStyle == null) {
                cellStyle = wb.createCellStyle();
            }
            DataFormat dataFormat = wb.getCreationHelper().createDataFormat();
            // @see #BuiltinFormats
            // 0xe, "m/d/yy"
            // 0x14 "h:mm"
            // 0x16 "m/d/yy h:mm"
            // {@linke https://en.wikipedia.org/wiki/Year_10,000_problem}
            /** [1899/12/31 00:00:00:000~1900/01/01 00:00:000) */
            if (time >= TIME_1899_12_31_00_00_00_000 && time < TIME_1900_01_02_00_00_00_000) {
                cellStyle.setDataFormat(dataFormat.getFormat("h:mm"));
                // cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy h:mm"));
            } else {
                // if ( time % (24 * 60 * 60 * 1000) == 0) {//for time
                // zone,we can't use this way.
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(dateVal);
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                int minute = calendar.get(Calendar.MINUTE);
                int second = calendar.get(Calendar.SECOND);
                int millisecond = calendar.get(Calendar.MILLISECOND);
                if (millisecond == 0 && second == 0 && minute == 0 && hour == 0) {
                    cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy"));
                } else {
                    cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy h:mm"));
                }
            }
            cell.setCellStyle(cellStyle);
        }
    } else if (val instanceof Boolean) {// Boolean
        cell.setCellValue(((Boolean) val).booleanValue());
    } else {// String
        cell.setCellValue((String) val.toString());
    }
}