diff --git a/src/main/java/eu/m724/wtapi/provider/twilight/CacheableTwilightTimeProvider.java b/src/main/java/eu/m724/wtapi/provider/twilight/CacheableTwilightTimeProvider.java new file mode 100644 index 0000000..649d8d1 --- /dev/null +++ b/src/main/java/eu/m724/wtapi/provider/twilight/CacheableTwilightTimeProvider.java @@ -0,0 +1,40 @@ +package eu.m724.wtapi.provider.twilight; + +import eu.m724.wtapi.object.Coordinates; +import eu.m724.wtapi.object.Twilight; + +import java.time.LocalDate; + +// TODO reconsider if this is necessary and doesn't actually harm performance +/** + * A {@link TwilightTimeProvider} that can cache some calculations to be faster + * + * @param An implementation of {@link TwilightTimeCache} where you store whatever you need + */ +public abstract class CacheableTwilightTimeProvider extends TwilightTimeProvider { + /** + * Calculates sunrise and sunset for provided coordinates + * + * @param cache {@link T}, implementation of {@link TwilightTimeCache} + * @param coordinates Coordinates of the observer + * @return {@link Twilight} + * @see #initializeCache(LocalDate) + */ + public abstract Twilight calculateTwilightTime(T cache, Coordinates coordinates); + + /** + * Initializes cache for provided date + * + * @param date The UTC date + * @return ready to use cache + */ + public abstract T initializeCache(LocalDate date); + + @Override + public Twilight calculateTwilightTime(LocalDate date, Coordinates coordinates) { + return calculateTwilightTime( + initializeCache(date), + coordinates + ); + } +} diff --git a/src/main/java/eu/m724/wtapi/provider/twilight/TwilightTimeCache.java b/src/main/java/eu/m724/wtapi/provider/twilight/TwilightTimeCache.java new file mode 100644 index 0000000..fe6304c --- /dev/null +++ b/src/main/java/eu/m724/wtapi/provider/twilight/TwilightTimeCache.java @@ -0,0 +1,4 @@ +package eu.m724.wtapi.provider.twilight; + +public interface TwilightTimeCache { +}