List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:com.sindicetech.siren.solr.facet.SirenFieldFacetExtractor.java
private void generateFacetsForCustomDatatypeLeaf(ObjectNode object, String fieldName, ExtendedJsonField sirenField, String path, List<SirenFacetEntry> facets) { Iterator<Entry<String, JsonNode>> iterator = object.getFields(); String datatype = null;//from ww w . jav a 2s. co m String value = null; while (iterator.hasNext()) { Entry<String, JsonNode> entry = iterator.next(); if ("_datatype_".equals(entry.getKey())) { datatype = entry.getValue().asText(); } else if ("_value_".equals(entry.getKey())) { value = entry.getValue().asText(); } else { logger.warn("Unexpected field {} in custom datatype object: {}", entry.getKey(), object.asText()); continue; } } if (datatype == null || value == null) { logger.warn( "Unexpected form of custom datatype object: {}. Not generating facets for this nested object.", object.asText()); return; } SirenFacetEntry entry = new SirenFacetEntry(); entry.fieldName = fieldName; entry.path = path; Datatype customDatatype = sirenField.getDatatypes().get(datatype); if (customDatatype instanceof TrieDatatype) { NumericAnalyzer analyzer = (NumericAnalyzer) customDatatype.getAnalyzer(); NumericParser parser = analyzer.getNumericParser(); try { Number number = parser.parse(new StringReader(value)); if ((number instanceof Float) || (number instanceof Double)) { entry.datatype = FacetDatatype.DOUBLE; entry.value = number.doubleValue(); } else if ((number instanceof Integer) || (number instanceof Long)) { entry.datatype = FacetDatatype.LONG; entry.value = number.longValue(); } else { logger.warn( "Unknown number type {} in custom datatype in nested object {}. Not creating facet field.", number.getClass().getCanonicalName(), object.asText()); return; } } catch (IOException e) { logger.warn("Problem parsing custom datatype {} in nested object {}: " + e.getMessage(), datatype, object.asText()); return; } } else { entry.datatype = FacetDatatype.STRING; entry.value = value; } facets.add(entry); }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Double> getNormal(final RandomNumberStream rng, final Number mean, final Number sd) { final RealDistribution dist = new NormalDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng), mean.doubleValue(), sd.doubleValue()); return new RandomNumberDistribution<Double>() { @Override//from www . j a v a2 s .c o m public Double draw() { return dist.sample(); } }; }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Double> getBeta(final RandomNumberStream rng, final Number alpha, final Number beta) { final RealDistribution dist = new BetaDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng), alpha.doubleValue(), beta.doubleValue()); return new RandomNumberDistribution<Double>() { @Override// ww w .ja v a 2s .co m public Double draw() { return dist.sample(); } }; }
From source file:msi.gaml.operators.Stats.java
@operator(value = "min", can_be_const = true, type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 1, expected_content_type = { IType.INT, IType.FLOAT, IType.POINT }, category = { IOperatorCategory.STATISTICAL, IOperatorCategory.CONTAINER }, concept = { IConcept.STATISTIC }) @doc(value = "the minimum element found in the operand.", masterDoc = true, comment = "the min operator behavior depends on the nature of the operand", usages = { @usage(value = "if it is a list of int or float: min returns the minimum of all the elements", examples = { @example(value = "min ([100, 23.2, 34.5])", equals = "23.2") }), @usage(value = "if it is a list of points: min returns the minimum of all points as a point (i.e. the point with the smallest coordinate on the x-axis, in case of equality the point with the smallest coordinate on the y-axis is chosen. If all the points are equal, the first one is returned. )"), @usage(value = "if it is a population of a list of other types: min transforms all elements into integer and returns the minimum of them"), @usage(value = "if it is a map, min returns the minimum among the list of all elements value"), @usage(value = "if it is a file, min returns the minimum of the content of the file (that is also a container)"), @usage(value = "if it is a graph, min returns the minimum of the list of the elements of the graph (that can be the list of edges or vertexes depending on the graph)"), @usage(value = "if it is a matrix of int, float or object, min returns the minimum of all the numerical elements (thus all elements for integer and float matrices)"), @usage(value = "if it is a matrix of geometry, min returns the minimum of the list of the geometries"), @usage(value = "if it is a matrix of another type, min returns the minimum of the elements transformed into float") }, see = { "max" }) public static Object min(final IScope scope, final IContainer l) { Number minNum = null; ILocation minPoint = null;//ww w . j av a 2s . com for (final Object o : l.iterable(scope)) { if (o instanceof ILocation && minNum == null) { if (minPoint == null || ((ILocation) o).compareTo(minPoint) < 0) { minPoint = (ILocation) o; } } else if (o instanceof Number && minPoint == null && (minNum == null || ((Number) o).doubleValue() < minNum.doubleValue())) { minNum = (Number) o; } else { final Double d = Cast.asFloat(scope, o); if (minNum == null || d < minNum.doubleValue()) { minNum = d; } } } return minNum == null ? minPoint : minNum; }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert// www . j a v a 2 s .co m * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class targetClass) throws IllegalArgumentException { if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:edu.ucla.stat.SOCR.chart.gui.ExtendedStackedBarRenderer.java
/** * Draws a stacked bar for a specific item. * * @param g2 the graphics device./*from w w w . j a va 2 s . c o m*/ * @param state the renderer state. * @param dataArea the plot area. * @param plot the plot. * @param domainAxis the domain (category) axis. * @param rangeAxis the range (value) axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // nothing is drawn for null values... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); PlotOrientation orientation = plot.getOrientation(); double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0; double positiveBase = 0.0; double negativeBase = 0.0; for (int i = 0; i < row; i++) { Number v = dataset.getValue(i, column); if (v != null) { double d = v.doubleValue(); if (d > 0) { positiveBase = positiveBase + d; } else { negativeBase = negativeBase + d; } } } double translatedBase; double translatedValue; RectangleEdge location = plot.getRangeAxisEdge(); if (value > 0.0) { translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location); } else { translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location); } double barL0 = Math.min(translatedBase, translatedValue); double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength()); Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } if (value > 0.0) { if (this.showPositiveTotal) { if (isLastPositiveItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfPositiveValuesForCategory(dataset, column); if (orientation == PlotOrientation.HORIZONTAL) TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) (bar.getMaxX() + 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_LEFT, 0.0, TextAnchor.CENTER_LEFT); else TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) bar.getCenterX(), (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER, 0.0, TextAnchor.BOTTOM_CENTER); } } } else { if (this.showNegativeTotal) { if (isLastNegativeItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfNegativeValuesForCategory(dataset, column); if (orientation == PlotOrientation.HORIZONTAL) TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) (bar.getMinX() - 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_RIGHT, 0.0, TextAnchor.CENTER_RIGHT); else TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(), (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER); } } } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Double> getGamma(final RandomNumberStream rng, final Number shape, final Number scale) { final RealDistribution dist = new GammaDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng), shape.doubleValue(), scale.doubleValue()); return new RandomNumberDistribution<Double>() { @Override/*w ww. ja v a2 s. c o m*/ public Double draw() { return dist.sample(); } }; }
From source file:msi.gaml.operators.Stats.java
@operator(value = "max", can_be_const = true, type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 1, expected_content_type = { IType.INT, IType.FLOAT, IType.POINT }, category = { IOperatorCategory.STATISTICAL, IOperatorCategory.CONTAINER }, concept = { IConcept.STATISTIC }) @doc(value = "the maximum element found in the operand", masterDoc = true, comment = "the max operator behavior depends on the nature of the operand", usages = { @usage(value = "if it is a list of int of float, max returns the maximum of all the elements", examples = { @example(value = "max ([100, 23.2, 34.5])", equals = "100.0") }), @usage(value = "if it is a list of points: max returns the maximum of all points as a point (i.e. the point with the greatest coordinate on the x-axis, in case of equality the point with the greatest coordinate on the y-axis is chosen. If all the points are equal, the first one is returned. )", examples = { @example(value = "max([{1.0,3.0},{3.0,5.0},{9.0,1.0},{7.0,8.0}])", equals = "{9.0,1.0}") }), @usage("if it is a population of a list of other type: max transforms all elements into integer and returns the maximum of them"), @usage("if it is a map, max returns the maximum among the list of all elements value"), @usage("if it is a file, max returns the maximum of the content of the file (that is also a container)"), @usage("if it is a graph, max returns the maximum of the list of the elements of the graph (that can be the list of edges or vertexes depending on the graph)"), @usage("if it is a matrix of int, float or object, max returns the maximum of all the numerical elements (thus all elements for integer and float matrices)"), @usage("if it is a matrix of geometry, max returns the maximum of the list of the geometries"), @usage("if it is a matrix of another type, max returns the maximum of the elements transformed into float") }, see = { "min" }) public static Object max(final IScope scope, final IContainer l) { Number maxNum = null; ILocation maxPoint = null;/*from www. ja v a2 s .co m*/ for (final Object o : l.iterable(scope)) { if (o instanceof ILocation && maxNum == null) { if (maxPoint == null || ((ILocation) o).compareTo(maxPoint) > 0) { maxPoint = (ILocation) o; } } else if (o instanceof Number && maxPoint == null && (maxNum == null || ((Number) o).doubleValue() > maxNum.doubleValue())) { maxNum = (Number) o; } else { final Double d = Cast.asFloat(scope, o); if (maxNum == null || d > maxNum.doubleValue()) { maxNum = d; } } } return maxNum == null ? maxPoint : maxNum; }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Double> getPareto(final RandomNumberStream rng, final Number scale, final Number shape) { final RealDistribution dist = new ParetoDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng), scale.doubleValue(), shape.doubleValue()); return new RandomNumberDistribution<Double>() { @Override//from w ww . j a va 2 s .c om public Double draw() { return dist.sample(); } }; }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Double> getWeibull(final RandomNumberStream rng, final Number alpha, final Number beta) { final RealDistribution dist = new WeibullDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng), alpha.doubleValue(), beta.doubleValue()); return new RandomNumberDistribution<Double>() { @Override/*from www.j av a2 s.co m*/ public Double draw() { return dist.sample(); } }; }