Add cache for time provider
The improvement is surely negligible, perhaps harming performance, so more of a gimmick
This commit is contained in:
parent
1f1a3260c0
commit
7930e4dd0a
2 changed files with 44 additions and 0 deletions
|
@ -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 <T> An implementation of {@link TwilightTimeCache} where you store whatever you need
|
||||
*/
|
||||
public abstract class CacheableTwilightTimeProvider<T extends TwilightTimeCache> 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
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package eu.m724.wtapi.provider.twilight;
|
||||
|
||||
public interface TwilightTimeCache {
|
||||
}
|
Loading…
Reference in a new issue