break; case DataType.INTEGER: tuple.set(i, DataType.toInteger(object)); break; case DataType.LONG:
/** * Force a data object to an Integer, if possible. Any numeric type * can be forced to an Integer (though precision may be lost), as well * as CharArray, ByteArray, or Boolean. Complex types cannot be * forced to an Integer. This isn't particularly efficient, so if you * already <b>know</b> that the object you have is an Integer you * should just cast it. Unlike {@link #toInteger(Object, byte)} this * method will first determine the type of o and then do the cast. * Use {@link #toInteger(Object, byte)} if you already know the type. * @param o object to cast * @return The object as an Integer. * @throws ExecException if the type can't be forced to an Integer. */ public static Integer toInteger(Object o) throws ExecException { return toInteger(o, findType(o)); }
/** * java level API * @param input expects a numeric value to round, a number of digits to keep, and an optional rounding mode. * @return output returns a single numeric value, the number with only those digits retained */ @Override public Double exec(Tuple input) throws IOException { if (input == null || input.size() < 2) return null; try { Double num = DataType.toDouble(input.get(0)); Integer digits = DataType.toInteger(input.get(1)); RoundingMode mode = (input.size() >= 3) ? RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN; if (num == null) return null; BigDecimal bdnum = BigDecimal.valueOf(num); bdnum = bdnum.setScale(digits, mode); return bdnum.doubleValue(); } catch (NumberFormatException nfe){ System.err.println("Failed to process input; error - " + nfe.getMessage()); return null; } catch (Exception e){ throw new IOException("Caught exception processing input row ", e); } }
/** * java level API * @param input expects a numeric value to round, a number of digits to keep, and an optional rounding mode. * @return output returns a single numeric value, the number with only those digits retained */ @Override public Double exec(Tuple input) throws IOException { if (input == null || input.size() < 2) return null; try { Double num = (Double)input.get(0); Integer digits = (Integer)input.get(1); RoundingMode mode = (input.size() >= 3) ? RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN; if (num == null) return null; BigDecimal bdnum = BigDecimal.valueOf(num); bdnum = bdnum.setScale(digits, mode); return bdnum.doubleValue(); } catch (Exception e){ throw new IOException("Caught exception processing input row ", e); } }
/** * java level API * @param input expects a numeric value to round, a number of digits to keep, and an optional rounding mode. * @return output returns a single numeric value, the number with only those digits retained */ @Override public Float exec(Tuple input) throws IOException { if (input == null || input.size() < 2) return null; try { Float num = (Float)input.get(0); Integer digits = (Integer)input.get(1); RoundingMode mode = (input.size() >= 3) ? RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN; if (num == null) return null; BigDecimal bdnum = BigDecimal.valueOf(num); bdnum = bdnum.setScale(digits, mode); return bdnum.floatValue(); } catch (Exception e){ throw new IOException("Caught exception processing input row ", e); } }
return DataType.toInteger(o); case DataType.LONG: return DataType.toLong(o);
break; case DataType.INTEGER: tuple.set(i, DataType.toInteger(object)); break; case DataType.LONG: