@Override public Entry<String, Long> next() { Entry<String, ValueObject> input = iterator.next(); return new SimpleEntry<>(input.getKey(), input.getValue().asLong().getLong()); }
@Override public Long get(Object key) { String stringKey = (String) key; ValueObject val = data.get(stringKey); if (val == null) { return null; } else { return val.asLong().getLong(); } }
@Override public Long get(int index) { ValueObject val = data.get(index); if (val == null) return null; return val.asLong().getLong(); }
@Override public Long remove(int index) { ValueObject prev = data.remove(index); if (prev == null) return null; return prev.asLong().getLong(); }
@Override public Long remove(Object key) { String stringKey = (String) key; ValueObject val = data.remove(stringKey); if (val == null) { return null; } else { return val.asLong().getLong(); } }
@Override public boolean filter(Bundle bundle) { ValueLong timeValue = time.getValue(bundle).asLong(); if (timeValue == null) { return defaultExit; } long unixTime = timeValue.getLong(); if (before != null && unixTime > tbefore) { return false; } if (after != null && unixTime < tafter) { return false; } return defaultExit; }
@Override public Long set(int index, Long element) { ValueObject prev = data.set(index, ValueFactory.create(element)); if (prev == null) return null; return prev.asLong().getLong(); }
@Override public Long put(String key, Long value) { ValueObject val = data.put(key, ValueFactory.create(value)); if (val == null) { return null; } else { return val.asLong().getLong(); } }
private boolean updateCount(String input, Bundle bundle, Config conf) { long myCount = 1; if (conf.count != null) { ValueObject v = conf.count.getValue(bundle); if (v != null) { try { myCount = v.asLong().getLong(); } catch (ValueTranslationException ignored) { return false; } } else { return false; } } sketch.add(input, myCount); return true; }
@Override public boolean filter(Bundle bundle) { ValueLong timeValue = time.getValue(bundle).asLong(); return timeValue != null ? accept(timeValue.getLong(), field.getValue(bundle)) : false; }
@Override public boolean filter(Bundle bundle) { ValueLong timeValue = time.getValue(bundle).asLong(); return timeValue != null ? accept(timeValue.getLong(), field.getValue(bundle)) : false; }
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); } }
@Test public void getInt() throws Exception { ValueObject value = applyFilter("{key: a}"); assertEquals(value.asLong().asNative().longValue(), 1); }
@Test public void getField() throws Exception { ValueObject value = applyFilter("{key.field: somekey}"); assertEquals(value.asLong().asNative().longValue(), 2); }
@Test public void defaultValue() throws Exception { ValueObject value = applyFilter("{key: e, defaultValue: 5}"); assertEquals(value.asLong().asNative().longValue(), 5); }
@Test public void defaultField() throws Exception { ValueObject value = applyFilter("{key: e, defaultValue.field: somevalue}"); assertEquals(value.asLong().asNative().longValue(), 10); }
@Test public void singleThreadedCounter() { ValueFilterCounter counter = new ValueFilterCounter(null, 0, 1, 0); Thread thread = new CounterThread(counter, 1000000); thread.start(); try { thread.join(); } catch (InterruptedException e) { assertTrue(false); } Long expected = 1000000l; Long observed = counter.filterValue(null).asLong().getLong(); assertEquals(expected, observed); }
/** * Verifies that require.value works on Long input. * * This is for bug fix commit: https://github.com/addthis/hydra/commit/60a1e46 */ @Test public void longInputStringValue() throws Exception { ValueFilterRequire filter = Configs.decodeObject(ValueFilterRequire.class, "value:[\"0\"]"); ValueObject result = filter.filter(ValueFactory.create(0)); assertNotNull(result); assertEquals(new Long(0), result.asLong().asNative()); } }
private void verifyOnePass() { bundle = source.next(); assertNotNull(bundle); assertEquals("a", getField("A").asString().asNative()); assertEquals(new Long(1), getField("B").asLong().asNative()); assertNotNull(bundle); bundle = source.next(); assertNotNull(bundle); assertEquals(Lists.newArrayList(new Long(1), new Long(2)), getField("C").asArray().asNative()); assertEquals(Lists.newArrayList("a", "b"), getField("D").asArray().asNative()); }
@Test public void sparseEncodeDecode() throws Exception { int size = 100; DataMap dataMap = new DataMap(size); long val = 1232432425l; dataMap.put("foo", ValueFactory.create(val)); byte[] bytes = dataMap.bytesEncode(PageEncodeType.SPARSE.ordinal()); DataMap decoded = new DataMap(); decoded.bytesDecode(bytes, PageEncodeType.SPARSE.ordinal()); ValueObject result = dataMap.getValue("foo"); assertEquals(val, result.asLong().getLong()); assertEquals(size, dataMap.getSize()); assertEquals(size, decoded.getSize()); }