List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:ru.iris.noolite4j.gateway.HTTPCommand.java
/** * ? ??/* w w w .ja v a2 s . c o m*/ * @return ?? ?? */ public List<Sensor> getSensors() { List<Sensor> sensors = new ArrayList<>(); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse("http://" + PR1132.getHost() + "/sens.xml"); doc.getDocumentElement().normalize(); String text = doc.getDocumentElement().getTextContent(); String[] values = text.split("\n"); for (int idx = 1; idx <= values.length - 1; idx++) { if (values[idx].isEmpty()) continue; double value = 0; if (!values[idx].equals("-")) { NumberFormat format = NumberFormat.getInstance(); Number number = format.parse(values[idx]); value = number.doubleValue(); } /** * ? ?? ? ?? */ byte channel = 0; if (idx <= 3) channel = 1; else if (idx >= 4 && idx <= 6) channel = 2; else if (idx >= 7 && idx <= 9) channel = 3; else if (idx >= 10 && idx <= 12) channel = 4; Sensor sensor; if (sensors.size() >= channel) { sensor = sensors.get(channel - 1); } else { sensor = new Sensor(); } if (sensor == null) sensor = new Sensor(); sensor.setChannel(channel); /** * */ if (idx == 1 || idx == 4 || idx == 7 || idx == 10) { value /= 10; sensor.setTemperature(value); } else if (idx == 2 || idx == 5 || idx == 8 || idx == 11) { sensor.setHumidity((byte) value); } else if (idx == 3 || idx == 6 || idx == 9 || idx == 12) { sensor.setState(SensorState.values()[(int) value]); } boolean isNew = true; for (int i = 0; i < sensors.size(); i++) { if (sensors.get(i).getChannel() == sensor.getChannel()) { sensors.remove(i); sensors.add(i, sensor); isNew = false; } } if (isNew) { sensors.add(sensor); } } } catch (Exception e) { LOGGER.error(" ? PR1132: " + e.getMessage()); e.printStackTrace(); } return sensors; }
From source file:mulavito.algorithms.shortestpath.ksp.Eppstein.java
/** * Create <math>\delta(e)</math> for each edge in graph {@link #g}. * // w ww .j a va2s . co m * @param target * The target * @return The delta edge weight. */ private Transformer<E, Double> prepareTransformations(V target) { Map<V, Double> lengthMap = new HashMap<V, Double>(); // d(x, t) Map<E, Double> edgeMap = new HashMap<E, Double>(); // Search the shortest path from "target" to any vertex, // and store the length in a map. for (V v : graph.getVertices()) { Number dist = dijkstra.getDistance(v, target); if (dist != null) // target is reachable from v. lengthMap.put(v, dist.doubleValue()); else { // Block edges from or to unreachable vertices. for (E e : graph.getIncidentEdges(v)) edgeMap.put(e, Double.POSITIVE_INFINITY); } } // Calculate delta(e) for (E e : graph.getEdges()) { if (edgeMap.get(e) == null) { // Only consider edges to reachable vertices. double l = nev.transform(e).doubleValue() /* l(e) */ + lengthMap.get(graph.getDest(e)) /* d(head(e), t) */ - lengthMap.get(graph.getSource(e)) /* d(tail(e), t) */; edgeMap.put(e, l); } } return MapTransformer.getInstance(edgeMap); }
From source file:org.xwiki.rendering.internal.macro.chart.source.AxisConfigurator.java
/** * Set the limits of a number axis.// w w w .j a va 2 s . com * * @param axis The axis. * @param index The index of the axis * @throws MacroExecutionException if the parameters could not be parsed as numbers. */ private void setNumberLimits(ValueAxis axis, int index) throws MacroExecutionException { try { if (axisLowerLimit[index] != null) { Number number = NumberUtils.createNumber(StringUtils.trim(axisLowerLimit[index])); axis.setLowerBound(number.doubleValue()); } if (axisUpperLimit[index] != null) { Number number = NumberUtils.createNumber(StringUtils.trim(axisUpperLimit[index])); axis.setUpperBound(number.doubleValue()); } } catch (NumberFormatException e) { throw new MacroExecutionException("Invalid number in axis bound.", e); } }
From source file:de.instantouch.model.io.SnakeJSONReader.java
public void read(SnakeType type, Object value) throws SnakeModelException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { if (type.hasReference()) { SnakeReference ref = type.getReference(); if (ref == null) { throw new SnakeNotInitializedException("reference is not initialized"); }/*ww w. j av a 2 s . c o m*/ SnakeType key = ref.getKey(); if (key == null) { throw new SnakeNotInitializedException("no reference key container os given"); } read(key, value); } else { if (type instanceof SnakeEntity) { readEntity((SnakeEntity) type, value); } else if (type instanceof SnakeList) { readList((SnakeList) type, value); } else if (type instanceof SnakeMap) { readMap((SnakeMap) type, value); } else if (value == null) { type.setNull(); } else if (value instanceof String) { type.set(value.toString()); } else if (value instanceof Boolean) { type.set(value.toString()); } else if (value instanceof Number) { Number number = (Number) value; if (value instanceof Double) { type.set(number.doubleValue()); } else if (value instanceof Float) { type.set(number.floatValue()); } else if (value instanceof Byte) { type.set(number.byteValue()); } else if (value instanceof Short) { type.set(number.shortValue()); } else if (value instanceof Integer) { type.set(number.intValue()); } else if (value instanceof Long) { type.set(number.longValue()); } } } }
From source file:grakn.core.graql.analytics.MedianVertexProgram.java
@Override public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { switch (memory.getIteration()) { case 0://from w ww . j a v a2 s . c om degreeStatisticsStepResourceOwner(vertex, messenger, statisticsResourceLabelIds); break; case 1: degreeStatisticsStepResourceRelation(vertex, messenger, statisticsResourceLabelIds); break; case 2: if (vertexHasSelectedTypeId(vertex, statisticsResourceLabelIds)) { // put degree long degree = vertex.property(DEGREE).isPresent() ? getMessageCount(messenger) + (Long) vertex.value(DEGREE) : getMessageCount(messenger); vertex.property(DEGREE, degree); // select pivot randomly if (degree > 0) { memory.add(PIVOT, vertex.value((String) persistentProperties.get(RESOURCE_DATA_TYPE))); memory.add(COUNT, degree); } } break; case 3: if (vertexHasSelectedTypeId(vertex, statisticsResourceLabelIds) && (long) vertex.value(DEGREE) > 0) { Number value = vertex.value((String) persistentProperties.get(RESOURCE_DATA_TYPE)); if (value.doubleValue() < memory.<Number>get(PIVOT).doubleValue()) { updateMemoryNegative(vertex, memory, value); } else if (value.doubleValue() > memory.<Number>get(PIVOT).doubleValue()) { updateMemoryPositive(vertex, memory, value); } else { // also assign a label to pivot, so all the selected resources have label vertex.property(LABEL, 0); } } break; // default case is almost the same as case 5, except that in case 5 no vertex has label default: if (vertexHasSelectedTypeId(vertex, statisticsResourceLabelIds) && (long) vertex.value(DEGREE) > 0 && (int) vertex.value(LABEL) == memory.<Integer>get(LABEL_SELECTED)) { Number value = vertex.value((String) persistentProperties.get(RESOURCE_DATA_TYPE)); if (value.doubleValue() < memory.<Number>get(PIVOT).doubleValue()) { updateMemoryNegative(vertex, memory, value); } else if (value.doubleValue() > memory.<Number>get(PIVOT).doubleValue()) { updateMemoryPositive(vertex, memory, value); } } break; } }
From source file:ai.grakn.graql.internal.analytics.MedianVertexProgram.java
@Override public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { switch (memory.getIteration()) { case 0://from w w w. j a v a 2 s.c o m degreeStatisticsStepResourceOwner(vertex, messenger, selectedTypes, statisticsResourceTypeIds); break; case 1: degreeStatisticsStepResourceRelation(vertex, messenger); break; case 2: if (statisticsResourceTypeIds.contains(Utility.getVertexTypeId(vertex))) { // put degree long degree = getMessageCount(messenger); vertex.property(degreePropertyKey, degree); // select pivot randomly if (degree > 0) { memory.set(PIVOT, vertex.value((String) persistentProperties.get(RESOURCE_DATA_TYPE))); memory.incr(COUNT, degree); } } break; case 3: if (statisticsResourceTypeIds.contains(Utility.getVertexTypeId(vertex)) && (long) vertex.value(degreePropertyKey) > 0) { Number value = vertex.value((String) persistentProperties.get(RESOURCE_DATA_TYPE)); if (value.doubleValue() < memory.<Number>get(PIVOT).doubleValue()) { updateMemoryNegative(vertex, memory, value); } else if (value.doubleValue() > memory.<Number>get(PIVOT).doubleValue()) { updateMemoryPositive(vertex, memory, value); } else { // also assign a label to pivot, so all the selected resources have label vertex.property(labelKey, 0); } } break; // default case is almost the same as case 5, except that in case 5 no vertex has label default: if (statisticsResourceTypeIds.contains(Utility.getVertexTypeId(vertex)) && (long) vertex.value(degreePropertyKey) > 0 && (int) vertex.value(labelKey) == memory.<Integer>get(LABEL_SELECTED)) { Number value = vertex.value((String) persistentProperties.get(RESOURCE_DATA_TYPE)); if (value.doubleValue() < memory.<Number>get(PIVOT).doubleValue()) { updateMemoryNegative(vertex, memory, value); } else if (value.doubleValue() > memory.<Number>get(PIVOT).doubleValue()) { updateMemoryPositive(vertex, memory, value); } } break; } }
From source file:MutableDouble.java
/** * Adds a value./*from w w w. java2 s .c o m*/ * * @param operand * the value to add * @throws NullPointerException * if the object is null * * @since Commons Lang 2.2 */ public void add(Number operand) { this.value += operand.doubleValue(); }
From source file:MutableDouble.java
/** * Subtracts a value.//from ww w . ja va2s .c om * * @param operand * the value to add * @throws NullPointerException * if the object is null * * @since Commons Lang 2.2 */ public void subtract(Number operand) { this.value -= operand.doubleValue(); }
From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java
/** * Calculates the sum of the positive values within a category. * * @param dataset the dataset./* w ww . ja v a 2 s . c o m*/ * @param column the column (category). * * @return the sum of the positive values. */ private double calculateSumOfPositiveValuesForCategory(CategoryDataset dataset, int column) { double result = 0.0; for (int r = 0; r < dataset.getRowCount(); r++) { Number dataValue = dataset.getValue(r, column); if (dataValue != null) { double v = dataValue.doubleValue(); if (v > 0.0) { result = result + v; } } } return result; }
From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java
/** * Calculates the sum of the negative values within a category. * * @param dataset the dataset.//from w w w . j a v a 2 s .c om * @param column the column (category). * * @return the sum of the negative values. */ private double calculateSumOfNegativeValuesForCategory(CategoryDataset dataset, int column) { double result = 0.0; for (int r = 0; r < dataset.getRowCount(); r++) { Number dataValue = dataset.getValue(r, column); if (dataValue != null) { double v = dataValue.doubleValue(); if (v < 0.0) { result = result + v; } } } return result; }