GithubHelp home page GithubHelp logo

Comments (3)

raboof avatar raboof commented on September 21, 2024 1

Let me know if you think there are advantages for your suggestion over this one.

Gladly!

This basically indicates there is no correlation between the period and the recurrence set, as the temporal type is derived from the type used in DTSTART property.

That makes sense to me.

Generally, I think a library should use the type system to specify what it guarantees. The user of the library can make additional assumptions, and the mechanism to encode those is casts. From that perspective, I think

public final Set<Period<Temporal>> calculateRecurrenceSet(Period<? extends Temporal> period)

would be slightly better. In

Set<Period<LocalDate>> result = calculateRecurrenceSet(period);
LocalDate date = result.iterator().next().getStart()

, when passing in events with different types for the DTSTART property, it would be surprising to me to get a ClassCastException on the second line. With my proposed signature, indeed this code becomes either

Set<Period<LocalDate>> result = (Set<Period<LocalDate>>) calculateRecurrenceSet(period);
LocalDate date = result.iterator().next().getStart()

or

Set<Period<Temporal>> result = calculateRecurrenceSet(period);
LocalDate date = (LocalDate) result.iterator().next().getStart()

While this is more verbose, I like how the cast makes it explicit that I'm responsible for this assumption (justified by the knowledge of the DTSTART property).

Anyway, I don't feel particularly strongly about this, and I'm happy with the library as it is, but since you asked these are my 2ct :)

from ical4j.

benfortuna avatar benfortuna commented on September 21, 2024

Thanks for the feedback, apologies for late response.

This has been fixed in a recent version, although the fix is slightly different to your suggestion:

public final <T extends Temporal> Set<Period<T>> calculateRecurrenceSet(Period<? extends Temporal> period)

This basically indicates there is no correlation between the period and the recurrence set, as the temporal type is derived from the type used in DTSTART property.

The difference is that the caller can use their knowledge of the DTSTART property to assume the correct type, e.g:

Set<Period<LocalDate>> result = calculateRecurrenceSet(period);

Let me know if you think there are advantages for your suggestion over this one.

https://javadoc.io/doc/org.mnode.ical4j/ical4j/latest/ical4j.core/net/fortuna/ical4j/model/Component.html

from ical4j.

benfortuna avatar benfortuna commented on September 21, 2024

Good points, although I think the explicit cast of the entire set doesn't work (I get following error):

Inconvertible types; cannot cast 'java.util.Set<net.fortuna.ical4j.model.Period<java.time.temporal.Temporal>>' to 'java.util.Set<net.fortuna.ical4j.model.Period<java.time.LocalDate>>'

Still, I might change it anyway.

from ical4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.