Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed signature of component and property collection interfaces to …
…avoid confusion with migration to v4.x
  • Loading branch information
benfortuna committed Jan 6, 2022
1 parent 776283f commit fe79ce9
Show file tree
Hide file tree
Showing 71 changed files with 256 additions and 239 deletions.
Expand Up @@ -236,7 +236,7 @@ public Calendar cancel(VEvent... component) {
@Override
public Calendar refresh(VEvent component) {
Calendar refresh = wrap(Method.REFRESH, component.copy());
// componentTransformers.get(Method.REFRESH).transform(refresh.getComponents().getAll());
// componentTransformers.get(Method.REFRESH).transform(refresh.getComponents());
refresh.validate();
return refresh;
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ public ParameterEqualToRule(Comparable<Parameter> comparable) {

@Override
public final boolean test(final Property property) {
for (Parameter p : property.getParameters().getAll()) {
for (Parameter p : property.getParameters()) {
if (comparable.compareTo(p) == 0) {
return true;
}
Expand Down
Expand Up @@ -55,7 +55,7 @@ public PropertyContainsRule(Property specification, String value) {
@Override
public boolean test(T t) {
// filter all props matching the spec and check value for substring match..
return t.getProperties().getAll().stream()
return t.getProperties().stream()
.filter(p -> new PropertyExistsRule.PropertyExists(specification).compareTo(p) == 0)
.anyMatch(prop -> prop.getValue().contains(value));
}
Expand Down
Expand Up @@ -58,6 +58,6 @@ public PropertyEqualToRule(Comparable<Property> comparable) {
*/
@Override
public final boolean test(final T component) {
return component.getProperties().getAll().stream().anyMatch(p -> comparable.compareTo(p) == 0);
return component.getProperties().stream().anyMatch(p -> comparable.compareTo(p) == 0);
}
}
Expand Up @@ -31,12 +31,10 @@
*/
package net.fortuna.ical4j.filter.predicate;

import net.fortuna.ical4j.model.ParameterList;
import net.fortuna.ical4j.model.Property;
import net.fortuna.ical4j.model.PropertyContainer;

import java.util.Comparator;
import java.util.function.Function;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -69,7 +67,7 @@ public PropertyExists(Property specification) {
@Override
public int compareTo(Property o) {
return Comparator.comparing(Property::getName)
.thenComparing((Function<Property, ParameterList>) Property::getParameters)
.thenComparing(Property::getParameterList)
.compare(specification, o);
}
}
Expand Down
Expand Up @@ -59,9 +59,9 @@ public PropertyGreaterThanRule(Comparable<Property> comparable, boolean inclusiv
@Override
public boolean test(T t) {
if (inclusive) {
return t.getProperties().getAll().stream().anyMatch(p -> comparable.compareTo(p) < 0);
return t.getProperties().stream().anyMatch(p -> comparable.compareTo(p) < 0);
} else {
return t.getProperties().getAll().stream().anyMatch(p -> comparable.compareTo(p) <= 0);
return t.getProperties().stream().anyMatch(p -> comparable.compareTo(p) <= 0);
}
}
}
Expand Up @@ -63,10 +63,10 @@ public PropertyInRangeRule(Comparable<Property> lowerBound, Comparable<Property>
@Override
public boolean test(T t) {
if (inclusive) {
return t.getProperties().getAll().stream()
return t.getProperties().stream()
.anyMatch(p -> lowerBound.compareTo(p) < 0 && upperBound.compareTo(p) > 0);
} else {
return t.getProperties().getAll().stream()
return t.getProperties().stream()
.anyMatch(p -> lowerBound.compareTo(p) <= 0 && upperBound.compareTo(p) >= 0);
}
}
Expand Down
Expand Up @@ -59,9 +59,9 @@ public PropertyLessThanRule(Comparable<Property> comparable, boolean inclusive)
@Override
public boolean test(T t) {
if (inclusive) {
return t.getProperties().getAll().stream().anyMatch(p -> comparable.compareTo(p) > 0);
return t.getProperties().stream().anyMatch(p -> comparable.compareTo(p) > 0);
} else {
return t.getProperties().getAll().stream().anyMatch(p -> comparable.compareTo(p) <= 0);
return t.getProperties().stream().anyMatch(p -> comparable.compareTo(p) <= 0);
}
}
}
Expand Up @@ -55,7 +55,7 @@ public PropertyMatchesRule(Property specification, String pattern) {
@Override
public boolean test(T t) {
// filter all props matching the spec and apply regex pattern matching..
return t.getProperties().getAll().stream()
return t.getProperties().stream()
.filter(p -> new PropertyExistsRule.PropertyExists(specification).compareTo(p) == 0)
.anyMatch(prop -> prop.getValue().matches(pattern));
}
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/net/fortuna/ical4j/model/Calendar.java
Expand Up @@ -197,6 +197,10 @@ public final String toString() {
Strings.LINE_SEPARATOR;
}

public <C extends CalendarComponent> List<C> getComponents() {
return ComponentContainer.super.getComponents();
}

/**
* @return Returns the components.
* @deprecated to avoid confusion with how to mutate a ComponentList from v4.x onwards this method is temporarily
Expand All @@ -207,15 +211,19 @@ public final String toString() {
*/
@Deprecated
@Override
public final ComponentList<CalendarComponent> getComponents() {
public final ComponentList<CalendarComponent> getComponentList() {
return components;
}

@Override
public void setComponents(ComponentList<CalendarComponent> components) {
public void setComponentList(ComponentList<CalendarComponent> components) {
this.components = components;
}

public <T extends Property> List<T> getProperties() {
return PropertyContainer.super.getProperties();
}

/**
* @return Returns the properties.
* @deprecated to avoid confusion with how to mutate a PropertyList from v4.x onwards this method is temporarily
Expand All @@ -227,7 +235,7 @@ public void setComponents(ComponentList<CalendarComponent> components) {
*/
@Deprecated
@Override
public final PropertyList getProperties() {
public final PropertyList getPropertyList() {
return properties;
}

Expand Down Expand Up @@ -302,8 +310,8 @@ public final Calendar copy() {
public Calendar merge(final Calendar c2) {
List<Property> mergedProperties = new ArrayList<>();
List<CalendarComponent> mergedComponents = new ArrayList<>();
mergedProperties.addAll(getProperties().getAll());
for (final Property p : c2.getProperties().getAll()) {
mergedProperties.addAll(getProperties());
for (final Property p : c2.getProperties()) {
if (!mergedProperties.contains(p)) {
mergedProperties.add(p);
}
Expand Down Expand Up @@ -345,12 +353,12 @@ public Calendar[] split() {
Calendar uidCal = calendars.get(uid.get());
if (uidCal == null) {
// remove METHOD property for split calendars..
PropertyList splitProps = (PropertyList) getProperties().removeAll(Property.METHOD);
PropertyList splitProps = (PropertyList) getPropertyList().removeAll(Property.METHOD);
uidCal = new Calendar(splitProps, new ComponentList<>());
calendars.put(uid.get(), uidCal);
}

for (final Property p : c.getProperties().getAll()) {
for (final Property p : c.getProperties()) {
final Optional<TzId> tzid = p.getParameter(Parameter.TZID);
if (tzid.isPresent()) {
final VTimeZone timezone = timezones.getComponent(tzid.get().getValue());
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/fortuna/ical4j/model/Component.java
Expand Up @@ -185,6 +185,10 @@ public String getValue() {
return properties.toString();
}

public <T extends Property> List<T> getProperties() {
return PropertyContainer.super.getProperties();
}

/**
* @return Returns the properties.
* @deprecated to avoid confusion with how to mutate a PropertyList from v4.x onwards this method is temporarily
Expand All @@ -196,7 +200,7 @@ public String getValue() {
*/
@Deprecated
@Override
public final PropertyList getProperties() {
public final PropertyList getPropertyList() {
return properties;
}

Expand Down Expand Up @@ -228,7 +232,7 @@ public final void validate() throws ValidationException {
* @throws ValidationException where any of the component properties is not in a valid state
*/
protected final void validateProperties() throws ValidationException {
for (final Property property : getProperties().getAll()) {
for (final Property property : getProperties()) {
property.validate();
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/net/fortuna/ical4j/model/ComponentContainer.java
Expand Up @@ -5,16 +5,16 @@

public interface ComponentContainer<T extends Component> {

ComponentList<T> getComponents();
ComponentList<T> getComponentList();

void setComponents(ComponentList<T> components);
void setComponentList(ComponentList<T> components);

default <C extends T> List<C> getComponents(final String... name) {
return getComponents().get(name);
return getComponentList().get(name);
}

default <C extends T> Optional<C> getComponent(final String name) {
return getComponents().getFirst(name);
return getComponentList().getFirst(name);
}

/**
Expand All @@ -23,7 +23,7 @@ default <C extends T> Optional<C> getComponent(final String name) {
* @return a reference to this component to support method chaining
*/
default ComponentContainer<T> add(T component) {
setComponents((ComponentList<T>) getComponents().add(component));
setComponentList((ComponentList<T>) getComponentList().add(component));
return this;
}

Expand All @@ -33,7 +33,7 @@ default ComponentContainer<T> add(T component) {
* @return a reference to this component to support method chaining
*/
default ComponentContainer<T> remove(T component) {
setComponents((ComponentList<T>) getComponents().remove(component));
setComponentList((ComponentList<T>) getComponentList().remove(component));
return this;
}

Expand All @@ -43,7 +43,7 @@ default ComponentContainer<T> remove(T component) {
* @return a reference to the component to support method chaining
*/
default ComponentContainer<T> replace(T component) {
setComponents((ComponentList<T>) getComponents().replace(component));
setComponentList((ComponentList<T>) getComponentList().replace(component));
return this;
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/ComponentList.java
Expand Up @@ -136,7 +136,7 @@ public final <R extends T> Optional<R> getComponent(final String aName) {
* @deprecated use {@link ComponentList#get(String)}
*/
@Deprecated
public final <C extends T> List<C> getComponents(final String name) {
public final <C extends T> List<C> getComponents(final String... name) {
return get(name);
}

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/fortuna/ical4j/model/ContentCollection.java
Expand Up @@ -29,10 +29,20 @@ public interface ContentCollection<T extends Content> extends Serializable {

List<T> getAll();

/**
* Return a list of elements filtered by name. If no names are specified return all elements.
* @param names a list of zero or more names to match
* @param <R> content type
* @return a list of elements less than or equal to the elements in this collection
*/
@SuppressWarnings("unchecked")
default <R extends T> List<R> get(String... names) {
List<String> filter = Arrays.asList(names);
return getAll().stream().filter(c -> filter.contains(c.getName())).map(c -> (R) c).collect(Collectors.toList());
if (names.length > 0) {
List<String> filter = Arrays.stream(names).map(String::toUpperCase).collect(Collectors.toList());
return getAll().stream().filter(c -> filter.contains(c.getName())).map(c -> (R) c).collect(Collectors.toList());
} else {
return (List<R>) getAll();
}
}

@SuppressWarnings("unchecked")
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/net/fortuna/ical4j/model/Property.java
Expand Up @@ -44,7 +44,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

/**
* Defines an iCalendar property. Subclasses of this class provide additional validation and typed values for specific
Expand Down Expand Up @@ -477,7 +476,7 @@ public final String getName() {
* @see Property#replace(Parameter)
*/
@Deprecated
public final ParameterList getParameters() {
public final ParameterList getParameterList() {
return parameters;
}

Expand Down Expand Up @@ -536,7 +535,7 @@ public <T extends Property> T replace(Parameter parameter) {
* @return a parameter list containing only parameters with the specified name
*/
public final List<Parameter> getParameters(final String... name) {
return getParameters().get(name);
return getParameterList().get(name);
}

/**
Expand All @@ -546,7 +545,7 @@ public final List<Parameter> getParameters(final String... name) {
* @return the first parameter from the parameter list with the specified name
*/
public final <P extends Parameter> Optional<P> getParameter(final String name) {
return getParameters().getFirst(name);
return getParameterList().getFirst(name);
}

/**
Expand All @@ -556,7 +555,7 @@ public final <P extends Parameter> Optional<P> getParameter(final String name) {
* @return
*/
public final <P extends Parameter> P getRequiredParameter(final String name) {
return getParameters().getRequired(name);
return getParameterList().getRequired(name);
}

/**
Expand All @@ -583,8 +582,8 @@ public final boolean equals(final Object arg0) {
if (arg0 instanceof Property) {
final Property p = (Property) arg0;
return getName().equals(p.getName())
&& new EqualsBuilder().append(getValue(), p.getValue()).append(getParameters(),
p.getParameters()).isEquals();
&& new EqualsBuilder().append(getValue(), p.getValue()).append(getParameterList(),
p.getParameterList()).isEquals();
}
return super.equals(arg0);
}
Expand All @@ -596,7 +595,7 @@ && new EqualsBuilder().append(getValue(), p.getValue()).append(getParameters(),
public int hashCode() {
// as property name is case-insensitive generate hash for uppercase..
return new HashCodeBuilder().append(getName().toUpperCase()).append(
getValue()).append(getParameters()).toHashCode();
getValue()).append(getParameterList()).toHashCode();
}

/**
Expand All @@ -621,7 +620,7 @@ public int compareTo(Property o) {
}
return Comparator.comparing(Property::getName)
.thenComparing(Property::getValue)
.thenComparing((Function<Property, ParameterList>) Property::getParameters)
.thenComparing(Property::getParameterList)
.compare(this, o);
}
}

0 comments on commit fe79ce9

Please sign in to comment.