Skip to content

Commit

Permalink
Fix filter to support any collection in collecton expression
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Mar 5, 2023
1 parent 9269241 commit f26d856
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/net/fortuna/ical4j/filter/AbstractFilter.java
Expand Up @@ -44,6 +44,7 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.Collection;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -122,7 +123,7 @@ protected Property property(BinaryExpression expression) {
*/
protected List<Comparable<Property>> properties(BinaryExpression expression) {
FilterTarget operand = target(expression);
List<String> literal = literal(expression);
Collection<String> literal = literal(expression);
return literal.stream().map(l -> property(operand, l)).collect(Collectors.toList());
}

Expand Down Expand Up @@ -198,7 +199,7 @@ protected Parameter parameter(BinaryExpression expression) {
protected List<Comparable<Parameter>> parameters(BinaryExpression expression) {
// only applicable for operand expressions..
FilterTarget specification = target(expression);
List<String> literal = literal(expression);
Collection<String> literal = literal(expression);
return literal.stream().map(l -> parameter(specification.getName(), l)).collect(Collectors.toList());
}

Expand Down
@@ -1,8 +1,10 @@
package net.fortuna.ical4j.filter

import net.fortuna.ical4j.model.ContentBuilder
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.property.Attendee
import net.fortuna.ical4j.model.property.Organizer
import net.fortuna.ical4j.model.property.Summary
import spock.lang.Ignore
import spock.lang.Shared
import spock.lang.Specification
Expand All @@ -18,10 +20,14 @@ class ComponentFilterTest extends Specification {
@Shared
Attendee attendee

@Shared
Summary summary

def setupSpec() {
builder = new ContentBuilder()
organiser = builder.organizer('Mailto:B@example.com')
attendee = builder.attendee('Mailto:A@example.com')
summary = builder.summary('Test')
}

def 'test filter expression equals'() {
Expand Down Expand Up @@ -149,4 +155,19 @@ class ComponentFilterTest extends Specification {
'request-status not exists' | true
'sequence > 1' | true
}

def 'test filter expressions with sets'() {
given: 'a filter expression using sets'
def filter = FilterExpression.in(Property.SUMMARY, ['Test'] as Set)

and: 'an event'
def event = builder.vevent {
organizer(organiser)
attendee(attendee)
summary(summary)
}

expect: 'filter matches the event'
new ComponentFilter().predicate(filter).test(event)
}
}

0 comments on commit f26d856

Please sign in to comment.