Skip to content

Commit

Permalink
Removed generics
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Feb 26, 2020
1 parent 974c36c commit 48e3930
Show file tree
Hide file tree
Showing 29 changed files with 176 additions and 160 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/fortuna/ical4j/filter/HasPropertyRule.java
Expand Up @@ -33,8 +33,8 @@

import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.Property;
import net.fortuna.ical4j.model.PropertyList;

import java.util.List;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ public HasPropertyRule(final Property property, final boolean matchEquals) {
*/
public final boolean test(final Component component) {
boolean match = false;
final PropertyList<Property> properties = component.getProperties(property.getName());
final List<Property> properties = component.getProperties(property.getName());
for (final Property p : properties) {
if (matchEquals && property.equals(p)) {
match = true;
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/net/fortuna/ical4j/model/Calendar.java
Expand Up @@ -47,6 +47,7 @@
import java.io.Serializable;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.List;

/**
* $Id$ [Apr 5, 2004]
Expand Down Expand Up @@ -134,7 +135,7 @@ public class Calendar implements Serializable {
*/
public static final String END = "END";

private final PropertyList<Property> properties;
private final PropertyList properties;

private final ComponentList<CalendarComponent> components;

Expand All @@ -144,23 +145,23 @@ public class Calendar implements Serializable {
* Default constructor.
*/
public Calendar() {
this(new PropertyList<Property>(), new ComponentList<CalendarComponent>());
this(new PropertyList(), new ComponentList<CalendarComponent>());
}

/**
* Constructs a new calendar with no properties and the specified components.
* @param components a list of components to add to the calendar
*/
public Calendar(final ComponentList<CalendarComponent> components) {
this(new PropertyList<Property>(), components);
this(new PropertyList(), components);
}

/**
* Initialise a Calendar object using the default configured validator.
* @param properties a list of initial calendar properties
* @param components a list of initial calendar components
*/
public Calendar(PropertyList<Property> properties, ComponentList<CalendarComponent> components) {
public Calendar(PropertyList properties, ComponentList<CalendarComponent> components) {
this(properties, components, AbstractCalendarValidatorFactory.getInstance().newInstance());
}

Expand All @@ -170,7 +171,7 @@ public Calendar(PropertyList<Property> properties, ComponentList<CalendarCompone
* @param c a list of components
* @param validator used to ensure the validity of the calendar instance
*/
public Calendar(PropertyList<Property> p, ComponentList<CalendarComponent> c, Validator<Calendar> validator) {
public Calendar(PropertyList p, ComponentList<CalendarComponent> c, Validator<Calendar> validator) {
this.properties = p;
this.components = c;
this.validator = validator;
Expand All @@ -186,7 +187,7 @@ public Calendar(PropertyList<Property> p, ComponentList<CalendarComponent> c, Va
public Calendar(Calendar c) throws ParseException, IOException,
URISyntaxException {

this(new PropertyList<Property>(c.getProperties()),
this(new PropertyList(c.getProperties()),
new ComponentList<CalendarComponent>(c.getComponents()));
}

Expand Down Expand Up @@ -234,7 +235,7 @@ public final CalendarComponent getComponent(final String name) {
/**
* @return Returns the properties.
*/
public final PropertyList<Property> getProperties() {
public final PropertyList getProperties() {
return properties;
}

Expand All @@ -243,7 +244,7 @@ public final PropertyList<Property> getProperties() {
* @param name name of properties to retrieve
* @return a property list containing only properties with the specified name
*/
public final PropertyList<Property> getProperties(final String name) {
public final List<Property> getProperties(final String name) {
return getProperties().getProperties(name);
}

Expand All @@ -253,7 +254,7 @@ public final PropertyList<Property> getProperties(final String name) {
* @return the first matching property in the property list with the specified name
*/
public final <T extends Property> T getProperty(final String name) {
return getProperties().getProperty(name);
return (T) getProperties().getProperty(name);
}

/**
Expand Down
45 changes: 23 additions & 22 deletions src/main/java/net/fortuna/ical4j/model/Component.java
Expand Up @@ -38,6 +38,7 @@
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 All @@ -55,7 +56,7 @@
*
* @author Ben Fortuna
*/
public abstract class Component<C extends Component> implements Serializable {
public abstract class Component implements Serializable {

private static final long serialVersionUID = 4943193483665822201L;

Expand Down Expand Up @@ -121,15 +122,15 @@ public abstract class Component<C extends Component> implements Serializable {

private String name;

private PropertyList<Property> properties;
private PropertyList properties;

/**
* Constructs a new component containing no properties.
*
* @param s a component name
*/
protected Component(final String s) {
this(s, new PropertyList<>());
this(s, new PropertyList());
}

/**
Expand All @@ -138,7 +139,7 @@ protected Component(final String s) {
* @param s component name
* @param p a list of properties
*/
protected Component(final String s, final PropertyList<Property> p) {
protected Component(final String s, final PropertyList p) {
this.name = s;
this.properties = p;
}
Expand Down Expand Up @@ -168,7 +169,7 @@ public final String getName() {
/**
* @return Returns the properties.
*/
public final PropertyList<Property> getProperties() {
public final PropertyList getProperties() {
return properties;
}

Expand All @@ -178,7 +179,7 @@ public final PropertyList<Property> getProperties() {
* @param name name of properties to retrieve
* @return a property list containing only properties with the specified name
*/
public final <T extends Property> PropertyList<T> getProperties(final String name) {
public final List<Property> getProperties(final String name) {
return getProperties().getProperties(name);
}

Expand All @@ -188,7 +189,7 @@ public final <T extends Property> PropertyList<T> getProperties(final String nam
* @param name name of the property to retrieve
* @return the first matching property in the property list with the specified name
*/
public final <T extends Property> T getProperty(final String name) {
public <T extends Property> T getProperty(final String name) {
return (T) getProperties().getProperty(name);
}

Expand All @@ -200,11 +201,11 @@ public final <T extends Property> T getProperty(final String name) {
* @throws ConstraintViolationException when a property is not found
*/
protected final <T extends Property> T getRequiredProperty(String name) throws ConstraintViolationException {
T p = getProperties().getProperty(name);
Property p = getProperties().getProperty(name);
if (p == null) {
throw new ConstraintViolationException(String.format("Missing %s property", name));
}
return p;
return (T) p;
}

/**
Expand Down Expand Up @@ -263,10 +264,10 @@ public int hashCode() {
* @throws ParseException where parsing component data fails
* @throws URISyntaxException where component data contains an invalid URI
*/
public C copy() throws ParseException, URISyntaxException {
public Component copy() throws ParseException, URISyntaxException, IOException {

// Deep copy properties..
final PropertyList<Property> newprops = new PropertyList<>(getProperties());
final PropertyList newprops = new PropertyList(getProperties());

return new ComponentFactoryImpl().createComponent(getName(),
newprops);
Expand Down Expand Up @@ -326,19 +327,19 @@ public final <T extends Temporal> List<Period<T>> calculateRecurrenceSet(final P
}

// add recurrence dates..
List<RDate<T>> rDates = getProperties(Property.RDATE);
List<Property> rDates = getProperties(Property.RDATE);
recurrenceSet.addAll(rDates.stream().filter(p -> p.getParameter(Parameter.VALUE) == Value.PERIOD)
.map(RDate::getPeriods).flatMap(List<Period<T>>::stream).filter(period::intersects)
.map(p -> ((RDate<T>) p).getPeriods()).flatMap(List<Period<T>>::stream).filter(period::intersects)
.collect(Collectors.toList()));

List<Period<T>> calculated = rDates.stream().filter(p -> p.getParameter(Parameter.VALUE) == Value.DATE_TIME)
.map(DateListProperty::getDates).map(DateList::getDates)
.map(p -> ((DateListProperty<T>) p).getDates()).map(DateList::getDates)
.flatMap(List<T>::stream).filter(period::includes)
.map(rdateTime -> new Period<>(rdateTime, rDuration)).collect(Collectors.toList());
recurrenceSet.addAll(calculated);

recurrenceSet.addAll(rDates.stream().filter(p -> p.getParameter(Parameter.VALUE) == Value.DATE)
.map(DateListProperty::getDates).map(DateList::getDates)
.map(p -> ((DateListProperty<T>) p).getDates()).map(DateList::getDates)
.flatMap(List<T>::stream).filter(period::includes)
.map(rdateDate -> new Period<>(rdateDate, rDuration)).collect(Collectors.toList()));

Expand All @@ -347,9 +348,9 @@ public final <T extends Temporal> List<Period<T>> calculateRecurrenceSet(final P
final T startMinusDuration = (T) period.getStart().minus(rDuration);

// add recurrence rules..
List<RRule> rRules = getProperties(Property.RRULE);
List<Property> rRules = getProperties(Property.RRULE);
if (!rRules.isEmpty()) {
recurrenceSet.addAll(rRules.stream().map(r -> r.getRecur().getDates(start.getDate(),
recurrenceSet.addAll(rRules.stream().map(r -> ((RRule) r).getRecur().getDates(start.getDate(),
startMinusDuration, period.getEnd())).flatMap(List<T>::stream)
.map(rruleDate -> new Period<T>(rruleDate, rDuration)).collect(Collectors.toList()));
} else {
Expand All @@ -374,15 +375,15 @@ public final <T extends Temporal> List<Period<T>> calculateRecurrenceSet(final P
}

// subtract exception dates..
List<ExDate> exDateProps = getProperties(Property.EXDATE);
List<Temporal> exDates = exDateProps.stream().map(DateListProperty::getDates).map(DateList::getDates).flatMap(List<Temporal>::stream)
.collect(Collectors.toList());
List<Property> exDateProps = getProperties(Property.EXDATE);
List<Temporal> exDates = exDateProps.stream().map(p -> ((DateListProperty<T>) p).getDates())
.map(DateList::getDates).flatMap(List<T>::stream).collect(Collectors.toList());

recurrenceSet.removeIf(recurrence -> exDates.contains(recurrence.getStart()));

// subtract exception rules..
List<ExRule> exRules = getProperties(Property.EXRULE);
List<Object> exRuleDates = exRules.stream().map(e -> e.getRecur().getDates(start.getDate(),
List<Property> exRules = getProperties(Property.EXRULE);
List<Object> exRuleDates = exRules.stream().map(e -> ((ExRule) e).getRecur().getDates(start.getDate(),
period)).flatMap(List<T>::stream).collect(Collectors.toList());

recurrenceSet.removeIf(recurrence -> exRuleDates.contains(recurrence.getStart()));
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/net/fortuna/ical4j/model/IndexedPropertyList.java
Expand Up @@ -45,21 +45,21 @@
*/
public class IndexedPropertyList {

private static final PropertyList<Property> EMPTY_LIST = new PropertyList<Property>();
private static final PropertyList EMPTY_LIST = new PropertyList();

private Map<String, PropertyList<Property>> index;
private Map<String, PropertyList> index;

/**
* Creates a new instance indexed on the parameters with the specified name.
* @param list a list of properties
* @param parameterName the name of parameters on which to index
*/
public IndexedPropertyList(final PropertyList<Property> list, final String parameterName) {
final Map<String, PropertyList<Property>> indexedProperties = new HashMap<String, PropertyList<Property>>();
public IndexedPropertyList(final PropertyList list, final String parameterName) {
final Map<String, PropertyList> indexedProperties = new HashMap<>();
list.forEach(property -> property.getParameters(parameterName).forEach(parameter -> {
PropertyList<Property> properties = indexedProperties.get(parameter.getValue());
PropertyList properties = indexedProperties.get(parameter.getValue());
if (properties == null) {
properties = new PropertyList<Property>();
properties = new PropertyList();
indexedProperties.put(parameter.getValue(), properties);
}
properties.add(property);
Expand All @@ -74,8 +74,8 @@ public IndexedPropertyList(final PropertyList<Property> list, final String param
* returned properties
* @return a property list
*/
public PropertyList<Property> getProperties(final String paramValue) {
PropertyList<Property> properties = index.get(paramValue);
public PropertyList getProperties(final String paramValue) {
PropertyList properties = index.get(paramValue);
if (properties == null) {
properties = EMPTY_LIST;
}
Expand All @@ -91,7 +91,7 @@ public PropertyList<Property> getProperties(final String paramValue) {
* with the specified value
*/
public Property getProperty(final String paramValue) {
final PropertyList<Property> properties = getProperties(paramValue);
final PropertyList properties = getProperties(paramValue);
if (!properties.isEmpty()) {
return properties.iterator().next();
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/fortuna/ical4j/model/Property.java
Expand Up @@ -361,15 +361,15 @@ public abstract class Property extends Content {

private final ParameterList parameters;

private final PropertyFactory<? extends Property> factory;
private final PropertyFactory<?> factory;

/**
* Constructor.
*
* @param aName property name
* @param factory the factory used to create the property instance
*/
protected Property(final String aName, PropertyFactory factory) {
protected Property(final String aName, PropertyFactory<?> factory) {
this(aName, new ParameterList(), factory);
}

Expand All @@ -387,7 +387,7 @@ protected Property(final String aName, PropertyFactory factory) {
* @param aList a list of initial parameters
* @param factory the factory used to create the property instance
*/
protected Property(final String aName, final ParameterList aList, PropertyFactory<? extends Property> factory) {
protected Property(final String aName, final ParameterList aList, PropertyFactory<?> factory) {
this.name = aName;
this.parameters = aList;
this.factory = factory;
Expand Down Expand Up @@ -517,16 +517,15 @@ public int hashCode() {
* Create a (deep) copy of this property.
*
* @return the copy of the property
* @throws IOException where an error occurs reading property data
* @throws URISyntaxException where the property contains an invalid URI value
* @throws ParseException where the property contains an invalid date value
*/
public <T extends Property> T copy() throws URISyntaxException, ParseException {
public Property copy() throws URISyntaxException, ParseException {
if (factory == null) {
throw new UnsupportedOperationException("No factory specified");
}
// Deep copy parameter list..
final ParameterList params = new ParameterList(getParameters(), false);
return (T) factory.createProperty(params, getValue());
return factory.createProperty(params, getValue());
}
}

0 comments on commit 48e3930

Please sign in to comment.