From 2d3c430061e15cd708701611a8ef459c7217bbdd Mon Sep 17 00:00:00 2001 From: Ben Fortuna Date: Sun, 1 Aug 2021 14:49:33 +1000 Subject: [PATCH] Refactoring filter predicates --- .../ical4j/filter/DateInRangeRule.java | 66 --------------- .../ical4j/filter/ParameterEqualToRule.java | 70 ---------------- .../ical4j/filter/PropertyEqualToRule.java | 82 ------------------- .../fortuna/ical4j/filter/PropertyInRule.java | 28 ------- .../filter/predicate/DateInRangeRule.java | 42 ++++++++++ .../predicate/ParameterEqualToRule.java | 46 +++++++++++ .../filter/predicate/ParameterExistsRule.java | 34 ++++++++ .../filter/{ => predicate}/PeriodRule.java | 38 ++------- .../{ => predicate}/PropertyContainsRule.java | 14 +++- .../filter/predicate/PropertyEqualToRule.java | 58 +++++++++++++ .../{ => predicate}/PropertyExistsRule.java | 14 +++- .../PropertyGreaterThanRule.java | 14 +++- .../filter/predicate/PropertyInRule.java | 36 ++++++++ .../{ => predicate}/PropertyLessThanRule.java | 14 +++- .../filter/predicate/PropertyMatchesRule.java | 43 ++++++++++ .../fortuna/ical4j/model/ComponentGroup.java | 4 +- 16 files changed, 312 insertions(+), 291 deletions(-) delete mode 100644 src/main/java/net/fortuna/ical4j/filter/DateInRangeRule.java delete mode 100644 src/main/java/net/fortuna/ical4j/filter/ParameterEqualToRule.java delete mode 100644 src/main/java/net/fortuna/ical4j/filter/PropertyEqualToRule.java delete mode 100644 src/main/java/net/fortuna/ical4j/filter/PropertyInRule.java create mode 100644 src/main/java/net/fortuna/ical4j/filter/predicate/DateInRangeRule.java create mode 100644 src/main/java/net/fortuna/ical4j/filter/predicate/ParameterEqualToRule.java create mode 100644 src/main/java/net/fortuna/ical4j/filter/predicate/ParameterExistsRule.java rename src/main/java/net/fortuna/ical4j/filter/{ => predicate}/PeriodRule.java (50%) rename src/main/java/net/fortuna/ical4j/filter/{ => predicate}/PropertyContainsRule.java (56%) create mode 100644 src/main/java/net/fortuna/ical4j/filter/predicate/PropertyEqualToRule.java rename src/main/java/net/fortuna/ical4j/filter/{ => predicate}/PropertyExistsRule.java (54%) rename src/main/java/net/fortuna/ical4j/filter/{ => predicate}/PropertyGreaterThanRule.java (64%) create mode 100644 src/main/java/net/fortuna/ical4j/filter/predicate/PropertyInRule.java rename src/main/java/net/fortuna/ical4j/filter/{ => predicate}/PropertyLessThanRule.java (73%) create mode 100644 src/main/java/net/fortuna/ical4j/filter/predicate/PropertyMatchesRule.java diff --git a/src/main/java/net/fortuna/ical4j/filter/DateInRangeRule.java b/src/main/java/net/fortuna/ical4j/filter/DateInRangeRule.java deleted file mode 100644 index c90479415..000000000 --- a/src/main/java/net/fortuna/ical4j/filter/DateInRangeRule.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2012, Ben Fortuna - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * o Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * o Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * o Neither the name of Ben Fortuna nor the names of any other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.fortuna.ical4j.filter; - -import net.fortuna.ical4j.model.DateRange; - -import java.util.Date; -import java.util.function.Predicate; - -/** - * @author fortuna - * - */ -public class DateInRangeRule implements Predicate { - - private final DateRange range; - - private final int inclusiveMask; - - /** - * @param range the range to check - * @param inclusiveMask indicates inclusiveness of start and end of the range - */ - public DateInRangeRule(DateRange range, int inclusiveMask) { - this.range = range; - this.inclusiveMask = inclusiveMask; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean test(Date date) { - return range.includes(date, inclusiveMask); - } - -} diff --git a/src/main/java/net/fortuna/ical4j/filter/ParameterEqualToRule.java b/src/main/java/net/fortuna/ical4j/filter/ParameterEqualToRule.java deleted file mode 100644 index 87023a389..000000000 --- a/src/main/java/net/fortuna/ical4j/filter/ParameterEqualToRule.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2012, Ben Fortuna - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * o Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * o Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * o Neither the name of Ben Fortuna nor the names of any other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.fortuna.ical4j.filter; - -import net.fortuna.ical4j.model.Parameter; -import net.fortuna.ical4j.model.ParameterList; -import net.fortuna.ical4j.model.Property; - -import java.util.function.Predicate; - -/** - * $Id$ - * - * Created on 5/02/2006 - * - * A rule that matches any component containing the specified property. Note that this rule ignores any parameters - * matching only on the value of the property. - * @author Ben Fortuna - */ -public class ParameterEqualToRule implements Predicate { - - private final String parameterName; - - private final Object value; - - public ParameterEqualToRule(String parameterName, Object value) { - this.parameterName = parameterName; - this.value = value; - } - - @Override - public final boolean test(final Property property) { - final ParameterList parameters = property.getParameters(parameterName); - for (final Parameter p : parameters) { - if (value.equals(p.getValue())) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/net/fortuna/ical4j/filter/PropertyEqualToRule.java b/src/main/java/net/fortuna/ical4j/filter/PropertyEqualToRule.java deleted file mode 100644 index 8e3e1c8af..000000000 --- a/src/main/java/net/fortuna/ical4j/filter/PropertyEqualToRule.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) 2012, Ben Fortuna - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * o Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * o Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * o Neither the name of Ben Fortuna nor the names of any other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.fortuna.ical4j.filter; - -import net.fortuna.ical4j.model.Component; -import net.fortuna.ical4j.model.Property; -import net.fortuna.ical4j.model.PropertyList; - -import java.util.function.Predicate; - -/** - * $Id$ - * - * Created on 5/02/2006 - * - * A rule that matches any component containing the specified property. Note that this rule ignores any parameters - * matching only on the value of the property. - * @author Ben Fortuna - */ -public class PropertyEqualToRule implements Predicate { - - private final String propertyName; - - private final Object value; - - /** - * Constructs a new instance with the specified property. Ignores any parameters matching only on the value of the - * property. - * @param property a property instance to check for - */ - public PropertyEqualToRule(final Property property) { - this(property.getName(), property.getValue()); - } - - public PropertyEqualToRule(String propertyName, Object value) { - this.propertyName = propertyName; - this.value = value; - } - - /** - * {@inheritDoc} - */ - @Override - public final boolean test(final T component) { - final PropertyList properties = component.getProperties(propertyName); - for (final Property p : properties) { - if (value.equals(p.getValue())) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/net/fortuna/ical4j/filter/PropertyInRule.java b/src/main/java/net/fortuna/ical4j/filter/PropertyInRule.java deleted file mode 100644 index b5905b125..000000000 --- a/src/main/java/net/fortuna/ical4j/filter/PropertyInRule.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.fortuna.ical4j.filter; - -import net.fortuna.ical4j.model.Component; - -import java.util.List; -import java.util.function.Predicate; - -/** - * Test for a property matching any values in the provided list. - * - * @param - */ -public class PropertyInRule implements Predicate { - - private final String propertyName; - - private final List value; - - public PropertyInRule(String propertyName, List value) { - this.propertyName = propertyName; - this.value = value; - } - - @Override - public boolean test(Component t) { - return value.stream().anyMatch(value -> new PropertyEqualToRule<>(propertyName, value).test(t)); - } -} diff --git a/src/main/java/net/fortuna/ical4j/filter/predicate/DateInRangeRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/DateInRangeRule.java new file mode 100644 index 000000000..19a919809 --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/DateInRangeRule.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012-2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ +package net.fortuna.ical4j.filter.predicate; + +import net.fortuna.ical4j.model.DateRange; + +import java.util.Date; +import java.util.function.Predicate; + +/** + * @author fortuna + * + */ +public class DateInRangeRule implements Predicate { + + private final DateRange range; + + private final int inclusiveMask; + + /** + * @param range the range to check + * @param inclusiveMask indicates inclusiveness of start and end of the range + */ + public DateInRangeRule(DateRange range, int inclusiveMask) { + this.range = range; + this.inclusiveMask = inclusiveMask; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean test(Date date) { + return range.includes(date, inclusiveMask); + } + +} diff --git a/src/main/java/net/fortuna/ical4j/filter/predicate/ParameterEqualToRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/ParameterEqualToRule.java new file mode 100644 index 000000000..fdb182227 --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/ParameterEqualToRule.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012-2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ +package net.fortuna.ical4j.filter.predicate; + +import net.fortuna.ical4j.model.Parameter; +import net.fortuna.ical4j.model.ParameterList; +import net.fortuna.ical4j.model.Property; + +import java.util.function.Predicate; + +/** + * $Id$ + * + * Created on 5/02/2006 + * + * A rule that matches any component containing the specified property. Note that this rule ignores any parameters + * matching only on the value of the property. + * @author Ben Fortuna + */ +public class ParameterEqualToRule implements Predicate { + + private final String parameterName; + + private final Object value; + + public ParameterEqualToRule(String parameterName, Object value) { + this.parameterName = parameterName; + this.value = value; + } + + @Override + public final boolean test(final Property property) { + final ParameterList parameters = property.getParameters(parameterName); + for (final Parameter p : parameters) { + if (value.equals(p.getValue())) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/net/fortuna/ical4j/filter/predicate/ParameterExistsRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/ParameterExistsRule.java new file mode 100644 index 000000000..5ad6f362d --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/ParameterExistsRule.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package net.fortuna.ical4j.filter.predicate; + +import net.fortuna.ical4j.model.Property; + +import java.util.function.Predicate; + +/** + * Test for a parameter matching the provided name. + */ +public class ParameterExistsRule implements Predicate { + + private final String parameterName; + + public ParameterExistsRule(String parameterName) { + this.parameterName = parameterName; + } + + @Override + public boolean test(Property t) { + String[] param = parameterName.split(":"); + if (param.length > 1) { + return new ParameterEqualToRule<>(param[0], param[1]).test(t); + } + return !t.getParameters(parameterName).isEmpty(); + } +} diff --git a/src/main/java/net/fortuna/ical4j/filter/PeriodRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PeriodRule.java similarity index 50% rename from src/main/java/net/fortuna/ical4j/filter/PeriodRule.java rename to src/main/java/net/fortuna/ical4j/filter/predicate/PeriodRule.java index abb737456..d6e61d0f8 100644 --- a/src/main/java/net/fortuna/ical4j/filter/PeriodRule.java +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PeriodRule.java @@ -1,35 +1,11 @@ -/** - * Copyright (c) 2012, Ben Fortuna - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * o Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * o Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * o Neither the name of Ben Fortuna nor the names of any other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * Copyright (c) 2012-2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. */ -package net.fortuna.ical4j.filter; +package net.fortuna.ical4j.filter.predicate; import net.fortuna.ical4j.model.Component; import net.fortuna.ical4j.model.Period; diff --git a/src/main/java/net/fortuna/ical4j/filter/PropertyContainsRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyContainsRule.java similarity index 56% rename from src/main/java/net/fortuna/ical4j/filter/PropertyContainsRule.java rename to src/main/java/net/fortuna/ical4j/filter/predicate/PropertyContainsRule.java index 21ca0ba5c..4550c9a6a 100644 --- a/src/main/java/net/fortuna/ical4j/filter/PropertyContainsRule.java +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyContainsRule.java @@ -1,7 +1,15 @@ -package net.fortuna.ical4j.filter; +/* + * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package net.fortuna.ical4j.filter.predicate; -import net.fortuna.ical4j.model.Component; import net.fortuna.ical4j.model.Property; +import net.fortuna.ical4j.model.PropertyContainer; import net.fortuna.ical4j.model.PropertyList; import java.util.function.Predicate; @@ -11,7 +19,7 @@ * * @param */ -public class PropertyContainsRule implements Predicate { +public class PropertyContainsRule implements Predicate { private final String propertyName; diff --git a/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyEqualToRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyEqualToRule.java new file mode 100644 index 000000000..ca56616e5 --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyEqualToRule.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012-2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ +package net.fortuna.ical4j.filter.predicate; + +import net.fortuna.ical4j.model.Property; +import net.fortuna.ical4j.model.PropertyContainer; +import net.fortuna.ical4j.model.PropertyList; + +import java.util.function.Predicate; + +/** + * $Id$ + * + * Created on 5/02/2006 + * + * A rule that matches any component containing the specified property. Note that this rule ignores any parameters + * matching only on the value of the property. + * @author Ben Fortuna + */ +public class PropertyEqualToRule implements Predicate { + + private final String propertyName; + + private final V value; + + /** + * Constructs a new instance with the specified property. Ignores any parameters matching only on the value of the + * property. + * @param property a property instance to check for + */ + public PropertyEqualToRule(final Property property) { + this(property.getName(), (V) property.getValue()); + } + + public PropertyEqualToRule(String propertyName, V value) { + this.propertyName = propertyName; + this.value = value; + } + + /** + * {@inheritDoc} + */ + @Override + public final boolean test(final T component) { + final PropertyList properties = component.getProperties(propertyName); + for (final Property p : properties) { + if (value.equals(p.getValue())) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/net/fortuna/ical4j/filter/PropertyExistsRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyExistsRule.java similarity index 54% rename from src/main/java/net/fortuna/ical4j/filter/PropertyExistsRule.java rename to src/main/java/net/fortuna/ical4j/filter/predicate/PropertyExistsRule.java index 2f93aabf5..d0ed6be17 100644 --- a/src/main/java/net/fortuna/ical4j/filter/PropertyExistsRule.java +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyExistsRule.java @@ -1,6 +1,14 @@ -package net.fortuna.ical4j.filter; +/* + * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package net.fortuna.ical4j.filter.predicate; -import net.fortuna.ical4j.model.Component; +import net.fortuna.ical4j.model.PropertyContainer; import java.util.function.Predicate; @@ -10,7 +18,7 @@ * * @param */ -public class PropertyExistsRule implements Predicate { +public class PropertyExistsRule implements Predicate { private final String propertyName; diff --git a/src/main/java/net/fortuna/ical4j/filter/PropertyGreaterThanRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyGreaterThanRule.java similarity index 64% rename from src/main/java/net/fortuna/ical4j/filter/PropertyGreaterThanRule.java rename to src/main/java/net/fortuna/ical4j/filter/predicate/PropertyGreaterThanRule.java index 70bbbe8f6..e5f423a8b 100644 --- a/src/main/java/net/fortuna/ical4j/filter/PropertyGreaterThanRule.java +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyGreaterThanRule.java @@ -1,6 +1,14 @@ -package net.fortuna.ical4j.filter; +/* + * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package net.fortuna.ical4j.filter.predicate; -import net.fortuna.ical4j.model.Component; +import net.fortuna.ical4j.model.PropertyContainer; import net.fortuna.ical4j.model.property.Sequence; import java.util.function.Predicate; @@ -10,7 +18,7 @@ * * @param */ -public class PropertyGreaterThanRule implements Predicate { +public class PropertyGreaterThanRule implements Predicate { private final String propertyName; diff --git a/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyInRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyInRule.java new file mode 100644 index 000000000..aa0dd3291 --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyInRule.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package net.fortuna.ical4j.filter.predicate; + +import net.fortuna.ical4j.model.PropertyContainer; + +import java.util.Collection; +import java.util.function.Predicate; + +/** + * Test for a property matching any values in the provided list. + * + * @param + */ +public class PropertyInRule implements Predicate { + + private final String propertyName; + + private final Collection value; + + public PropertyInRule(String propertyName, Collection value) { + this.propertyName = propertyName; + this.value = value; + } + + @Override + public boolean test(T t) { + return value.stream().anyMatch(value -> new PropertyEqualToRule<>(propertyName, value).test(t)); + } +} diff --git a/src/main/java/net/fortuna/ical4j/filter/PropertyLessThanRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyLessThanRule.java similarity index 73% rename from src/main/java/net/fortuna/ical4j/filter/PropertyLessThanRule.java rename to src/main/java/net/fortuna/ical4j/filter/predicate/PropertyLessThanRule.java index bcb891e62..40eb756ca 100644 --- a/src/main/java/net/fortuna/ical4j/filter/PropertyLessThanRule.java +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyLessThanRule.java @@ -1,6 +1,14 @@ -package net.fortuna.ical4j.filter; +/* + * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package net.fortuna.ical4j.filter.predicate; -import net.fortuna.ical4j.model.Component; +import net.fortuna.ical4j.model.PropertyContainer; import net.fortuna.ical4j.model.property.DateProperty; import net.fortuna.ical4j.model.property.Sequence; @@ -15,7 +23,7 @@ * * @param */ -public class PropertyLessThanRule implements Predicate { +public class PropertyLessThanRule implements Predicate { private final String propertyName; diff --git a/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyMatchesRule.java b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyMatchesRule.java new file mode 100644 index 000000000..b7c39c4cd --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/filter/predicate/PropertyMatchesRule.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package net.fortuna.ical4j.filter.predicate; + +import net.fortuna.ical4j.model.Property; +import net.fortuna.ical4j.model.PropertyContainer; +import net.fortuna.ical4j.model.PropertyList; + +import java.util.function.Predicate; + +/** + * Test for a property that "matches" the provided regular expression. + * + * @param + */ +public class PropertyMatchesRule implements Predicate { + + private final String propertyName; + + private final Object value; + + public PropertyMatchesRule(String propertyName, Object value) { + this.propertyName = propertyName; + this.value = value; + } + + @Override + public boolean test(T t) { + final PropertyList properties = t.getProperties(propertyName); + for (final Property p : properties) { + if (p.getValue().matches(value.toString())) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/net/fortuna/ical4j/model/ComponentGroup.java b/src/main/java/net/fortuna/ical4j/model/ComponentGroup.java index 569341938..1f4048446 100644 --- a/src/main/java/net/fortuna/ical4j/model/ComponentGroup.java +++ b/src/main/java/net/fortuna/ical4j/model/ComponentGroup.java @@ -1,6 +1,6 @@ package net.fortuna.ical4j.model; -import net.fortuna.ical4j.filter.PropertyEqualToRule; +import net.fortuna.ical4j.filter.predicate.PropertyEqualToRule; import net.fortuna.ical4j.model.property.RecurrenceId; import net.fortuna.ical4j.model.property.Uid; @@ -44,7 +44,7 @@ public ComponentGroup(ComponentList components, Uid uid, RecurrenceId recurre this.components = components; if (recurrenceId != null) { - componentPredicate = new PropertyEqualToRule(uid).and(new PropertyEqualToRule<>(recurrenceId)); + componentPredicate = new PropertyEqualToRule(uid).and(new PropertyEqualToRule<>(recurrenceId)); } else { componentPredicate = new PropertyEqualToRule<>(uid); }