Skip to content

Commit

Permalink
Simplify lambda and other expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Apr 22, 2018
1 parent 15adcf2 commit 818d36b
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/ComponentGroup.java
Expand Up @@ -60,7 +60,7 @@ public ComponentList<T> getRevisions() {
*/
public T getLatestRevision() {
ComponentList<T> revisions = getRevisions();
Collections.sort(revisions, new ComponentSequenceComparator());
revisions.sort(new ComponentSequenceComparator());
Collections.reverse(revisions);
return revisions.iterator().next();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/DateList.java
Expand Up @@ -168,7 +168,7 @@ public DateList(final DateList list, final Value type) {
* {@inheritDoc}
*/
public final String toString() {
return stream().map(x -> x.toString()).collect(Collectors.joining(","));
return stream().map(Iso8601::toString).collect(Collectors.joining(","));
}

/**
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/net/fortuna/ical4j/model/IndexedPropertyList.java
Expand Up @@ -56,16 +56,14 @@ public class IndexedPropertyList {
*/
public IndexedPropertyList(final PropertyList<Property> list, final String parameterName) {
final Map<String, PropertyList<Property>> indexedProperties = new HashMap<String, PropertyList<Property>>();
list.forEach(property -> {
property.getParameters(parameterName).forEach(parameter -> {
PropertyList<Property> properties = indexedProperties.get(parameter.getValue());
if (properties == null) {
properties = new PropertyList<Property>();
indexedProperties.put(parameter.getValue(), properties);
}
properties.add(property);
});
});
list.forEach(property -> property.getParameters(parameterName).forEach(parameter -> {
PropertyList<Property> properties = indexedProperties.get(parameter.getValue());
if (properties == null) {
properties = new PropertyList<Property>();
indexedProperties.put(parameter.getValue(), properties);
}
properties.add(property);
}));
this.index = Collections.unmodifiableMap(indexedProperties);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/NumberList.java
Expand Up @@ -120,6 +120,6 @@ public final boolean add(final Integer aNumber) {
* {@inheritDoc}
*/
public final String toString() {
return stream().map(x -> x.toString()).collect(Collectors.joining(","));
return stream().map(Object::toString).collect(Collectors.joining(","));
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/PeriodList.java
Expand Up @@ -109,7 +109,7 @@ public PeriodList(final String aValue) throws ParseException {
* {@inheritDoc}
*/
public final String toString() {
return stream().map(x -> x.toString()).collect(Collectors.joining(","));
return stream().map(Period::toString).collect(Collectors.joining(","));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/fortuna/ical4j/model/PropertyList.java
Expand Up @@ -82,9 +82,7 @@ public PropertyList(PropertyList<? extends T> properties) throws ParseException,
*/
public final String toString() {
final StringBuilder sb = new StringBuilder();
forEach(t -> {
sb.append(t.toString());
});
forEach(t -> sb.append(t.toString()));
return sb.toString();
}

Expand Down
21 changes: 3 additions & 18 deletions src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java
Expand Up @@ -28,7 +28,6 @@
import java.time.zone.ZoneOffsetTransitionRule;
import java.util.*;
import java.util.TimeZone;
import java.util.function.Supplier;

public class TimeZoneLoader {

Expand Down Expand Up @@ -177,12 +176,7 @@ private static void addTransitionRules(ZoneId zoneId, int rawTimeZoneOffsetInSec

if (!zoneId.getRules().getTransitions().isEmpty()) {
Collections.min(zoneId.getRules().getTransitions(),
new Comparator<ZoneOffsetTransition>() {
@Override
public int compare(ZoneOffsetTransition z1, ZoneOffsetTransition z2) {
return z1.getDateTimeBefore().compareTo(z2.getDateTimeBefore());
}
});
Comparator.comparing(ZoneOffsetTransition::getDateTimeBefore));
}

LocalDateTime startDate = null;
Expand Down Expand Up @@ -250,11 +244,7 @@ private static void addTransitions(ZoneId zoneId, VTimeZone result, int rawTimeZ
for (ZoneOffsetTransition zoneTransitionRule : zoneId.getRules().getTransitions()) {
ZoneOffsetKey offfsetKey = ZoneOffsetKey.of(zoneTransitionRule.getOffsetBefore(), zoneTransitionRule.getOffsetAfter());

Set<ZoneOffsetTransition> transitionRulesForOffset = zoneTransitionsByOffsets.get(offfsetKey);
if (transitionRulesForOffset == null) {
transitionRulesForOffset = new HashSet<ZoneOffsetTransition>(1);
zoneTransitionsByOffsets.put(offfsetKey, transitionRulesForOffset);
}
Set<ZoneOffsetTransition> transitionRulesForOffset = zoneTransitionsByOffsets.computeIfAbsent(offfsetKey, k -> new HashSet<ZoneOffsetTransition>(1));
transitionRulesForOffset.add(zoneTransitionRule);
}

Expand Down Expand Up @@ -283,12 +273,7 @@ private static void addTransitions(ZoneId zoneId, VTimeZone result, int rawTimeZ

private static TimeZoneCache cacheInit() {
Optional<TimeZoneCache> property = Configurator.getObjectProperty(TZ_CACHE_IMPL);
return property.orElseGet(new Supplier<TimeZoneCache>() {
@Override
public TimeZoneCache get() {
return new JCacheTimeZoneCache();
}
});
return property.orElseGet(JCacheTimeZoneCache::new);
}

private static class ZoneOffsetKey {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/WeekDayList.java
Expand Up @@ -86,6 +86,6 @@ public WeekDayList(final String aString) {
* {@inheritDoc}
*/
public final String toString() {
return stream().map(x -> x.toString()).collect(Collectors.joining(","));
return stream().map(WeekDay::toString).collect(Collectors.joining(","));
}
}
Expand Up @@ -115,9 +115,7 @@ public final void validate(final boolean recurse)
/*
* ; dtstamp / dtstart / uid are required, but MUST NOT occur more than once /
*/
Arrays.asList(Property.DTSTART, Property.DTSTAMP, Property.UID).forEach(property -> {
PropertyValidator.getInstance().assertOne(property, getProperties());
});
Arrays.asList(Property.DTSTART, Property.DTSTAMP, Property.UID).forEach(property -> PropertyValidator.getInstance().assertOne(property, getProperties()));

/* If specified, the "DTSTART" and "DTEND" properties in
* "VAVAILABILITY" components and "AVAILABLE" sub-components MUST be
Expand All @@ -138,9 +136,7 @@ public final void validate(final boolean recurse)
* summary /
*/
Arrays.asList(Property.CREATED, Property.LAST_MODIFIED, Property.RECURRENCE_ID,
Property.RRULE, Property.SUMMARY).forEach(property -> {
PropertyValidator.getInstance().assertOneOrLess(property, getProperties());
});
Property.RRULE, Property.SUMMARY).forEach(property -> PropertyValidator.getInstance().assertOneOrLess(property, getProperties()));

/*
; either a 'dtend' or a 'duration' is required
Expand Down
Expand Up @@ -179,9 +179,7 @@ public final void validate(final boolean recurse)
/*
* ; dtstamp / dtstart / uid are required, but MUST NOT occur more than once /
*/
Arrays.asList(Property.DTSTART, Property.DTSTAMP, Property.UID).forEach(parameter -> {
PropertyValidator.getInstance().assertOne(parameter, getProperties());
});
Arrays.asList(Property.DTSTART, Property.DTSTAMP, Property.UID).forEach(parameter -> PropertyValidator.getInstance().assertOne(parameter, getProperties()));

/* If specified, the "DTSTART" and "DTEND" properties in
* "VAVAILABILITY" components and "AVAILABLE" sub-components MUST be
Expand Down Expand Up @@ -223,9 +221,7 @@ public final void validate(final boolean recurse)
* organizer / seq / summary / url /
*/
Arrays.asList(Property.BUSYTYPE, Property.CREATED, Property.LAST_MODIFIED,
Property.ORGANIZER, Property.SEQUENCE, Property.SUMMARY, Property.URL).forEach(property -> {
PropertyValidator.getInstance().assertOneOrLess(property, getProperties());
});
Property.ORGANIZER, Property.SEQUENCE, Property.SUMMARY, Property.URL).forEach(property -> PropertyValidator.getInstance().assertOneOrLess(property, getProperties()));

/*
* ; the following are optional, ; and MAY occur more than once
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/fortuna/ical4j/model/component/VEvent.java
Expand Up @@ -346,9 +346,7 @@ public final void validate(final boolean recurse) throws ValidationException {
Arrays.asList(Property.CLASS, Property.CREATED, Property.DESCRIPTION,
Property.DTSTART, Property.GEO, Property.LAST_MODIFIED, Property.LOCATION, Property.ORGANIZER,
Property.PRIORITY, Property.DTSTAMP, Property.SEQUENCE, Property.STATUS, Property.SUMMARY,
Property.TRANSP, Property.UID, Property.URL, Property.RECURRENCE_ID).forEach(property -> {
PropertyValidator.getInstance().assertOneOrLess(property, getProperties());
});
Property.TRANSP, Property.UID, Property.URL, Property.RECURRENCE_ID).forEach(property -> PropertyValidator.getInstance().assertOneOrLess(property, getProperties()));

final Status status = getProperty(Property.STATUS);
if (status != null && !Status.VEVENT_TENTATIVE.getValue().equals(status.getValue())
Expand Down
Expand Up @@ -500,9 +500,7 @@ public final void validate(final boolean recurse) throws ValidationException {
* dtstamp / organizer / uid / url /
*/
Arrays.asList(Property.CONTACT, Property.DTSTART, Property.DTEND, Property.DURATION,
Property.DTSTAMP, Property.ORGANIZER, Property.UID, Property.URL).forEach(parameter -> {
PropertyValidator.getInstance().assertOneOrLess(parameter, getProperties());
});
Property.DTSTAMP, Property.ORGANIZER, Property.UID, Property.URL).forEach(parameter -> PropertyValidator.getInstance().assertOneOrLess(parameter, getProperties()));

/*
* ; the following are optional, ; and MAY occur more than once attendee / comment / freebusy / rstatus / x-prop
Expand All @@ -513,9 +511,7 @@ public final void validate(final boolean recurse) throws ValidationException {
* calendar component. Any recurring events are resolved into their individual busy time periods using the
* "FREEBUSY" property.
*/
Arrays.asList(Property.RRULE, Property.EXRULE, Property.RDATE, Property.EXDATE).forEach(property -> {
PropertyValidator.getInstance().assertNone(property, getProperties());
});
Arrays.asList(Property.RRULE, Property.EXRULE, Property.RDATE, Property.EXDATE).forEach(property -> PropertyValidator.getInstance().assertNone(property, getProperties()));

// DtEnd value must be later in time that DtStart..
final DtStart dtStart = getProperty(Property.DTSTART);
Expand Down
Expand Up @@ -176,9 +176,7 @@ public final void validate(final boolean recurse)
*/
Arrays.asList(Property.CLASS, Property.CREATED, Property.DESCRIPTION, Property.DTSTART,
Property.DTSTAMP, Property.LAST_MODIFIED, Property.ORGANIZER, Property.RECURRENCE_ID, Property.SEQUENCE,
Property.STATUS, Property.SUMMARY, Property.UID, Property.URL).forEach(property -> {
PropertyValidator.getInstance().assertOneOrLess(property, getProperties());
});
Property.STATUS, Property.SUMMARY, Property.UID, Property.URL).forEach(property -> PropertyValidator.getInstance().assertOneOrLess(property, getProperties()));

final Status status = getProperty(Property.STATUS);
if (status != null && !Status.VJOURNAL_DRAFT.getValue().equals(status.getValue())
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/fortuna/ical4j/model/component/VToDo.java
Expand Up @@ -253,9 +253,7 @@ public final void validate(final boolean recurse)
Arrays.asList(Property.CLASS, Property.COMPLETED, Property.CREATED, Property.DESCRIPTION,
Property.DTSTAMP, Property.DTSTART, Property.GEO, Property.LAST_MODIFIED, Property.LOCATION, Property.ORGANIZER,
Property.PERCENT_COMPLETE, Property.PRIORITY, Property.RECURRENCE_ID, Property.SEQUENCE, Property.STATUS,
Property.SUMMARY, Property.UID, Property.URL).forEach(property -> {
PropertyValidator.getInstance().assertOneOrLess(property, getProperties());
});
Property.SUMMARY, Property.UID, Property.URL).forEach(property -> PropertyValidator.getInstance().assertOneOrLess(property, getProperties()));

final Status status = getProperty(Property.STATUS);
if (status != null && !Status.VTODO_NEEDS_ACTION.getValue().equals(status.getValue())
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/fortuna/ical4j/model/component/VVenue.java
Expand Up @@ -147,9 +147,7 @@ public final void validate(final boolean recurse)
*/
Arrays.asList(Property.NAME, Property.DESCRIPTION, Property.STREET_ADDRESS, Property.EXTENDED_ADDRESS,
Property.LOCALITY, Property.REGION, Property.COUNTRY, Property.POSTALCODE, Property.TZID, Property.GEO,
Property.LOCATION_TYPE, Property.CATEGORIES, Property.DTSTAMP, Property.CREATED, Property.LAST_MODIFIED).forEach(property -> {
PropertyValidator.getInstance().assertOneOrLess(property, getProperties());
});
Property.LOCATION_TYPE, Property.CATEGORIES, Property.DTSTAMP, Property.CREATED, Property.LAST_MODIFIED).forEach(property -> PropertyValidator.getInstance().assertOneOrLess(property, getProperties()));

/*
* ; the following is optional, ; and MAY occur more than once tel / url / x-prop
Expand Down
Expand Up @@ -121,9 +121,7 @@ public final void validate() throws ValidationException {
*/
Arrays.asList(Parameter.CUTYPE, Parameter.MEMBER, Parameter.ROLE, Parameter.PARTSTAT,
Parameter.RSVP, Parameter.DELEGATED_TO, Parameter.DELEGATED_FROM, Parameter.SENT_BY, Parameter.CN,
Parameter.DIR, Parameter.LANGUAGE).forEach(parameter -> {
ParameterValidator.getInstance().assertOneOrLess(parameter, getParameters());
});
Parameter.DIR, Parameter.LANGUAGE).forEach(parameter -> ParameterValidator.getInstance().assertOneOrLess(parameter, getParameters()));

/* scheduleagent and schedulestatus added for CalDAV scheduling
*/
Expand Down
Expand Up @@ -191,9 +191,7 @@ public final void validate() throws ValidationException {
* sentbyparam) / (";" languageparam) /
*/
Arrays.asList(Parameter.CN, Parameter.DIR, Parameter.SENT_BY,
Parameter.LANGUAGE).forEach(parameter -> {
ParameterValidator.getInstance().assertOneOrLess(parameter, getParameters());
});
Parameter.LANGUAGE).forEach(parameter -> ParameterValidator.getInstance().assertOneOrLess(parameter, getParameters()));

/* schedulestatus added for CalDAV scheduling
*/
Expand Down

0 comments on commit 818d36b

Please sign in to comment.