@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)); }
@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; }
ValueFilterIndex extends AbstractValueFilterContextual { @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; } }
ValueFilterIndex extends AbstractValueFilterContextual { @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; }  }
ValueFilterIndex extends AbstractValueFilterContextual { @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; }  @Override ValueObject filter(ValueObject value, Bundle context); @Override ValueObject filterValue(ValueObject value, Bundle context); }
ValueFilterIndex extends AbstractValueFilterContextual { @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; }  @Override ValueObject filter(ValueObject value, Bundle context); @Override ValueObject filterValue(ValueObject value, Bundle context);  }