Skip to content

Commit

Permalink
Simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Feb 27, 2020
1 parent adc21a4 commit 7b9b68e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 37 deletions.
2 changes: 0 additions & 2 deletions src/main/java/net/fortuna/ical4j/model/Calendar.java
Expand Up @@ -43,7 +43,6 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.IOException;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.text.ParseException;
Expand Down Expand Up @@ -180,7 +179,6 @@ public Calendar(PropertyList p, ComponentList<CalendarComponent> c, Validator<Ca
/**
* Creates a deep copy of the specified calendar.
* @param c the calendar to copy
* @throws IOException where an error occurs reading calendar data
* @throws ParseException where calendar parsing fails
* @throws URISyntaxException where an invalid URI string is encountered
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/ComponentGroup.java
Expand Up @@ -13,7 +13,7 @@

/**
* Support for operations applicable to a group of components. Typically this class is used to manage
* component revisions (whereby each revision is a separate component), and the resulting ouput of
* component revisions (whereby each revision is a separate component), and the resulting output of
* such group functions.
*
* Example - Find latest revision of an event:
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/fortuna/ical4j/model/PropertyList.java
Expand Up @@ -31,7 +31,6 @@
*/
package net.fortuna.ical4j.model;

import java.io.IOException;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.text.ParseException;
Expand Down Expand Up @@ -66,9 +65,6 @@ public PropertyList(final int initialCapacity) {
/**
* Creates a deep copy of the specified property list.
* @param properties a property list
* @throws ParseException where property data cannot be parsed
* @throws IOException where property data cannot be read
* @throws URISyntaxException where a property contains an invalid URI
*/

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -135,4 +131,8 @@ public final boolean add(final Property property) {
public final boolean remove(final Property property) {
return super.remove(property);
}

public void replaceAll(Property property) {
replaceAll(p -> p.getName().equals(property.getName()) ? property : p);
}
}
6 changes: 3 additions & 3 deletions src/main/java/net/fortuna/ical4j/model/TextList.java
Expand Up @@ -66,7 +66,7 @@ public TextList() {
* @param aValue a string representation of a list of categories
*/
public TextList(final String aValue) {
texts = new CopyOnWriteArrayList<String>();
texts = new CopyOnWriteArrayList<>();

final Pattern pattern = Pattern.compile("(?:\\\\.|[^\\\\,]++)+");

Expand All @@ -80,15 +80,15 @@ public TextList(final String aValue) {
/**
* @param textValues an array of text values
*/
public TextList(String[] textValues) {
public TextList(String...textValues) {
texts = Arrays.asList(textValues);
}

/**
* {@inheritDoc}
*/
public final String toString() {
return texts.stream().map(t -> Strings.escape(t)).collect(Collectors.joining(","));
return texts.stream().map(Strings::escape).collect(Collectors.joining(","));
}

/**
Expand Down
Expand Up @@ -124,20 +124,17 @@ public final void validate(final boolean recurse) throws ValidationException {
// From "4.8.3.3 Time Zone Offset From":
// Conformance: This property MUST be specified in a "VTIMEZONE"
// calendar component.
PropertyValidator.assertOne(Property.TZOFFSETFROM,
getProperties());
PropertyValidator.assertOne(Property.TZOFFSETFROM, getProperties());

// From "4.8.3.4 Time Zone Offset To":
// Conformance: This property MUST be specified in a "VTIMEZONE"
// calendar component.
PropertyValidator.assertOne(Property.TZOFFSETTO,
getProperties());
PropertyValidator.assertOne(Property.TZOFFSETTO, getProperties());

/*
* ; the following are each REQUIRED, ; but MUST NOT occur more than once dtstart / tzoffsetto / tzoffsetfrom /
*/
PropertyValidator.assertOne(Property.DTSTART,
getProperties());
PropertyValidator.assertOne(Property.DTSTART, getProperties());

/*
* ; the following are optional, ; and MAY occur more than once comment / rdate / rrule / tzname / x-prop
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/fortuna/ical4j/data/ConcurrencyTest.java
Expand Up @@ -94,7 +94,7 @@ public void run() {
try {
Calendar cal = new Calendar(calendar);
size.addAndGet(cal.getComponents().size());
} catch (IOException | ParseException | URISyntaxException e) {
} catch (ParseException | URISyntaxException e) {
e.printStackTrace();
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/net/fortuna/ical4j/filter/FilterTest.java
Expand Up @@ -146,24 +146,24 @@ public static TestSuite suite() throws FileNotFoundException, IOException, Parse

TestSuite suite = new TestSuite();
//testFilterMatchAll..
Filter<CalendarComponent> filter = new Filter<CalendarComponent>(new Predicate[] {organiserRuleMatch, attendee1RuleMatch}, Filter.MATCH_ALL);
suite.addTest(new FilterTest<CalendarComponent>("testFilteredSize", filter, calendar.getComponents(), 2));
Filter<CalendarComponent> filter = new Filter<>(new Predicate[] {organiserRuleMatch, attendee1RuleMatch}, Filter.MATCH_ALL);
suite.addTest(new FilterTest<>("testFilteredSize", filter, calendar.getComponents(), 2));

filter = new Filter<CalendarComponent>(new Predicate[] {organiserRuleNoMatch, attendee1RuleMatch}, Filter.MATCH_ALL);
suite.addTest(new FilterTest<CalendarComponent>("testFilteredIsEmpty", filter, calendar.getComponents()));
filter = new Filter<>(new Predicate[] {organiserRuleNoMatch, attendee1RuleMatch}, Filter.MATCH_ALL);
suite.addTest(new FilterTest<>("testFilteredIsEmpty", filter, calendar.getComponents()));

filter = new Filter<CalendarComponent>(new Predicate[] {organiserRuleMatch, attendeeRuleNoMatch}, Filter.MATCH_ALL);
suite.addTest(new FilterTest<CalendarComponent>("testFilteredIsEmpty", filter, calendar.getComponents()));
filter = new Filter<>(new Predicate[] {organiserRuleMatch, attendeeRuleNoMatch}, Filter.MATCH_ALL);
suite.addTest(new FilterTest<>("testFilteredIsEmpty", filter, calendar.getComponents()));

//testFilterMatchAny..
filter = new Filter<CalendarComponent>(new Predicate[] {organiserRuleMatch, attendee1RuleMatch}, Filter.MATCH_ANY);
suite.addTest(new FilterTest<CalendarComponent>("testFilteredSize", filter, calendar.getComponents(), 3));
filter = new Filter<>(new Predicate[] {organiserRuleMatch, attendee1RuleMatch}, Filter.MATCH_ANY);
suite.addTest(new FilterTest<>("testFilteredSize", filter, calendar.getComponents(), 3));

filter = new Filter<CalendarComponent>(new Predicate[] {organiserRuleNoMatch, attendee1RuleMatch}, Filter.MATCH_ANY);
suite.addTest(new FilterTest<CalendarComponent>("testFilteredSize", filter, calendar.getComponents(), 2));
filter = new Filter<>(new Predicate[] {organiserRuleNoMatch, attendee1RuleMatch}, Filter.MATCH_ANY);
suite.addTest(new FilterTest<>("testFilteredSize", filter, calendar.getComponents(), 2));

filter = new Filter<CalendarComponent>(new Predicate[] {organiserRuleMatch, attendeeRuleNoMatch}, Filter.MATCH_ANY);
suite.addTest(new FilterTest<CalendarComponent>("testFilteredSize", filter, calendar.getComponents(), 3));
filter = new Filter<>(new Predicate[] {organiserRuleMatch, attendeeRuleNoMatch}, Filter.MATCH_ANY);
suite.addTest(new FilterTest<>("testFilteredSize", filter, calendar.getComponents(), 3));
return suite;
}
}
4 changes: 2 additions & 2 deletions src/test/java/net/fortuna/ical4j/filter/PeriodRuleTest.java
Expand Up @@ -88,7 +88,7 @@ public PeriodRuleTest(String testMethod, Filter<CalendarComponent> filter,
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
protected void tearDown() {
CompatibilityHints.clearHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION);
}

Expand Down Expand Up @@ -128,7 +128,7 @@ public static TestSuite suite() throws FileNotFoundException, IOException, Parse
ZonedDateTime apr1 = ZonedDateTime.now().withYear(2004).withMonth(4).withDayOfMonth(1);
// period of two weeks..
Period<ZonedDateTime> period = new Period<>(apr1, java.time.Period.ofWeeks(2));
Filter<CalendarComponent> filter = new Filter<CalendarComponent>(new PeriodRule<>(period));
Filter<CalendarComponent> filter = new Filter<>(new PeriodRule<>(period));
// ComponentList filtered = (ComponentList) filter.filter(calendar.getComponents());
// assertTrue(!filtered.isEmpty());
suite.addTest(new PeriodRuleTest("testFilteredIsNotEmpty", filter, calendar.getComponents()));
Expand Down
Expand Up @@ -158,7 +158,7 @@ protected void tearDown() throws Exception {
* Class under test for void VFreeBusy(ComponentList)
*/
public final void testVFreeBusyComponentList() {
ComponentList<CalendarComponent> components = new ComponentList<CalendarComponent>();
ComponentList<CalendarComponent> components = new ComponentList<>();

ZonedDateTime startDate = ZonedDateTime.ofInstant(
Instant.ofEpochMilli(0), ZoneId.systemDefault());
Expand Down Expand Up @@ -218,8 +218,8 @@ public final void testVFreeBusyComponentList2() throws Exception {
}
}

public final void testVFreeBusyComponentList3() throws Exception {
ComponentList<CalendarComponent> components = new ComponentList<CalendarComponent>();
public final void testVFreeBusyComponentList3() {
ComponentList<CalendarComponent> components = new ComponentList<>();

ZonedDateTime eventStart = ZonedDateTime.ofInstant(
Instant.ofEpochMilli(0), ZoneId.systemDefault());
Expand Down Expand Up @@ -255,7 +255,7 @@ public final void testVFreeBusyComponentList3() throws Exception {
}

public final void testVFreeBusyComponentList4() {
ComponentList<CalendarComponent> components = new ComponentList<CalendarComponent>();
ComponentList<CalendarComponent> components = new ComponentList<>();

Instant startDate = Instant.now();
Instant endDate = ZonedDateTime.now().plusDays(3).toInstant();
Expand Down Expand Up @@ -402,7 +402,7 @@ public static TestSuite suite() throws ParseException, URISyntaxException,
// A test for a request for free time where the VFreeBusy instance doesn't
// consume any time in the specified range. Correct behaviour should see the
// return of a VFreeBusy specifying the entire range as free.
ComponentList<CalendarComponent> components = new ComponentList<CalendarComponent>();
ComponentList<CalendarComponent> components = new ComponentList<>();
VEvent event1 = new VEvent(TemporalAdapter.parse("20050101T080000").getTemporal(),
java.time.Duration.ofMinutes(15), "Consultation 1");
components.add(event1);
Expand All @@ -423,7 +423,7 @@ public static TestSuite suite() throws ParseException, URISyntaxException,
suite.addTest(new VFreeBusyTest("testFreeBusyPeriods", requestFree, components, periods));

//testBusyTime..
components = new ComponentList<CalendarComponent>();
components = new ComponentList<>();
event1 = new VEvent((Temporal) TemporalAdapter.parse("20050103T080000Z").getTemporal(),
java.time.Duration.ofHours(5), "Event 1");
Recur rRuleRecur = new Recur("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR");
Expand Down

0 comments on commit 7b9b68e

Please sign in to comment.