redouane59 / twittered

Twitter API client for Java developers
Apache License 2.0
234 stars 64 forks source link

FilteredStreamRulePredicate empty does not return true for isEmpty #433

Open snicoll opened 1 year ago

snicoll commented 1 year ago

I am initializing a predicate to empty to build a list of OR predicates.

I've noticed that applying or on such a predicate with anything leads to the following predicate:

 OR mypredicate

(notice the space before the OR).

I've tried to workaround this by creating the following method:

private static FilteredStreamRulePredicate or(FilteredStreamRulePredicate left, FilteredStreamRulePredicate right) {
    if (left == null || left.isEmpty()) {
        return right;
    }
    return left.or(right);
}

That turned out to not work as even if left is FilteredStreamRulePredicate.empty(), isEmpty returns false.

I am happy to contribute a PR. Besides contributing a fix for the isEmpty check, it would be nice to also fix the composition so that it doesn't apply an operator between two predicates if one of them is empty.

redouane59 commented 1 year ago

Hello,

Feel free to submit a pull request yes :) This feature was also added by a contributor a few months ago.