Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make filter object of any type, not only String #540

Closed
davideas opened this issue Feb 13, 2018 · 1 comment
Closed

Make filter object of any type, not only String #540

davideas opened this issue Feb 13, 2018 · 1 comment
Milestone

Comments

@davideas
Copy link
Owner

davideas commented Feb 13, 2018

Reason of the improvement

Give the possibility to apply a multi filter simultaneously on more fields.

Impact

It will have an impact on IFilterable signature, so the filter() method can accept a custom type.
New methods will substitute the current when managing the filter:

Old methods New methods
setSearchText(String) => setFilter(Serializable)
String getSearchText() => Serializable getFilter()
boolean hasSearchText() => boolean hasFilter()
`boolean hasNewSearchText(String) => boolean hasNewFilter(Serializable)

If filter object is of type String, automatic trim and lowercase is maintained when setting it.
Must be of type Serializable in order to maintain save/restore instance state on configuration changes. String it is.

⚠️ Note: Old methods will be removed from next release.

@davideas davideas added this to the 5.0.0 milestone Feb 13, 2018
@davideas
Copy link
Owner Author

davideas commented Feb 13, 2018

Example with simple text:

public class ... extends ... implements IFilterable<String> {
    @Override
    public boolean filter(String constraint) {
        return getTitle() != null && getTitle().toLowerCase().trim().contains(constraint);
    }
}

Example with custom type (multi filter)

It's your choice to implement an inclusive (any match) or exclusive (all match) filter, here an exclusive example is shown:

public class ... extends ... implements IFilterable<MyFilter> {
    @Override
    public boolean filter(MyFilter constraint) {
        boolean result = true;
        if (constraint.isElectricCarSet()) {
            result = this.electric == constraint.isElectric());
        }
        if (result && constraint.isPriceSet()) {
            result = this.price <= constraint.getPrice());
        }
        return result;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant