@Test public void testBundleFilterFirst() throws IOException { BundleFilterFirstValue bff = Configs.decodeObject( BundleFilterFirstValue.class, "{op:\"first\", in:[\"a\", \"b\", \"c\", \"d\"], " + "out:\"out\"}"); MapBundle b1 = MapBundle.createBundle(new String[]{ "a", "123", "b", "234", "c", "345", "d", "456" }); assertTrue(bff.filter(b1)); assertEquals("123", b1.get("out")); b1 = MapBundle.createBundle(new String[]{ "a", "", "b", "234", "c", "345", "d", "456" }); assertTrue(bff.filter(b1)); assertEquals("234", b1.get("out")); b1 = MapBundle.createBundle(new String[]{ "a", null, "b", "", "c", "345", "d", "456" }); assertTrue(bff.filter(b1)); assertEquals("345", b1.get("out")); ValueArray array = ValueFactory.createArray(0); b1.setValue(b1.getFormat().getField("b"), array); assertTrue(bff.filter(b1)); assertEquals("345", b1.get("out")); array = ValueFactory.createArray(1); array.add(ValueFactory.create("foo")); b1.setValue(b1.getFormat().getField("b"), array); assertTrue(bff.filter(b1)); assertTrue(!b1.get("out").equals("345")); }
@Override public boolean filter(Bundle bundle) { for (int i = 0; i < in.length; i++) { ValueObject v = in[i].getValue(bundle); if (v == null) { continue; } switch (v.getObjectType()) { case ARRAY: ValueArray arr = v.asArray(); if (arr.size() > 0) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, arr); return true; } break; default: String str = ValueUtil.asNativeString(v); if (!LessStrings.isEmpty(str)) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, v); return true; } break; } } return false; }
BundleFilterFirstValue implements BundleFilter { @Override public boolean filter(Bundle bundle) { for (int i = 0; i < in.length; i++) { ValueObject v = in[i].getValue(bundle); if (v == null) { continue; } switch (v.getObjectType()) { case ARRAY: ValueArray arr = v.asArray(); if (arr.size() > 0) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, arr); return true; } break; default: String str = ValueUtil.asNativeString(v); if (!LessStrings.isEmpty(str)) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, v); return true; } break; } } return false; } }
BundleFilterFirstValue implements BundleFilter { @Override public boolean filter(Bundle bundle) { for (int i = 0; i < in.length; i++) { ValueObject v = in[i].getValue(bundle); if (v == null) { continue; } switch (v.getObjectType()) { case ARRAY: ValueArray arr = v.asArray(); if (arr.size() > 0) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, arr); return true; } break; default: String str = ValueUtil.asNativeString(v); if (!LessStrings.isEmpty(str)) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, v); return true; } break; } } return false; }  }
BundleFilterFirstValue implements BundleFilter { @Override public boolean filter(Bundle bundle) { for (int i = 0; i < in.length; i++) { ValueObject v = in[i].getValue(bundle); if (v == null) { continue; } switch (v.getObjectType()) { case ARRAY: ValueArray arr = v.asArray(); if (arr.size() > 0) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, arr); return true; } break; default: String str = ValueUtil.asNativeString(v); if (!LessStrings.isEmpty(str)) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, v); return true; } break; } } return false; }  @Override boolean filter(Bundle bundle); }
BundleFilterFirstValue implements BundleFilter { @Override public boolean filter(Bundle bundle) { for (int i = 0; i < in.length; i++) { ValueObject v = in[i].getValue(bundle); if (v == null) { continue; } switch (v.getObjectType()) { case ARRAY: ValueArray arr = v.asArray(); if (arr.size() > 0) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, arr); return true; } break; default: String str = ValueUtil.asNativeString(v); if (!LessStrings.isEmpty(str)) { if (which != null) { ValueObject fieldName = ValueFactory.create(in[i].name); which.setValue(bundle, fieldName); } out.setValue(bundle, v); return true; } break; } } return false; }  @Override boolean filter(Bundle bundle);  }