Skip to content

Commit

Permalink
Replace commons predicate with java8 predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Apr 20, 2018
1 parent bd0054e commit 47a92de
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/fortuna/ical4j/filter/DateInRangeRule.java
Expand Up @@ -32,9 +32,9 @@
package net.fortuna.ical4j.filter;

import net.fortuna.ical4j.model.DateRange;
import org.apache.commons.collections4.Predicate;

import java.util.Date;
import java.util.function.Predicate;

/**
* @author fortuna
Expand All @@ -58,7 +58,7 @@ public DateInRangeRule(DateRange range, int inclusiveMask) {
/**
* {@inheritDoc}
*/
public boolean evaluate(Date date) {
public boolean test(Date date) {
return range.includes(date, inclusiveMask);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/fortuna/ical4j/filter/Filter.java
Expand Up @@ -31,7 +31,6 @@
*/
package net.fortuna.ical4j.filter;

import org.apache.commons.collections4.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -40,6 +39,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;

/**
* $Id$
Expand Down Expand Up @@ -123,7 +123,7 @@ private List<T> matchAll(Collection<T> c) {
List<T> temp = new ArrayList<T>();
for (int n = 0; n < getRules().length; n++) {
for (final T o : list) {
if (getRules()[n].evaluate(o)) {
if (getRules()[n].test(o)) {
temp.add(o);
}
}
Expand All @@ -137,7 +137,7 @@ private List<T> matchAny(Collection<T> c) {
final List<T> matches = new ArrayList<T>();
for (T o : c) {
for (int n = 0; n < getRules().length; n++) {
if (getRules()[n].evaluate(o)) {
if (getRules()[n].test(o)) {
matches.add(o);
break;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/fortuna/ical4j/filter/HasPropertyRule.java
Expand Up @@ -34,7 +34,8 @@
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.Property;
import net.fortuna.ical4j.model.PropertyList;
import org.apache.commons.collections4.Predicate;

import java.util.function.Predicate;

/**
* $Id$
Expand Down Expand Up @@ -74,7 +75,7 @@ public HasPropertyRule(final Property property, final boolean matchEquals) {
/**
* {@inheritDoc}
*/
public final boolean evaluate(final Component component) {
public final boolean test(final Component component) {
boolean match = false;
final PropertyList<Property> properties = component.getProperties(property.getName());
for (final Property p : properties) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/fortuna/ical4j/filter/PeriodRule.java
Expand Up @@ -34,7 +34,8 @@
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.Period;
import net.fortuna.ical4j.model.PeriodList;
import org.apache.commons.collections4.Predicate;

import java.util.function.Predicate;

/**
* $Id$
Expand All @@ -59,7 +60,7 @@ public PeriodRule(final Period period) {
/**
* {@inheritDoc}
*/
public final boolean evaluate(final Component component) {
public final boolean test(final Component component) {

/*
DtStart start = (DtStart) component.getProperty(Property.DTSTART);
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/fortuna/ical4j/model/ComponentGroup.java
Expand Up @@ -4,10 +4,9 @@
import net.fortuna.ical4j.filter.HasPropertyRule;
import net.fortuna.ical4j.model.property.RecurrenceId;
import net.fortuna.ical4j.model.property.Uid;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.PredicateUtils;

import java.util.Collections;
import java.util.function.Predicate;

/**
* Support for operations applicable to a group of components. Typically this class is used to manage
Expand Down Expand Up @@ -37,8 +36,7 @@ public ComponentGroup(ComponentList<T> components, Uid uid, RecurrenceId recurre

Predicate<T> componentPredicate;
if (recurrenceId != null) {
componentPredicate = PredicateUtils.andPredicate(new HasPropertyRule<T>(uid),
new HasPropertyRule<T>(recurrenceId));
componentPredicate = new HasPropertyRule<T>(uid).and(new HasPropertyRule<T>(recurrenceId));
} else {
componentPredicate = new HasPropertyRule<T>(uid);
}
Expand Down
Expand Up @@ -6,8 +6,6 @@
import net.fortuna.ical4j.model.component.CalendarComponent;
import net.fortuna.ical4j.model.property.*;
import net.fortuna.ical4j.util.CompatibilityHints;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -53,12 +51,7 @@ public void validate(Calendar target) throws ValidationException {

// validate properties..
for (final Property property : target.getProperties()) {
boolean isCalendarProperty = CollectionUtils.find(calendarProperties, new Predicate<Class<? extends Property>>() {
@Override
public boolean evaluate(Class<? extends Property> object) {
return object.isInstance(property);
}
}) != null;
boolean isCalendarProperty = calendarProperties.stream().filter(calProp -> calProp.isInstance(property)) != null;

if (!(property instanceof XProperty) && !isCalendarProperty) {
throw new ValidationException("Invalid property: " + property.getName());
Expand Down
Expand Up @@ -35,7 +35,7 @@ class HasPropertyRuleTest extends Specification {
}

expect: 'a property rule matches when applied'
rule.evaluate(event)
rule.test(event)

where:
rule << [new HasPropertyRule<VEvent>(organiser), new HasPropertyRule<VEvent>(attendee)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/fortuna/ical4j/filter/FilterTest.java
Expand Up @@ -40,13 +40,13 @@
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.property.Attendee;
import net.fortuna.ical4j.model.property.Organizer;
import org.apache.commons.collections4.Predicate;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.function.Predicate;

/**
* $Id$
Expand Down

0 comments on commit 47a92de

Please sign in to comment.