@Test public void unique() throws IOException { BundleFilterAppend bfa = Configs.decodeObject(BundleFilterAppend.class, "from: F, to: T, unique: true"); Bundle bundle = Bundles.decode("T: C, F: [A, B, C]"); bfa.filter(bundle); Bundle targetBundle = Bundles.decode("T: [C, A, B], F: [A, B, C]"); assertTrue(Bundles.equals(bundle, targetBundle)); }
@Override public boolean filter(Bundle bundle) { ValueObject toVal = to.getValue(bundle); ValueArray arr = null; if (toVal == null) { if (nullFail) { return false; } arr = ValueFactory.createArray(size); } else { if (toVal.getObjectType() == ValueObject.TYPE.ARRAY) { arr = toVal.asArray(); } else { arr = ValueUtil.asArray(toVal); } } if (values != null) { for (String value : values) { ValueString str = ValueFactory.create(value); if (!unique || !arr.contains(str)) { arr.add(str); } } } if (from != null) { ValueObject fromVal = from.getValue(bundle); if (filter != null) { fromVal = filter.filter(fromVal, bundle); } if (fromVal != null) { if (fromVal.getObjectType() == ValueObject.TYPE.ARRAY) { for (ValueObject element : fromVal.asArray()) { if (!unique || !arr.contains(element)) { arr.add(element); } } } else if (!unique || !arr.contains(fromVal)) { arr.add(fromVal); } } } to.setValue(bundle, arr); return true; }
BundleFilterAppend implements BundleFilter { @Override public boolean filter(Bundle bundle) { ValueObject toVal = to.getValue(bundle); ValueArray arr = null; if (toVal == null) { if (nullFail) { return false; } arr = ValueFactory.createArray(size); } else { if (toVal.getObjectType() == ValueObject.TYPE.ARRAY) { arr = toVal.asArray(); } else { arr = ValueUtil.asArray(toVal); } } if (values != null) { for (String value : values) { ValueString str = ValueFactory.create(value); if (!unique || !arr.contains(str)) { arr.add(str); } } } if (from != null) { ValueObject fromVal = from.getValue(bundle); if (filter != null) { fromVal = filter.filter(fromVal, bundle); } if (fromVal != null) { if (fromVal.getObjectType() == ValueObject.TYPE.ARRAY) { for (ValueObject element : fromVal.asArray()) { if (!unique || !arr.contains(element)) { arr.add(element); } } } else if (!unique || !arr.contains(fromVal)) { arr.add(fromVal); } } } to.setValue(bundle, arr); return true; } }
BundleFilterAppend implements BundleFilter { @Override public boolean filter(Bundle bundle) { ValueObject toVal = to.getValue(bundle); ValueArray arr = null; if (toVal == null) { if (nullFail) { return false; } arr = ValueFactory.createArray(size); } else { if (toVal.getObjectType() == ValueObject.TYPE.ARRAY) { arr = toVal.asArray(); } else { arr = ValueUtil.asArray(toVal); } } if (values != null) { for (String value : values) { ValueString str = ValueFactory.create(value); if (!unique || !arr.contains(str)) { arr.add(str); } } } if (from != null) { ValueObject fromVal = from.getValue(bundle); if (filter != null) { fromVal = filter.filter(fromVal, bundle); } if (fromVal != null) { if (fromVal.getObjectType() == ValueObject.TYPE.ARRAY) { for (ValueObject element : fromVal.asArray()) { if (!unique || !arr.contains(element)) { arr.add(element); } } } else if (!unique || !arr.contains(fromVal)) { arr.add(fromVal); } } } to.setValue(bundle, arr); return true; }  }
BundleFilterAppend implements BundleFilter { @Override public boolean filter(Bundle bundle) { ValueObject toVal = to.getValue(bundle); ValueArray arr = null; if (toVal == null) { if (nullFail) { return false; } arr = ValueFactory.createArray(size); } else { if (toVal.getObjectType() == ValueObject.TYPE.ARRAY) { arr = toVal.asArray(); } else { arr = ValueUtil.asArray(toVal); } } if (values != null) { for (String value : values) { ValueString str = ValueFactory.create(value); if (!unique || !arr.contains(str)) { arr.add(str); } } } if (from != null) { ValueObject fromVal = from.getValue(bundle); if (filter != null) { fromVal = filter.filter(fromVal, bundle); } if (fromVal != null) { if (fromVal.getObjectType() == ValueObject.TYPE.ARRAY) { for (ValueObject element : fromVal.asArray()) { if (!unique || !arr.contains(element)) { arr.add(element); } } } else if (!unique || !arr.contains(fromVal)) { arr.add(fromVal); } } } to.setValue(bundle, arr); return true; }  @JsonIgnore BundleFilterAppend setValues(ArrayList<String> values); @JsonIgnore BundleFilterAppend setValues(HashSet<String> values); BundleFilterAppend setToField(AutoField field); BundleFilterAppend setFilter(ValueFilter filter); BundleFilterAppend setNullFail(boolean nullFail); BundleFilterAppend setSize(int size); @Override boolean filter(Bundle bundle); }
BundleFilterAppend implements BundleFilter { @Override public boolean filter(Bundle bundle) { ValueObject toVal = to.getValue(bundle); ValueArray arr = null; if (toVal == null) { if (nullFail) { return false; } arr = ValueFactory.createArray(size); } else { if (toVal.getObjectType() == ValueObject.TYPE.ARRAY) { arr = toVal.asArray(); } else { arr = ValueUtil.asArray(toVal); } } if (values != null) { for (String value : values) { ValueString str = ValueFactory.create(value); if (!unique || !arr.contains(str)) { arr.add(str); } } } if (from != null) { ValueObject fromVal = from.getValue(bundle); if (filter != null) { fromVal = filter.filter(fromVal, bundle); } if (fromVal != null) { if (fromVal.getObjectType() == ValueObject.TYPE.ARRAY) { for (ValueObject element : fromVal.asArray()) { if (!unique || !arr.contains(element)) { arr.add(element); } } } else if (!unique || !arr.contains(fromVal)) { arr.add(fromVal); } } } to.setValue(bundle, arr); return true; }  @JsonIgnore BundleFilterAppend setValues(ArrayList<String> values); @JsonIgnore BundleFilterAppend setValues(HashSet<String> values); BundleFilterAppend setToField(AutoField field); BundleFilterAppend setFilter(ValueFilter filter); BundleFilterAppend setNullFail(boolean nullFail); BundleFilterAppend setSize(int size); @Override boolean filter(Bundle bundle);  }