List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:com.dianping.cat.report.page.business.graph.CustomDataCalculator.java
private double calculate(String pattern) { JexlExpression e = jexl.createExpression(pattern); Number result = (Number) e.evaluate(null); return result.doubleValue(); }
From source file:broadwick.graph.algorithms.ShortestPath.java
/** * Returns the length of a shortest path from the source to the target vertex, or null if the target is not * reachable from the source. If either vertex is not in the graph for which this instance was created, throws * <code>IllegalArgumentException</code>. * @param source the source// w w w .j ava2 s . c om * @param target the target * @return the distance from source to target */ public final double calculateDistance(final V source, final V target) { final DijkstraDistance<V, E> distance = new DijkstraDistance<>(jungGraph, weightTransformer); final Number d = distance.getDistance(source, target); return d == null ? 0 : d.doubleValue(); }
From source file:com.insightml.evaluation.functions.MeanAbsoluteError.java
@Override public double instance(final Number prediction, final Number label, final Sample sample) { final double pred = Math.min(max, Math.max(min, prediction.doubleValue())); return Math.abs(label.doubleValue() - pred); }
From source file:com.thinkbiganalytics.policy.validation.RangeValidator.java
@Override public boolean validate(Number value) { if (value == null) { return true; }/*from ww w .jav a 2s.c o m*/ double dval = value.doubleValue(); if (min != null) { if (dval < min) { return false; } } if (max != null) { if (dval > max) { return false; } } return true; }
From source file:org.openfaces.component.chart.impl.helpers.NumberAxis3DAdapter.java
private Double getBound(Series[] series, boolean foundLowerBound) { double result = 0; for (Series seriesItem : series) { if (seriesItem == null) continue; Tuple[] tuples = seriesItem.getTuples(); for (Tuple tuple : tuples) { Number value = ((Number) tuple.getValue()); if (foundLowerBound) { if (value.doubleValue() < result) result = value.doubleValue(); } else { if (value.doubleValue() > result) result = value.doubleValue(); }//w w w. j av a 2s .c om } } return result; }
From source file:com.hihframework.core.utils.CurrencyConverter.java
/** * Convert a String to a Double and a Double to a String * * @param type the class type to output//from w w w. ja v a 2 s . c o m * @param value the object to convert * @return object the converted object (Double or String) */ public final Object convert(final Class<?> type, final Object value) { // for a null value, return null if (value == null) { return null; } else { if (value instanceof String) { if (log.isDebugEnabled()) { log.debug("value (" + value + ") instance of String"); } try { if (StringUtils.isNotEmpty(String.valueOf(value))) { return null; } if (log.isDebugEnabled()) { log.debug("converting '" + value + "' to a decimal"); } //formatter.setDecimalSeparatorAlwaysShown(true); Number num = formatter.parse(String.valueOf(value)); return new Double(num.doubleValue()); } catch (ParseException pe) { pe.printStackTrace(); } } else if (value instanceof Double) { if (log.isDebugEnabled()) { log.debug("value (" + value + ") instance of Double"); log.debug("returning double: " + formatter.format(value)); } return formatter.format(value); } } throw new ConversionException("Could not convert " + value + " to " + type.getName() + "!"); }
From source file:com.projity.server.data.MPXConverter.java
public static void oldToProjityTask(Task mpxTask, NormalTask projityTask, Context context) { //TODO what about resources that are unassigned, do they have a fictive task associated? projityTask.setName(truncName(mpxTask.getName())); if (mpxTask.getWBS() != null) projityTask.setWbs(mpxTask.getWBS()); //projityTask.setUniqueId(mpxTask.getUniqueIDValue()); projityTask.setNotes(mpxTask.getNotes()); projityTask.getCurrentSchedule().setStart(DateTime.gmt(mpxTask.getStart())); // start needs to be correct for assignment import projityTask.getCurrentSchedule().setFinish(DateTime.gmt(mpxTask.getFinish())); // finish needs to be correct for assignment import if (mpxTask.getID() == null) { // if no task id, generate one mpxTask.setID(++autoId);// w w w . jav a 2s.com } projityTask.setId(mpxTask.getID()); projityTask.setCreated(toNormalDate(mpxTask.getCreateDate())); projityTask.setDuration(toProjityDuration(mpxTask.getDuration(), context)); // set duration without controls projityTask.setEstimated(mpxTask.getEstimated()); if (mpxTask.getDeadline() != null) projityTask.setDeadline(DateTime.gmt(mpxTask.getDeadline())); Priority priority = mpxTask.getPriority(); if (priority != null) projityTask.setPriority(mpxTask.getPriority().getValue()); Number fc = mpxTask.getFixedCost(); if (fc != null) projityTask.setFixedCost(fc.doubleValue()); Date constraintDate = DateTime.gmtDate(mpxTask.getConstraintDate()); ConstraintType ct = mpxTask.getConstraintType(); if (ct != null) projityTask.setScheduleConstraint(ct.getType(), constraintDate == null ? 0 : constraintDate.getTime()); ProjectCalendar mpxCalendar = mpxTask.getCalendar(); if (mpxCalendar != null) { WorkCalendar cal = ImportedCalendarService.getInstance().findImportedCalendar(mpxCalendar); if (cal == null) System.out.println("Error finding imported calendar " + mpxCalendar.getName()); else projityTask.setWorkCalendar(cal); } // System.out.println("reading %" + mpxTask.getPercentageComplete().doubleValue()); // projityTask.setPercentComplete(mpxTask.getPercentageComplete().doubleValue()); //use stop and not percent complete because of rounding issues - this is a little odd, but true. setting stop in assignment can set % complete if (mpxTask.getStop() != null) projityTask.setStop(DateTime.gmt(mpxTask.getStop())); projityTask.setLevelingDelay(toProjityDuration(mpxTask.getLevelingDelay(), context)); // Date bs = toNormalDate(mpxTask.getBaselineStart()); projityTask.setEffortDriven(mpxTask.getEffortDriven()); if (mpxTask.getType() != null) projityTask.setSchedulingType(mpxTask.getType().getValue()); Number fixed = mpxTask.getFixedCost(); if (fixed != null) projityTask.setFixedCost(fixed.doubleValue()); if (mpxTask.getFixedCostAccrual() != null) projityTask.setFixedCostAccrual(mpxTask.getFixedCostAccrual().getType()); if (!projityTask.isMilestone() && mpxTask.getMilestone()) // only set flag if marked - don't want the flag for 0d tasks projityTask.setMarkTaskAsMilestone(true); if (mpxTask.getEarnedValueMethod() != null) projityTask.setEarnedValueMethod(mpxTask.getEarnedValueMethod().getValue()); projityTask.setIgnoreResourceCalendar(mpxTask.getIgnoreResourceCalendar()); toProjityCustomFields(projityTask.getCustomFields(), mpxTask, CustomFieldsMapper.getInstance().taskMaps, context); }
From source file:org.sakaiproject.evaluation.tool.reporting.LikertPercentageItemLabelGenerator.java
public String generateLabel(CategoryDataset dataset, int series, int category) { Number value = dataset.getValue(series, category); if (value == null) return ""; double doubleVal = value.doubleValue(); int intVal = value.intValue(); if (doubleVal == 0.0) { return "0 % (0)"; } else if (totalItems != 0) { double percentage = doubleVal / doubleTotalItems * 100; // return percentage + " % (" + intVal + ")"; // return String.format("%.2f %s (%s)", percentage,"%", intVal+""); return String.format("%.0f %s (%s)", percentage, "%", intVal + ""); } else if (value != null) { return value.toString(); }//from w ww. j a va 2 s. c o m return ""; }
From source file:org.openlmis.fulfillment.web.validator.BaseValidator.java
void rejectIfLessThanZero(List<Message.LocalizedMessage> errors, Number value, String field) { if (null == value) { errors.add(getErrorMessage(MUST_CONTAIN_VALUE, field)); } else if (value.doubleValue() < 0) { errors.add(getErrorMessage(MUST_BE_GREATER_THAN_OR_EQUAL_TO_ZERO, field)); }//from www . ja v a 2 s. c om }
From source file:com.projity.server.data.MPXConverter.java
public static void toProjityCustomFields(CustomFields projityFields, FieldContainer mpx, CustomFieldsMapper.Maps maps, Context context) { for (int i = 0; i < maps.costMap.length; i++) { Number c = (Number) mpx.getCurrentValue(maps.costMap[i]); if (c != null) projityFields.setCustomCost(i, c.doubleValue()); }/*from w w w . ja va 2s.c o m*/ for (int i = 0; i < maps.dateMap.length; i++) { Date d = (Date) mpx.getCurrentValue(maps.dateMap[i]); if (d != null) projityFields.setCustomDate(i, d.getTime()); } for (int i = 0; i < maps.durationMap.length; i++) { net.sf.mpxj.Duration d = (net.sf.mpxj.Duration) mpx.getCurrentValue(maps.durationMap[i]); if (d != null) projityFields.setCustomDuration(i, toProjityDuration(d, context)); } for (int i = 0; i < maps.finishMap.length; i++) { Date d = (Date) mpx.getCurrentValue(maps.finishMap[i]); if (d != null) projityFields.setCustomFinish(i, d.getTime()); } for (int i = 0; i < maps.flagMap.length; i++) { Boolean b = (Boolean) mpx.getCurrentValue(maps.flagMap[i]); if (b != null) projityFields.setCustomFlag(i, b.booleanValue()); } for (int i = 0; i < maps.numberMap.length; i++) { Number n = (Number) mpx.getCurrentValue(maps.numberMap[i]); if (n != null) projityFields.setCustomNumber(i, n.doubleValue()); } for (int i = 0; i < maps.startMap.length; i++) { Date d = (Date) mpx.getCurrentValue(maps.startMap[i]); if (d != null) projityFields.setCustomStart(i, d.getTime()); } for (int i = 0; i < maps.textMap.length; i++) { String s = (String) mpx.getCurrentValue(maps.textMap[i]); if (s != null) projityFields.setCustomText(i, s); } }