private Short convertImpl(Object input) { if (input instanceof Short) { return (Short) input; } else if (isNumberIsh(input)) { BigDecimal value; try { value = new BigDecimal(input.toString()); } catch (NumberFormatException e) { return null; } try { return value.shortValueExact(); } catch (ArithmeticException e) { return null; } } else { return null; } }
public static short shortValue(BigDecimal decimal) { if (decimal == null) { return 0; } int scale = decimal.scale(); if (scale >= -100 && scale <= 100) { return decimal.shortValue(); } return decimal.shortValueExact(); }
bd = (BigDecimal) value; try { bd.shortValueExact(); return true; } catch (ArithmeticException e) {
@Override public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return actualType.getCodec().decodeShort(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder); return bd.shortValueExact(); } throwConstraintViolationException(actualType,this); return null; }
bd = (BigDecimal) value; try { bd.shortValueExact(); return true; } catch (ArithmeticException e) {
@Override protected Short createNumber(BigDecimal bg) throws ArithmeticException { return bg.shortValueExact(); }
private Short convertImpl(Object input) { if (input instanceof Short) { return (Short) input; } else if (isNumberIsh(input)) { BigDecimal value; try { value = new BigDecimal(input.toString()); } catch (NumberFormatException e) { return null; } try { return value.shortValueExact(); } catch (ArithmeticException e) { return null; } } else { return null; } }
@Override protected void convertNumberToNumber(BigDecimal n, NotationConvertResult<? super Short> result) { result.converted(n.shortValueExact()); } }
@SuppressWarnings("deprecation") @Override protected void set(BigDecimal value, ShortOption property) { property.modify(value.shortValueExact()); }
@Override public <E extends Number> Short convertExact(Class<E> numberType, Number number) { return ConvertBigDecimal.of(number).shortValueExact(); }
@FunctionType(functionName = "CINT", argumentTypes = { AccessType.DOUBLE }, returnType = AccessType.INTEGER) public static Short cint(Double value) throws UcanaccessSQLException { return new BigDecimal((long) Math.floor(value + 0.499999999999999d)).shortValueExact(); }
BigDecimal result = BigDecimal.valueOf(328).multiply( BigDecimal.valueOf(100)); try { short shortResult = result.shortValueExact(); } catch (ArithmeticException e) { // overflow System.out.println("Overflow!"); } try { int intResult = result.intValueExact(); } catch (ArithmeticException e) { // overflow }
@Override public Short transform(RDFBackend<Node> backend, Node node) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.decimalValue(node).shortValueExact(); } else { throw new IllegalArgumentException("cannot transform node of type "+ node.getClass().getCanonicalName()+" to short"); } }
@Override public Short transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.decimalValue(node).shortValueExact(); } else { throw new IllegalArgumentException("cannot transform node of type "+ node.getClass().getCanonicalName()+" to short"); } }
@Override public Short transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.decimalValue(node).shortValueExact(); } else { throw new IllegalArgumentException("cannot transform node of type "+ node.getClass().getCanonicalName()+" to short"); } }
public static Short castToShort(Object value){ if(value == null){ return null; } if(value instanceof BigDecimal){ return ((BigDecimal) value).shortValueExact(); } if(value instanceof Number){ return ((Number) value).shortValue(); } if(value instanceof String){ String strVal = (String) value; if(strVal.length() == 0 // || "null".equals(strVal) // || "NULL".equals(strVal)){ return null; } return Short.parseShort(strVal); } throw new JSONException("can not cast to short, value : " + value); }
public Short getShort() throws ConversionException { if (isEmpty()) { return null; } else { try { return getBigDecimal().shortValueExact(); } catch (ArithmeticException ex) { throw new ConversionException(ex); } } }
public Short getShort() throws ConversionException { if (isEmpty()) { return null; } else { try { return getBigDecimal().shortValueExact(); } catch (ArithmeticException ex) { throw new ConversionException(ex); } } }
@Override public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return actualType.getCodec().decodeShort(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder); return bd.shortValueExact(); } throwConstraintViolationException(actualType,this); return null; }
@Override public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return actualType.getCodec().decodeShort(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder); return bd.shortValueExact(); } throwConstraintViolationException(actualType,this); return null; }