@Override public Entry<String, Double> next() { Entry<String, ValueObject> input = iterator.next(); return new SimpleEntry<>(input.getKey(), input.getValue().asDouble().getDouble()); }
@Override public Double remove(Object key) { String stringKey = (String) key; ValueObject val = data.remove(stringKey); if (val == null) { return null; } else { return val.asDouble().getDouble(); } }
@Override public Double get(int index) { ValueObject val = data.get(index); if (val == null) return null; return val.asDouble().getDouble(); }
@Override public Double remove(int index) { ValueObject prev = data.remove(index); if (prev == null) return null; return prev.asDouble().getDouble(); }
@Override public Double get(Object key) { String stringKey = (String) key; ValueObject val = data.get(stringKey); if (val == null) { return null; } else { return val.asDouble().getDouble(); } }
@Override public Double put(String key, Double value) { ValueObject val = data.put(key, ValueFactory.create(value)); if (val == null) { return null; } else { return val.asDouble().getDouble(); } }
@Override public Double set(int index, Double element) { ValueObject prev = data.set(index, ValueFactory.create(element)); if (prev == null) return null; return prev.asDouble().getDouble(); }
private void announce(String metricName, String metricGroup, ValueObject metricValue, String metricUnits) throws GangliaException { // see if we have to represent a long as a double if (metricValue.getObjectType() == ValueObject.TYPE.INT) { long asLong = metricValue.asLong().getLong(); if ((int) asLong != asLong) { metricValue = metricValue.asDouble(); } } for (GMetric gmetric : gmetrics) { gmetric.announce(metricName, metricValue.toString(), detectType(metricValue.getObjectType()), metricUnits, GMetricSlope.BOTH, tMax, dMax, metricGroup); } }
@Override public void setValues(ValueMap valueMapEntries) { byte[] b = valueMapEntries.get("b").asBytes().asNative(); this.quantile = valueMapEntries.get("q").asDouble().getDouble(); this.op = OP.valueOf(valueMapEntries.get("o").asString().toString()); heldObject = TDigest.fromBytes(ByteBuffer.wrap(b)); }
private Object unbox(ValueObject val) { switch (val.getObjectType()) { case INT: return val.asLong().getLong(); case FLOAT: return val.asDouble().getDouble(); case STRING: return val.asString().asNative(); case ARRAY: List<Object> retList = new LinkedList<>(); for (ValueObject element : val.asArray()) { retList.add(unbox(element)); } return retList; case MAP: Map<String, Object> retMap = new HashMap<>(); ValueMap valAsMap = val.asMap(); for (ValueMapEntry entry : valAsMap) { retMap.put(entry.getKey(), unbox(entry.getValue())); } return retMap; } throw new IllegalArgumentException("Unsupported bundle field type: " + val.getObjectType()); }
@Override public void setValues(ValueMap map) { targetEpoch = map.get("targetEpoch").asLong().asNative(); numObservations = map.get("numObservations").asLong().asNative().intValue(); doubleToLongBits = map.get("doubleToLongBits").asLong().asNative().intValue() == 1; raw = map.get("raw").asLong().asNative().intValue() == 1; percentile = map.get("percentile").asDouble().asNative(); sigma = map.get("sigma").asDouble().asNative(); minMeasurement = map.get("minMeasurement").asLong().asNative().intValue(); mode = map.get("mode").asString().asNative(); long minEpoch = map.get("minEpoch").asLong().asNative(); ValueArray reservoirValueObject = map.get("reservoir").asArray(); int size = reservoirValueObject.size(); int[] reservoir = new int[size]; for (int i = 0; i < size; i++) { reservoir[i] = reservoirValueObject.get(i).asLong().asNative().intValue(); } this.heldObject = new DataReservoir(minEpoch, reservoir); }
@Test public void testGetValue() { DataReservoir reservoir = new DataReservoir(); reservoir.updateReservoir(1, 4, 4); reservoir.updateReservoir(2, 4, 12); reservoir.updateReservoir(3, 4, 4); reservoir.updateReservoir(4, 4, 100); ValueArray result = reservoir.getValue("epoch||4~sigma||2.0~obs||3").asArray(); assertEquals(5, result.size()); assertEquals(86, DoubleMath.roundToLong(result.get(0).asDouble().getDouble(), RoundingMode.HALF_UP)); assertEquals(100, result.get(1).asLong().getLong()); assertEquals(7, DoubleMath.roundToLong(result.get(2).asDouble().getDouble(), RoundingMode.HALF_UP)); assertEquals(4, DoubleMath.roundToLong(result.get(3).asDouble().getDouble(), RoundingMode.HALF_UP)); assertEquals(14, result.get(4).asLong().getLong()); // test mode "get" assertEquals(0, reservoir.getValue("mode||get~epoch||0").asLong().getLong()); assertEquals(4, reservoir.getValue("mode||get~epoch||1").asLong().getLong()); assertEquals(12, reservoir.getValue("mode||get~epoch||2").asLong().getLong()); assertEquals(4, reservoir.getValue("mode||get~epoch||3").asLong().getLong()); assertEquals(100, reservoir.getValue("mode||get~epoch||4").asLong().getLong()); assertEquals(0, reservoir.getValue("mode||get~epoch||5").asLong().getLong()); }
@Test public void testGetSerialization() { DataReservoir reservoir = new DataReservoir(); reservoir.updateReservoir(1, 4, 4); reservoir.updateReservoir(2, 4, 12); reservoir.updateReservoir(3, 4, 4); reservoir.updateReservoir(4, 4, 100); DataReservoir.DataReservoirValue original = (DataReservoir.DataReservoirValue) reservoir.getValue("epoch||4~sigma||2.0~obs||3"); DataReservoir.DataReservoirValue translated = new DataReservoir.DataReservoirValue(); translated.setValues(original.asMap()); ValueArray result = translated.asArray(); assertEquals(5, result.size()); assertEquals(86, DoubleMath.roundToLong(result.get(0).asDouble().getDouble(), RoundingMode.HALF_UP)); assertEquals(100, result.get(1).asLong().getLong()); assertEquals(7, DoubleMath.roundToLong(result.get(2).asDouble().getDouble(), RoundingMode.HALF_UP)); assertEquals(4, DoubleMath.roundToLong(result.get(3).asDouble().getDouble(), RoundingMode.HALF_UP)); assertEquals(14, result.get(4).asLong().getLong()); // test mode "get" assertEquals(0, reservoir.getValue("mode||get~epoch||0").asLong().getLong()); assertEquals(4, reservoir.getValue("mode||get~epoch||1").asLong().getLong()); assertEquals(12, reservoir.getValue("mode||get~epoch||2").asLong().getLong()); assertEquals(4, reservoir.getValue("mode||get~epoch||3").asLong().getLong()); assertEquals(100, reservoir.getValue("mode||get~epoch||4").asLong().getLong()); assertEquals(0, reservoir.getValue("mode||get~epoch||5").asLong().getLong()); }