Skip to content

Commit

Permalink
Temporarily deprecate accessors to help migration to modified mutatio…
Browse files Browse the repository at this point in the history
…n strategy post v4.x
  • Loading branch information
benfortuna committed Jan 6, 2022
1 parent ee16708 commit 11cd8b8
Show file tree
Hide file tree
Showing 62 changed files with 286 additions and 185 deletions.
17 changes: 15 additions & 2 deletions src/main/java/net/fortuna/ical4j/model/Calendar.java
Expand Up @@ -199,7 +199,13 @@ public final String toString() {

/**
* @return Returns the components.
* @deprecated to avoid confusion with how to mutate a ComponentList from v4.x onwards this method is temporarily
* deprecated.
* @see ComponentContainer#add(Component)
* @see ComponentContainer#remove(Component)
* @see ComponentContainer#replace(Component)
*/
@Deprecated
@Override
public final ComponentList<CalendarComponent> getComponents() {
return components;
Expand All @@ -212,7 +218,14 @@ public void setComponents(ComponentList<CalendarComponent> components) {

/**
* @return Returns the properties.
* @deprecated to avoid confusion with how to mutate a PropertyList from v4.x onwards this method is temporarily
* deprecated.
* @see PropertyContainer#add(Property)
* @see PropertyContainer#remove(Property)
* @see PropertyContainer#removeAll(String...)
* @see PropertyContainer#replace(Property)
*/
@Deprecated
@Override
public final PropertyList getProperties() {
return properties;
Expand Down Expand Up @@ -313,7 +326,7 @@ public Calendar[] split() {
// if calendar contains one component or less, or is composed entirely of timezone
// definitions, return the original calendar unmodified..
if (getComponents().getAll().size() <= 1
|| getComponents().get(Component.VTIMEZONE).size() == getComponents().getAll().size()) {
|| getComponents(Component.VTIMEZONE).size() == getComponents().getAll().size()) {
return new Calendar[] {this};
}

Expand Down Expand Up @@ -361,7 +374,7 @@ public Calendar[] split() {
public Uid getUid() throws ConstraintViolationException {
Uid uid = null;
for (final Component c : getComponents().getAll()) {
for (final Property foundUid : c.getProperties().get(Property.UID)) {
for (final Property foundUid : c.getProperties(Property.UID)) {
if (uid != null && !uid.equals(foundUid)) {
throw new ConstraintViolationException("More than one UID found in calendar");
}
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/net/fortuna/ical4j/model/Component.java
Expand Up @@ -190,7 +190,14 @@ public String getValue() {

/**
* @return Returns the properties.
* @deprecated to avoid confusion with how to mutate a PropertyList from v4.x onwards this method is temporarily
* deprecated.
* @see PropertyContainer#add(Property)
* @see PropertyContainer#remove(Property)
* @see PropertyContainer#removeAll(String...)
* @see PropertyContainer#replace(Property)
*/
@Deprecated
@Override
public final PropertyList getProperties() {
return properties;
Expand All @@ -201,20 +208,6 @@ public void setProperties(PropertyList properties) {
this.properties = properties;
}

/**
* Convenience method for retrieving a required named property.
*
* @param name name of the property to retrieve
* @return the first matching property in the property list with the specified name
* @throws ConstraintViolationException when a property is not found
*
* @deprecated use {@link PropertyList#getRequired(String)}
*/
@Deprecated
public final <T extends Property> T getRequiredProperty(String name) throws ConstraintViolationException {
return properties.getRequired(name);
}

/**
* Perform validation on a component and its properties.
*
Expand Down
Expand Up @@ -9,7 +9,7 @@ public interface ComponentContainer<T extends Component> {

void setComponents(ComponentList<T> components);

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/ComponentGroup.java
Expand Up @@ -95,7 +95,7 @@ public <T extends Temporal> List<Period<T>> calculateRecurrenceSet(final Period<

List<Period<T>> finalPeriods = new ArrayList<>(periods);
overrides.forEach(component -> {
RecurrenceId<?> recurrenceId = component.getProperties().getRequired(Property.RECURRENCE_ID);
RecurrenceId<?> recurrenceId = component.getRequiredProperty(Property.RECURRENCE_ID);
finalPeriods.removeIf(p -> p.getStart().equals(recurrenceId.getDate()));
component.calculateRecurrenceSet(period).stream()
.filter(p -> p.getStart().equals(recurrenceId.getDate()))
Expand Down
Expand Up @@ -53,7 +53,7 @@ public class IndexedComponentList<T extends Component> {
public IndexedComponentList(final List<T> list, final String propertyName) {
final Map<String, List<T>> indexedComponents = new HashMap<>();
for (final T component : list) {
for (final Property property : component.getProperties().get(propertyName)) {
for (final Property property : component.getProperties(propertyName)) {
List<T> components = indexedComponents.computeIfAbsent(property.getValue(), k -> new ArrayList<>());
components.add(component);
}
Expand Down
Expand Up @@ -52,7 +52,7 @@ public class IndexedPropertyList {
*/
public IndexedPropertyList(final List<Property> list, final String parameterName) {
final Map<String, List<Property>> indexedProperties = new HashMap<>();
list.forEach(property -> property.getParameters().get(parameterName).forEach(parameter -> {
list.forEach(property -> property.getParameters(parameterName).forEach(parameter -> {
List<Property> properties = indexedProperties.computeIfAbsent(parameter.getValue(), k -> new ArrayList<>());
properties.add(property);
}));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/ParameterList.java
Expand Up @@ -136,7 +136,7 @@ public final <T extends Parameter> Optional<T> getParameter(final String aName)
* @param name name of parameters to return
* @return a parameter list
*
* @deprecated use {@link ParameterList#get(String)}
* @deprecated use {@link ParameterList#get(String...)}
*/
@Deprecated
public final ParameterList getParameters(final String name) {
Expand Down
30 changes: 20 additions & 10 deletions src/main/java/net/fortuna/ical4j/model/Property.java
Expand Up @@ -41,11 +41,10 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.Comparator;
import java.util.function.Function;
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 @@ -470,7 +469,14 @@ public final String getName() {

/**
* @return Returns the parameters.
* @deprecated to avoid confusion with how to mutate a {@link ParameterList} from v4.x onwards this method is temporarily
* deprecated.
* @see Property#add(Parameter)
* @see Property#remove(Parameter)
* @see Property#removeAll(String...)
* @see Property#replace(Parameter)
*/
@Deprecated
public final ParameterList getParameters() {
return parameters;
}
Expand Down Expand Up @@ -507,7 +513,7 @@ public <T extends Property> T remove(Parameter parameter) {
* @return a reference to the property to support method chaining
*/
@SuppressWarnings("unchecked")
public <T extends Property> T removeAll(String parameterName) {
public <T extends Property> T removeAll(String... parameterName) {
setParameters((ParameterList) parameters.removeAll(parameterName));
return (T) this;
}
Expand All @@ -528,11 +534,8 @@ public <T extends Property> T replace(Parameter parameter) {
*
* @param name name of parameters to retrieve
* @return a parameter list containing only parameters with the specified name
*
* @deprecated use {@link ParameterList#get(String)}
*/
@Deprecated
public final List<Parameter> getParameters(final String name) {
public final List<Parameter> getParameters(final String... name) {
return getParameters().get(name);
}

Expand All @@ -541,14 +544,21 @@ public final List<Parameter> getParameters(final String name) {
*
* @param name name of the parameter to retrieve
* @return the first parameter from the parameter list with the specified name
*
* @deprecated use {@link ParameterList#getFirst(String)}
*/
@Deprecated
public final <P extends Parameter> Optional<P> getParameter(final String name) {
return getParameters().getFirst(name);
}

/**
* Retrieve a single required parameter.
* @param name
* @param <P>
* @return
*/
public final <P extends Parameter> P getRequiredParameter(final String name) {
return getParameters().getRequired(name);
}

/**
* Sets the current value of the property.
*
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/net/fortuna/ical4j/model/PropertyContainer.java
Expand Up @@ -9,14 +9,25 @@ public interface PropertyContainer {

void setProperties(PropertyList properties);

default <T extends Property> List<T> getProperties(final String name) {
default <T extends Property> List<T> getProperties(final String... name) {
return getProperties().get(name);
}

default <T extends Property> Optional<T> getProperty(final String name) {
return getProperties().getFirst(name);
}

/**
* Convenience method for retrieving a required named property.
*
* @param name name of the property to retrieve
* @return the first matching property in the property list with the specified name
* @throws ConstraintViolationException when a property is not found
*/
default <T extends Property> T getRequiredProperty(String name) throws ConstraintViolationException {
return getProperties().getRequired(name);
}

/**
* Add a property to the container.
* @param property the property to add
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/PropertyList.java
Expand Up @@ -133,7 +133,7 @@ public final <T extends Property> Optional<T> getProperty(final String aName) {
* @param name name of properties to return
* @return a property list
*
* @deprecated use {@link PropertyList#get(String)}
* @deprecated use {@link PropertyList#get(String...)}
*/
@Deprecated
public final List<Property> getProperties(final String name) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/fortuna/ical4j/model/TimeZone.java
Expand Up @@ -103,7 +103,7 @@ public final int getOffset(final int era, final int year, final int month, final
OffsetDateTime date = OffsetDateTime.of(year, month + 1, dayOfMonth, hour, minute, second, ms * 1000, ZoneOffset.ofTotalSeconds(getRawOffset() / 1000));
final Observance observance = vTimeZone.getApplicableObservance(date);
if (observance != null) {
final TzOffsetTo offset = observance.getProperties().getRequired(Property.TZOFFSETTO);
final TzOffsetTo offset = observance.getRequiredProperty(Property.TZOFFSETTO);
return (int) (offset.getOffset().getTotalSeconds() * 1000L);
}
return 0;
Expand All @@ -116,7 +116,7 @@ public final int getOffset(final int era, final int year, final int month, final
public int getOffset(long date) {
final Observance observance = vTimeZone.getApplicableObservance(Instant.ofEpochMilli(date));
if (observance != null) {
final TzOffsetTo offset = observance.getProperties().getRequired(Property.TZOFFSETTO);
final TzOffsetTo offset = observance.getRequiredProperty(Property.TZOFFSETTO);
if ((offset.getOffset().getTotalSeconds() * 1000L) < getRawOffset()) {
return getRawOffset();
} else {
Expand Down Expand Up @@ -162,7 +162,7 @@ public final void setRawOffset(final int offsetMillis) {
*/
@Override
public final boolean useDaylightTime() {
final List<Observance> daylights = vTimeZone.getObservances().get(Observance.DAYLIGHT);
final List<Observance> daylights = vTimeZone.getComponents(Observance.DAYLIGHT);
return (!daylights.isEmpty());
}

Expand All @@ -175,10 +175,10 @@ public final VTimeZone getVTimeZone() {

private static int getRawOffset(VTimeZone vt) {

List<Observance> seasonalTimes = vt.getObservances().get(Observance.STANDARD);
List<Observance> seasonalTimes = vt.getComponents(Observance.STANDARD);
// if no standard time use daylight time..
if (seasonalTimes.isEmpty()) {
seasonalTimes = vt.getObservances().get(Observance.DAYLIGHT);
seasonalTimes = vt.getComponents(Observance.DAYLIGHT);
if (seasonalTimes.isEmpty()) {
return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/net/fortuna/ical4j/model/ZoneRulesBuilder.java
Expand Up @@ -32,7 +32,7 @@ private List<ZoneOffsetTransition> buildTransitions(List<Observance> observances
for (Observance observance : observances) {
// ignore transitions that have no effect..
Optional<TzOffsetFrom> offsetFrom = observance.getProperties().getFirst(Property.TZOFFSETFROM);
TzOffsetTo offsetTo = observance.getProperties().getRequired(Property.TZOFFSETTO);
TzOffsetTo offsetTo = observance.getRequiredProperty(Property.TZOFFSETTO);

if (offsetFrom.isPresent() && !offsetFrom.get().getOffset().equals(offsetTo.getOffset())) {
Optional<DtStart<LocalDateTime>> startDate = observance.getProperties().getFirst(Property.DTSTART);
Expand All @@ -51,9 +51,9 @@ private Set<ZoneOffsetTransitionRule> buildTransitionRules(List<Observance> obse
Set<ZoneOffsetTransitionRule> transitionRules = new HashSet<>();
for (Observance observance : observances) {
Optional<RRule<?>> rrule = observance.getProperties().getFirst(Property.RRULE);
TzOffsetFrom offsetFrom = observance.getProperties().getRequired(Property.TZOFFSETFROM);
TzOffsetTo offsetTo = observance.getProperties().getRequired(Property.TZOFFSETTO);
DtStart<LocalDateTime> startDate = observance.getProperties().getRequired(Property.DTSTART);
TzOffsetFrom offsetFrom = observance.getRequiredProperty(Property.TZOFFSETFROM);
TzOffsetTo offsetTo = observance.getRequiredProperty(Property.TZOFFSETTO);
DtStart<LocalDateTime> startDate = observance.getRequiredProperty(Property.DTSTART);

// ignore invalid rules
if (rrule.isPresent() && !rrule.get().getRecur().getMonthList().isEmpty()) {
Expand All @@ -75,24 +75,24 @@ private Set<ZoneOffsetTransitionRule> buildTransitionRules(List<Observance> obse

public ZoneRules build() throws ConstraintViolationException {
Observance current = VTimeZone.getApplicableObservance(Instant.now(),
vTimeZone.getObservances().get(Observance.STANDARD));
vTimeZone.getComponents(Observance.STANDARD));

// if no standard time use daylight time..
if (current == null) {
current = VTimeZone.getApplicableObservance(Instant.now(),
vTimeZone.getObservances().get(Observance.DAYLIGHT));
vTimeZone.getComponents(Observance.DAYLIGHT));
}

TzOffsetFrom offsetFrom = current.getProperties().getRequired(Property.TZOFFSETFROM);
TzOffsetTo offsetTo = current.getProperties().getRequired(Property.TZOFFSETTO);
TzOffsetFrom offsetFrom = current.getRequiredProperty(Property.TZOFFSETFROM);
TzOffsetTo offsetTo = current.getRequiredProperty(Property.TZOFFSETTO);

ZoneOffset standardOffset = offsetTo.getOffset();
ZoneOffset wallOffset = offsetFrom.getOffset();
List<ZoneOffsetTransition> standardOffsetTransitions = buildTransitions(
vTimeZone.getObservances().get(Observance.STANDARD));
vTimeZone.getComponents(Observance.STANDARD));
Collections.sort(standardOffsetTransitions);
List<ZoneOffsetTransition> offsetTransitions = buildTransitions(
vTimeZone.getObservances().get(Observance.DAYLIGHT));
vTimeZone.getComponents(Observance.DAYLIGHT));
Collections.sort(offsetTransitions);
Set<ZoneOffsetTransitionRule> transitionRules = buildTransitionRules(
vTimeZone.getObservances().getAll(), standardOffset);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/fortuna/ical4j/model/component/Observance.java
Expand Up @@ -146,9 +146,9 @@ public final OffsetDateTime getLatestOnset(final Temporal date) {
throw new UnsupportedOperationException("Unable to get timezone observance for date-only temporal.");
}

TzOffsetTo offsetTo = getProperties().getRequired(TZOFFSETTO);
TzOffsetTo offsetTo = getRequiredProperty(TZOFFSETTO);

TzOffsetFrom offsetFrom = getProperties().getRequired(TZOFFSETFROM);
TzOffsetFrom offsetFrom = getRequiredProperty(TZOFFSETFROM);

OffsetDateTime offsetDate = LocalDateTime.ofInstant(Instant.from(date), ZoneOffset.UTC).atOffset(
offsetTo.getOffset());
Expand All @@ -159,7 +159,7 @@ public final OffsetDateTime getLatestOnset(final Temporal date) {

if (initialOnset == null) {
try {
DtStart<?> dtStart = getProperties().getRequired(DTSTART);
DtStart<?> dtStart = getRequiredProperty(DTSTART);
if (dtStart.getDate().isSupported(ChronoField.HOUR_OF_DAY)) {
initialOnset = LocalDateTime.from(dtStart.getDate()).atOffset(offsetFrom.getOffset());
} else {
Expand Down Expand Up @@ -191,7 +191,7 @@ public final OffsetDateTime getLatestOnset(final Temporal date) {
cacheableOnsets.add(initialOnset);

// check rdates for latest applicable onset..
final List<RDate<LocalDateTime>> rdates = getProperties().get(RDATE);
final List<RDate<LocalDateTime>> rdates = getProperties(RDATE);
for (RDate<LocalDateTime> rdate : rdates) {
List<LocalDateTime> rdateDates = rdate.getDates();
for (final LocalDateTime rdateDate : rdateDates) {
Expand All @@ -208,7 +208,7 @@ public final OffsetDateTime getLatestOnset(final Temporal date) {
}

// check recurrence rules for latest applicable onset..
final List<RRule<OffsetDateTime>> rrules = getProperties().get(RRULE);
final List<RRule<OffsetDateTime>> rrules = getProperties(RRULE);
for (RRule<OffsetDateTime> rrule : rrules) {
// include future onsets to determine onset period..
onsetLimit = offsetDate.plus(10, ChronoUnit.YEARS);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/fortuna/ical4j/model/component/Participant.java
Expand Up @@ -164,6 +164,16 @@ public final void validate(final boolean recurse) throws ValidationException {
}
}

/**
*
* @return
* @deprecated to avoid confusion with how to mutate a ComponentList from v4.x onwards this method is temporarily
* deprecated.
* @see ComponentContainer#add(Component)
* @see ComponentContainer#remove(Component)
* @see ComponentContainer#replace(Component)
*/
@Deprecated
@Override
public ComponentList<Component> getComponents() {
return (ComponentList<Component>) components;
Expand Down

0 comments on commit 11cd8b8

Please sign in to comment.