List of usage examples for java.lang Long doubleValue
public double doubleValue()
From source file:fr.cls.atoll.motu.library.misc.intfce.Organizer.java
/** * Sets the status done.// w ww .j a va 2 s . c o m * * @param product the product * @param statusModeResponse the status mode response * * @throws MotuException the motu exception */ public static void setStatusDone(StatusModeResponse statusModeResponse, Product product) throws MotuException { String downloadUrlPath = product.getDownloadUrlPath(); String locationData = product.getExtractLocationData(); File fileData = new File(locationData); Long size = fileData.length(); Date lastModified = new Date(fileData.lastModified()); statusModeResponse.setStatus(StatusModeType.DONE); statusModeResponse.setMsg(downloadUrlPath); statusModeResponse.setSize(size.doubleValue()); statusModeResponse.setDateProc(Organizer.dateToXMLGregorianCalendar(lastModified)); statusModeResponse.setCode(ErrorType.OK); statusModeResponse.setRemoteUri(downloadUrlPath); statusModeResponse.setLocalUri(locationData); }
From source file:sg.ncl.MainController.java
private String getUsageStatisticsByTeamId(String id) { log.info("Getting usage statistics for team {}", id); HttpEntity<String> request = createHttpEntityHeaderOnly(); ResponseEntity response;/*from w w w . ja v a 2 s. c o m*/ try { response = restTemplate.exchange(properties.getUsageStat(id), HttpMethod.GET, request, String.class); } catch (RestClientException e) { log.warn("Error connecting to sio get usage statistics {}", e); return "?"; } JSONArray jsonArray = new JSONArray(response.getBody().toString()); Long usage = 0L; for (int i = 0; i < jsonArray.length(); i++) { usage += jsonArray.getLong(i); } return String.format("%.2f", usage.doubleValue() / 60); }
From source file:ca.oson.json.Oson.java
private <E, R> String double2Json(FieldData objectDTO) { if (objectDTO == null || objectDTO.json2Java) { return null; }/*from ww w. j a v a 2s . co m*/ E value = (E) objectDTO.valueToProcess; Class<R> returnType = objectDTO.returnType; if (value != null && returnType != null && (returnType == double.class || returnType == Double.class)) { Double valueToProcess = null; String valueToReturn = null; if (returnType == double.class) { valueToProcess = Double.valueOf((Double) value); } else { valueToProcess = (Double) 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 Double2JsonFunction) { return ((Double2JsonFunction) 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 Double) { valueToProcess = (Double) 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.doubleValue() > valueToProcess) { valueToProcess = min.doubleValue(); } if (max != null && max.doubleValue() < valueToProcess) { valueToProcess = max.doubleValue(); } Integer precision = objectDTO.getPrecision(); Integer scale = objectDTO.getScale(); String result = null; if (precision != null) { if (scale != null) { valueToProcess = (double) NumberUtil.setPrecision(valueToProcess, precision, getRoundingMode()); BigDecimal b = new BigDecimal(valueToProcess); b = b.setScale(scale, getRoundingMode()); result = NumberUtil.toPlainString(b); } else { result = NumberUtil.precision2Json(valueToProcess, precision, getRoundingMode()); } } else if (scale != null) { BigDecimal b = new BigDecimal(valueToProcess); b = b.setScale(scale, getRoundingMode()); result = NumberUtil.toPlainString(b); } else { result = NumberUtil.toPlainString(valueToProcess); } return NumberUtil.appendingFloatingZero(result, isAppendingFloatingZero()); } } catch (Exception ex) { //ex.printStackTrace(); } } } return double2JsonDefault(objectDTO); }
From source file:ca.oson.json.Oson.java
private <E, R> Double json2Double(FieldData objectDTO) { if (objectDTO == null || !objectDTO.json2Java) { return null; }//from w w w .jav a 2 s. com E value = (E) objectDTO.valueToProcess; Class<R> returnType = objectDTO.returnType; if (value != null && value.toString().trim().length() > 0) { String valueToProcess = value.toString().trim(); Double 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 Json2DoubleFunction) { return ((Json2DoubleFunction) 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 Double) { valueToReturn = (Double) returnedValue; } else if (returnedValue instanceof String) { valueToReturn = Double.parseDouble((String) returnedValue); } else if (returnedValue instanceof Integer) { valueToReturn = ((Integer) returnedValue).doubleValue(); } else if (returnedValue instanceof Long) { valueToReturn = ((Long) returnedValue).doubleValue(); } else if (returnedValue instanceof Byte) { valueToReturn = ((Byte) returnedValue).doubleValue(); } else if (returnedValue instanceof Short) { valueToReturn = ((Short) returnedValue).doubleValue(); } else if (returnedValue instanceof Float) { valueToReturn = ((Float) returnedValue).doubleValue(); } else if (returnedValue instanceof BigInteger) { valueToReturn = ((BigInteger) returnedValue).doubleValue(); } else if (returnedValue instanceof BigDecimal) { valueToReturn = ((BigDecimal) returnedValue).doubleValue(); } else if (returnedValue instanceof AtomicInteger) { valueToReturn = ((AtomicInteger) returnedValue).doubleValue(); } else if (returnedValue instanceof AtomicLong) { valueToReturn = ((AtomicLong) returnedValue).doubleValue(); } else { valueToReturn = ((Number) returnedValue).doubleValue(); } } else if (returnedValue instanceof Character) { valueToReturn = (double) (((Character) returnedValue).charValue()); } else if (returnedValue instanceof Boolean) { if ((Boolean) returnedValue) valueToReturn = 1d; else valueToReturn = 0d; } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = ((Integer) ((Enum) returnedValue).ordinal()).doubleValue(); } else if (Date.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = (double) ((Date) returnedValue).getTime(); } else { valueToReturn = Double.parseDouble(returnedValue.toString()); } return valueToReturn; } catch (Exception e) { e.printStackTrace(); } } else { valueToReturn = Double.parseDouble(valueToProcess); } if (valueToReturn != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min.doubleValue() > valueToReturn) { return min.doubleValue(); } if (max != null && max.doubleValue() < valueToReturn) { valueToReturn = max.doubleValue(); } return valueToReturn; } } catch (Exception ex) { //ex.printStackTrace(); } } return json2DoubleDefault(objectDTO); }
From source file:ca.oson.json.Oson.java
private <E, R> Double json2DoubleDefault(FieldData objectDTO) { E value = (E) objectDTO.valueToProcess; Class<R> returnType = objectDTO.returnType; boolean required = objectDTO.required(); Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); boolean json2Java = objectDTO.json2Java; if (returnType == double.class || getDefaultType() == JSON_INCLUDE.DEFAULT || required) { Double defaultValue = (Double) objectDTO.getDefaultValue(); if (defaultValue != null) { if (min != null && min.doubleValue() > defaultValue) { return min.doubleValue(); }//from ww w. j a v a 2 s. co m return defaultValue; } if (min != null && min.doubleValue() > DefaultValue.ddouble) { return min.doubleValue(); } return DefaultValue.ddouble; } return null; }