List of usage examples for java.lang Long shortValue
public short shortValue()
From source file:com.intuit.tank.vm.settings.AgentConfigCpTest.java
/** * Run the Long getConnectionTimeout() method test. * //from www .ja va 2s.c o m * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testGetConnectionTimeout_1() throws Exception { AgentConfig fixture = new AgentConfig(new HierarchicalConfiguration()); fixture.setResultsTypeMap(new HashMap()); Long result = fixture.getConnectionTimeout(); assertNotNull(result); assertEquals("40000", result.toString()); assertEquals((byte) 64, result.byteValue()); assertEquals((short) -25536, result.shortValue()); assertEquals(40000, result.intValue()); assertEquals(40000L, result.longValue()); assertEquals(40000.0f, result.floatValue(), 1.0f); assertEquals(40000.0, result.doubleValue(), 1.0); }
From source file:cz.lbenda.dataman.db.RowDesc.java
@SuppressWarnings({ "unchecked", "RedundantCast" }) private <T> T repairClassOfValue(ColumnDesc column, T value) { if (value == null) { return null; }/*from w ww .j av a2s. c o m*/ if (column.getDataType().getJavaClass().equals(value.getClass())) { return value; } if (column.getDataType() == ColumnType.TIME) { if (value instanceof LocalTime) { return (T) (Object) java.sql.Time.valueOf((LocalTime) value); } } else if (column.getDataType() == ColumnType.DATE) { if (value instanceof LocalDate) { return (T) (Object) java.sql.Date.valueOf((LocalDate) value); } } else if (column.getDataType() == ColumnType.TIMESTAMP) { if (value instanceof LocalDateTime) { return (T) (Object) java.sql.Timestamp.valueOf((LocalDateTime) value); } } else { Long val; if (value instanceof Long) { val = (Long) value; } else if (value instanceof Integer) { val = ((Integer) value).longValue(); } else if (value instanceof Short) { val = ((Short) value).longValue(); } else if (value instanceof Byte) { val = ((Byte) value).longValue(); } else { return value; } if (column.getDataType() == ColumnType.INTEGER) { return (T) (Object) val.intValue(); } if (column.getDataType() == ColumnType.BYTE) { return (T) (Object) val.byteValue(); } if (column.getDataType() == ColumnType.SHORT) { return (T) (Object) val.shortValue(); } } return value; }
From source file:org.mifos.application.servicefacade.LoanAccountServiceFacadeWebTier.java
@Override public VariableInstallmentWithFeeValidationResult validateFeeCanBeAppliedToVariableInstallmentLoan(Long feeId) { try {//from w w w . j ava 2s .co m org.mifos.dto.domain.FeeDto fee = this.feeDao.findDtoById(feeId.shortValue()); boolean feeCanBeAppliedToVariableInstallmentLoan = true; String feeName = fee.getName(); if (fee.isPeriodic()) { feeCanBeAppliedToVariableInstallmentLoan = false; } else if (fee.isRateBasedFee()) { FeeFormula formula = FeeFormula.getFeeFormula(fee.getFeeFormula().getId()); switch (formula) { case AMOUNT_AND_INTEREST: feeCanBeAppliedToVariableInstallmentLoan = false; break; case INTEREST: feeCanBeAppliedToVariableInstallmentLoan = false; break; default: break; } } return new VariableInstallmentWithFeeValidationResult(feeCanBeAppliedToVariableInstallmentLoan, feeName); } catch (PropertyNotFoundException e) { throw new MifosRuntimeException(e); } }
From source file:ca.oson.json.Oson.java
private <E> String short2Json(FieldData objectDTO) { if (objectDTO == null || objectDTO.json2Java) { return null; }/*w w w. j a v a 2 s . com*/ Object value = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; if (returnType != null && value != null && (returnType == short.class || returnType == Short.class)) { Short valueToProcess = null; String valueToReturn = null; if (returnType == short.class) { valueToProcess = Short.valueOf((short) value); } else { valueToProcess = (Short) value; } if (valueToProcess != null) { try { Function function = objectDTO.getSerializer(); if (function != null) { try { if (function instanceof DataMapper2JsonFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); return ((DataMapper2JsonFunction) function).apply(classData); } else if (function instanceof Short2JsonFunction) { return ((Short2JsonFunction) function).apply(valueToProcess); } else { Object returnedValue = null; if (function instanceof FieldData2JsonFunction) { FieldData2JsonFunction f = (FieldData2JsonFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else { returnedValue = function.apply(value); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } else if (returnedValue instanceof Short) { valueToProcess = (Short) returnedValue; } else { objectDTO.valueToProcess = returnedValue; return object2String(objectDTO); } } } catch (Exception e) { } } if (valueToProcess != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min.shortValue() > valueToProcess) { valueToProcess = min.shortValue(); } if (max != null && max.shortValue() < valueToProcess) { valueToProcess = max.shortValue(); } Integer precision = objectDTO.getPrecision(); if (precision != null) { valueToProcess = (Short) NumberUtil.setPrecision(valueToProcess, precision, getRoundingMode()); } return NumberUtil.toPlainString(valueToProcess); } } catch (Exception ex) { //ex.printStackTrace(); } } } return short2JsonDefault(objectDTO); }
From source file:ca.oson.json.Oson.java
private <E> Short json2Short(FieldData objectDTO) { if (objectDTO == null || !objectDTO.json2Java) { return null; }// w w w . j a va 2 s . c o m Object value = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; if (value != null && value.toString().trim().length() > 0) { String valueToProcess = value.toString().trim(); Short valueToReturn = null; try { Function function = objectDTO.getDeserializer(); if (function != null) { try { Object returnedValue = null; if (function instanceof Json2DataMapperFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); returnedValue = ((Json2DataMapperFunction) function).apply(classData); } else if (function instanceof Json2FieldDataFunction) { Json2FieldDataFunction f = (Json2FieldDataFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else if (function instanceof Json2ShortFunction) { return ((Json2ShortFunction) function).apply(valueToProcess); } else { returnedValue = function.apply(valueToProcess); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } else if (Number.class.isAssignableFrom(returnedValue.getClass()) || returnedValue.getClass().isPrimitive()) { if (returnedValue instanceof Short) { valueToReturn = (Short) returnedValue; } else if (returnedValue instanceof String) { valueToReturn = Short .parseShort(NumberUtil.removeTrailingDecimalZeros(returnedValue)); } else if (returnedValue instanceof Integer) { valueToReturn = ((Integer) returnedValue).shortValue(); } else if (returnedValue instanceof Long) { valueToReturn = ((Long) returnedValue).shortValue(); } else if (returnedValue instanceof Byte) { valueToReturn = ((Byte) returnedValue).shortValue(); } else if (returnedValue instanceof Double) { valueToReturn = ((Double) returnedValue).shortValue(); } else if (returnedValue instanceof Float) { valueToReturn = ((Float) returnedValue).shortValue(); } else if (returnedValue instanceof BigInteger) { valueToReturn = ((BigInteger) returnedValue).shortValue(); } else if (returnedValue instanceof BigDecimal) { valueToReturn = ((BigDecimal) returnedValue).shortValue(); } else if (returnedValue instanceof AtomicInteger) { valueToReturn = ((AtomicInteger) returnedValue).shortValue(); } else if (returnedValue instanceof AtomicLong) { valueToReturn = ((AtomicLong) returnedValue).shortValue(); } else { valueToReturn = ((Number) returnedValue).shortValue(); } } else if (returnedValue instanceof Character) { valueToReturn = (short) (((Character) returnedValue).charValue()); } else if (returnedValue instanceof Boolean) { if ((Boolean) returnedValue) valueToReturn = 1; else valueToReturn = 0; } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = ((Integer) ((Enum) returnedValue).ordinal()).shortValue(); } else if (Date.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = (short) ((Date) returnedValue).getTime(); } else { valueToReturn = Short.parseShort(NumberUtil.removeTrailingDecimalZeros(returnedValue)); } return valueToReturn; } catch (Exception e) { e.printStackTrace(); } } else { long longValue = Long.parseLong(NumberUtil.removeTrailingDecimalZeros(valueToProcess)); if (longValue > Short.MAX_VALUE) { valueToReturn = Short.MAX_VALUE; } else { valueToReturn = (short) longValue; } // valueToReturn = Short.parseShort(valueToProcess); } if (valueToReturn != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min.shortValue() > valueToReturn) { return min.shortValue(); } if (max != null && max.shortValue() < valueToReturn) { valueToReturn = max.shortValue(); } return valueToReturn; } } catch (Exception ex) { //ex.printStackTrace(); } } return json2ShortDefault(objectDTO); }
From source file:ca.oson.json.Oson.java
private <E> Short json2ShortDefault(FieldData objectDTO) { Object value = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; boolean required = objectDTO.required(); Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); boolean json2Java = objectDTO.json2Java; if (returnType == short.class || getDefaultType() == JSON_INCLUDE.DEFAULT || required) { Short defaultValue = (Short) objectDTO.getDefaultValue(); if (defaultValue != null) { if (min != null && min.shortValue() > defaultValue) { return min.shortValue(); }/*w w w .j a v a 2 s. c o m*/ return defaultValue; } if (min != null && min.shortValue() > DefaultValue.dshort) { return min.shortValue(); } return DefaultValue.dshort; } return null; }