private String[] extractArray(ValueArray va) { int size = va.size(); String[] arr = new String[size]; for (int i = 0; i < size; i++) { arr[i] = va.get(i).toString(); } return arr; } }
@Override public boolean remove(Object o) { for (int i = 0; i < data.size(); i++) { ValueObject next = data.get(i); if ((next != null && next.equals(o)) || (next == null && o == null)) { data.remove(i); return true; } } return false; }
@Override public boolean remove(Object o) { for (int i = 0; i < data.size(); i++) { ValueObject next = data.get(i); if ((next != null && next.equals(o)) || (next == null && o == null)) { data.remove(i); return true; } } return false; }
@Override public boolean remove(Object o) { for (int i = 0; i < data.size(); i++) { ValueObject next = data.get(i); if ((next != null && next.equals(o)) || (next == null && o == null)) { data.remove(i); return true; } } return false; }
@Override public boolean remove(Object o) { for (int i = 0; i < data.size(); i++) { ValueObject next = data.get(i); if ((next != null && next.equals(o)) || (next == null && o == null)) { data.remove(i); return true; } } return false; }
@Override public Long get(int index) { ValueObject val = data.get(index); if (val == null) return null; return val.asLong().getLong(); }
@Override public String get(int index) { ValueObject val = data.get(index); if (val == null) return null; return val.asString().asNative(); }
@Override public byte[] get(int index) { ValueObject val = data.get(index); if (val == null) return null; return val.asBytes().asNative(); }
@Override public Double get(int index) { ValueObject val = data.get(index); if (val == null) return null; return val.asDouble().getDouble(); }
public ListBytes(ValueArray array, boolean copy) { if (copy) { int size = array.size(); this.data = ValueFactory.createArray(size); for (int i = 0; i < size; i++) { this.data.add(array.get(i)); } } else { this.data = array; } }
public ListLong(ValueArray array, boolean copy) { if (copy) { int size = array.size(); this.data = ValueFactory.createArray(size); for (int i = 0; i < size; i++) { this.data.add(array.get(i)); } } else { this.data = array; } }
public ListDouble(ValueArray array, boolean copy) { if (copy) { int size = array.size(); this.data = ValueFactory.createArray(size); for (int i = 0; i < size; i++) { this.data.add(data.get(i)); } } else { this.data = array; } }
public ListString(ValueArray array, boolean copy) { if (copy) { int size = array.size(); this.data = ValueFactory.createArray(size); for (int i = 0; i < size; i++) { this.data.add(array.get(i)); } } else { this.data = array; } }
@Override public ValueObject filter(ValueObject value, Bundle context) { ValueObject nullReturn = toNull ? null : value; if (ValueUtil.isEmpty(value)) { return nullReturn; } if (value.getObjectType() == ValueObject.TYPE.ARRAY) { ValueArray arr = value.asArray(); if (arr.isEmpty()) { return nullReturn; } int i = index.getInt(context).getAsInt(); while (i < 0) { i = arr.size() + i; } return (arr.size() > i) ? arr.get(i) : nullReturn; } return nullReturn; }
public MapStringListString(ValueMap map, boolean copy) { if (copy) { this.data = ValueFactory.createMap(); for (ValueMapEntry entry : map) { ValueArray array = entry.getValue().asArray(); int size = array.size(); ValueArray copyArray = ValueFactory.createArray(size); for (int i = 0; i < size; i++) { copyArray.add(array.get(i)); } this.data.put(entry.getKey(), copyArray); } } else { this.data = map; } }
@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 akamaiGroup() { ValueFilterRegex vf = new ValueFilterRegex().setPattern(Pattern.compile("Log_([0-9]+)\\.")); ValueObject res = vf.filter(ValueFactory.create("stream://san1.local:8614/split/logs/12345/2011/05/20/aLog_12345.esw3c_U.201105200000-0100-1.gz")); assertTrue(res != null); assertTrue(res.asArray().size() > 0); assertEquals("12345", res.asArray().get(0).asString().toString()); } }
@Test public void contextualIndex() throws IOException { ValueFilter valueFilter = decodeObject(ValueFilterIndex.class, "index.field = idx"); Bundle bundle = Bundles.decode("idx = 2"); ValueArray arr = ValueFactory.decodeValue("[a, b, c, d]").asArray(); assertEquals(valueFilter.filter(arr, bundle), arr.get(2)); }
@Test public void append() throws IOException { ValueFilterCreateMap vf = Configs.decodeObject(ValueFilterCreateMap.class, "appendValues=true"); ValueMap result = vf.filter(ValueFactory.create("hello=world,baz=quux,hello=bar,hello=world")).asMap(); ValueArray values = result.get("hello").asArray(); assertEquals(3, values.size()); assertEquals("world", values.get(0).asString().asNative()); assertEquals("bar", values.get(1).asString().asNative()); assertEquals("world", values.get(2).asString().asNative()); assertEquals("quux", result.get("baz").asString().asNative()); }
@Test public void filterLengthArray() { ValueFilterLength vfl = new ValueFilterLength(); ValueArray array = ValueFactory.createArray(0); assertEquals(null, vfl.filter(ValueFactory.createArray(0))); // prevent auto-filter iteration vfl.setOnce(true); assertEquals(ValueFactory.create(0), vfl.filter(array)); // add elements, try again array.add(ValueFactory.create("foo")); array.add(ValueFactory.create(5)); // there should be two elements assertEquals(ValueFactory.create(2), vfl.filter(array)); // disable once so each value is passed through the filter vfl.setOnce(false); array = (ValueArray) vfl.filter(array); assertEquals(ValueFactory.create(3), array.get(0)); // length of "foo" assertEquals(ValueFactory.create(5), array.get(1)); // length of the # 5 } }