private Byte convertImpl(Object input) { if (input instanceof Byte) { return (Byte) input; } else if (isNumberIsh(input)) { BigDecimal value; try { value = new BigDecimal(input.toString()); } catch (NumberFormatException e) { return null; } try { return value.byteValueExact(); } catch (ArithmeticException e) { return null; } } else { return null; } }
public static byte byteValue(BigDecimal decimal) { if (decimal == null) { return 0; } int scale = decimal.scale(); if (scale >= -100 && scale <= 100) { return decimal.byteValue(); } return decimal.byteValueExact(); }
bd = (BigDecimal) value; try { bd.byteValueExact(); return true; } catch (ArithmeticException e) {
@Override public Byte toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeByte(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.byteValueExact(); } throwConstraintViolationException(actualType, this); return null; }
bd = (BigDecimal) value; try { bd.byteValueExact(); return true; } catch (ArithmeticException e) {
@Override protected Byte createNumber(BigDecimal bg) throws ArithmeticException { return bg.byteValueExact(); }
private Byte convertImpl(Object input) { if (input instanceof Byte) { return (Byte) input; } else if (isNumberIsh(input)) { BigDecimal value; try { value = new BigDecimal(input.toString()); } catch (NumberFormatException e) { return null; } try { return value.byteValueExact(); } catch (ArithmeticException e) { return null; } } else { return null; } }
@Override public <E extends Number> Byte convertExact(Class<E> numberType, Number number) { return ConvertBigDecimal.of(number).byteValueExact(); }
@Override protected void convertNumberToNumber(BigDecimal n, NotationConvertResult<? super Byte> result) { result.converted(n.byteValueExact()); } }
@SuppressWarnings("deprecation") @Override protected void set(BigDecimal value, ByteOption property) { property.modify(value.byteValueExact()); }
@Override public Byte transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.decimalValue(node).byteValueExact(); } else { throw new IllegalArgumentException("cannot transform node of type "+ node.getClass().getCanonicalName()+" to byte"); } }
@Override public Byte transform(RDFBackend<Node> backend, Node node) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.decimalValue(node).byteValueExact(); } else { throw new IllegalArgumentException("cannot transform node of type "+ node.getClass().getCanonicalName()+" to byte"); } }
@Override public Byte transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.decimalValue(node).byteValueExact(); } else { throw new IllegalArgumentException("cannot transform node of type "+ node.getClass().getCanonicalName()+" to byte"); } }
public static Byte castToByte(Object value){ if(value == null){ return null; } if(value instanceof BigDecimal){ return ((BigDecimal) value).byteValueExact(); } if(value instanceof Number){ return ((Number) value).byteValue(); } if(value instanceof String){ String strVal = (String) value; if(strVal.length() == 0 // || "null".equals(strVal) // || "NULL".equals(strVal)){ return null; } return Byte.parseByte(strVal); } throw new JSONException("can not cast to byte, value : " + value); }
public static byte coerceToByte(Object val) throws SQLException { if (val == null) { return 0; } else if (val instanceof Byte) { return (byte) val; } else if (val instanceof Number) { try { return new BigDecimal(val.toString()).setScale(0, HALF_EVEN).byteValueExact(); } catch (ArithmeticException e) { throw new SQLException("Coercion error", e); } } else if (val instanceof String) { return Byte.parseByte(((String) val).trim()); } else if (val instanceof Boolean) { return ((Boolean) val) ? (byte) 1 : (byte) 0; } throw createCoercionException(val.getClass(), byte.class, val); }
/** Convert a BigDecimal into the specified type. */ public static void convertBigDecimalValue(BigDecimal n, Class<?> type, AsyncWork<Number, Exception> result) { try { if (byte.class.equals(type) || Byte.class.equals(type)) result.unblockSuccess(Byte.valueOf(n.byteValueExact())); else if (short.class.equals(type) || Short.class.equals(type)) result.unblockSuccess(Short.valueOf(n.shortValueExact())); else if (int.class.equals(type) || Integer.class.equals(type)) result.unblockSuccess(Integer.valueOf(n.intValueExact())); else if (long.class.equals(type) || Long.class.equals(type)) result.unblockSuccess(Long.valueOf(n.longValueExact())); else if (float.class.equals(type) || Float.class.equals(type)) result.unblockSuccess(Float.valueOf(n.floatValue())); else if (double.class.equals(type) || Double.class.equals(type)) result.unblockSuccess(Double.valueOf(n.doubleValue())); else if (BigInteger.class.equals(type)) result.unblockSuccess(n.toBigIntegerExact()); else if (BigDecimal.class.equals(type)) result.unblockSuccess(n); else throw new Exception("Unknown numeric value type " + type.getName()); } catch (Exception e) { result.error(e); } }
public Byte getByte() throws ConversionException { if (isEmpty()) { return null; } else { try { return getBigDecimal().byteValueExact(); } catch (ArithmeticException ex) { throw new ConversionException(ex); } } }
public Byte getByte() throws ConversionException { if (isEmpty()) { return null; } else { try { return getBigDecimal().byteValueExact(); } catch (ArithmeticException ex) { throw new ConversionException(ex); } } }
@Override public Byte toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeByte(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.byteValueExact(); } throwConstraintViolationException(actualType, this); return null; }
@Override public Byte toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeByte(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.byteValueExact(); } throwConstraintViolationException(actualType, this); return null; }