Class BaseBuilder<T>
java.lang.Object
org.shredzone.commons.suncalc.util.BaseBuilder<T>
- Type Parameters:
T- Type of the final builder
- All Implemented Interfaces:
Cloneable,GenericParameter<T>,LocationParameter<T>,TimeParameter<T>,TimeResultParameter<T>
public class BaseBuilder<T>
extends Object
implements GenericParameter<T>, LocationParameter<T>, TimeParameter<T>, TimeResultParameter<T>, Cloneable
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.shredzone.commons.suncalc.param.TimeResultParameter
TimeResultParameter.Unit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionat(double[] coords) Sets the geolocation.at(double lat, double lng) Sets the geolocation.protected Objectclone()copy()Creates a copy of the current parameters.protected CalendarCreates a newCalendarinstance containing the current instant.doubleReturns the height, in meters above sea level.Returns theJulianDateto be used.doubleReturns the latitude.doubleReturns the latitude.doubleReturns the longitude.doubleReturns the longitude.Returns theTimeResultParameter.Unitto truncate to.height(double h) Sets the height.latitude(double lat) Sets the latitude.latitude(int d, int m, double s) Sets the latitude.Sets the system'sTimeZone.longitude(double lng) Sets the longitude.longitude(int d, int m, double s) Sets the longitude.midnight()Sets the time to the start of the current date ("last midnight").now()Sets the current date and time.on(int year, int month, int date) Sets midnight of the year, month and date.on(int year, int month, int date, int hour, int minute, int second) Sets date and time.Uses the givenCalendarinstance.Uses the givenDateinstance.plusDays(int days) Adds a number of days to the current date.Uses the same location as given in theLocationParameterat this moment.sameTimeAs(TimeParameter<?> t) Uses the same time as given in theTimeParameter.Sets the givenTimeZone.Sets the givenTimeZone.today()Sets today, midnight.tomorrow()Sets tomorrow, midnight.Time unit to truncate the result to.utc()Sets the time zone to UTC.
-
Constructor Details
-
BaseBuilder
public BaseBuilder()
-
-
Method Details
-
on
Description copied from interface:TimeParameterSets midnight of the year, month and date. Uses the system's time zone unless a different time zone is given.- Specified by:
onin interfaceTimeParameter<T>- Parameters:
year- Yearmonth- Month (1 = January, 2 = February, ...)date- Day of month- Returns:
- itself
-
on
Description copied from interface:TimeParameterSets date and time. Note that also seconds can be passed in for convenience, but the results are not that accurate. Uses the system's time zone unless a different time zone is given.- Specified by:
onin interfaceTimeParameter<T>- Parameters:
year- Yearmonth- Month (1 = January, 2 = February, ...)date- Day of monthhour- Hour of dayminute- Minutesecond- Second- Returns:
- itself
-
on
Description copied from interface:TimeParameterUses the givenDateinstance. Uses the system's time zone unless a different time zone is given.- Specified by:
onin interfaceTimeParameter<T>- Parameters:
date-Date. A copy of the date is used. TheDateinstance may be reused after that.- Returns:
- itself
-
on
Description copied from interface:TimeParameterUses the givenCalendarinstance.- Specified by:
onin interfaceTimeParameter<T>- Parameters:
calendar-Calendar. A copy of the date, time, and time zone is used. TheCalendarinstance may be reused after that.- Returns:
- itself
-
plusDays
Description copied from interface:TimeParameterAdds a number of days to the current date.- Specified by:
plusDaysin interfaceTimeParameter<T>- Parameters:
days- Number of days to add- Returns:
- itself
-
today
Description copied from interface:TimeParameterSets today, midnight.It is the same as
now().midnight().- Specified by:
todayin interfaceTimeParameter<T>- Returns:
- itself
-
tomorrow
Description copied from interface:TimeParameterSets tomorrow, midnight.It is the same as
now().midnight().plusDays(1).- Specified by:
tomorrowin interfaceTimeParameter<T>- Returns:
- itself
-
now
Description copied from interface:TimeParameterSets the current date and time. This is the default.- Specified by:
nowin interfaceTimeParameter<T>- Returns:
- itself
-
midnight
Description copied from interface:TimeParameterSets the time to the start of the current date ("last midnight").- Specified by:
midnightin interfaceTimeParameter<T>- Returns:
- itself
-
timezone
Description copied from interface:TimeParameterSets the givenTimeZone.- Specified by:
timezonein interfaceTimeParameter<T>- Parameters:
tz-TimeZoneto be used.- Returns:
- itself
-
timezone
Description copied from interface:TimeParameterSets the givenTimeZone. This is a convenience method that just invokesTimeZone.getTimeZone(String).- Specified by:
timezonein interfaceTimeParameter<T>- Parameters:
id- ID of the time zone. "GMT" is used if the time zone ID was not understood.- Returns:
- itself
- See Also:
-
utc
Description copied from interface:TimeParameterSets the time zone to UTC.- Specified by:
utcin interfaceTimeParameter<T>- Returns:
- itself
-
localTime
Description copied from interface:TimeParameterSets the system'sTimeZone. This is the default.- Specified by:
localTimein interfaceTimeParameter<T>- Returns:
- itself
-
at
Description copied from interface:LocationParameterSets the geolocation.- Specified by:
atin interfaceLocationParameter<T>- Parameters:
lat- Latitude, in degrees.lng- Longitude, in degrees.- Returns:
- itself
-
at
Description copied from interface:LocationParameterSets the geolocation. In the given array, index 0 must contain the latitude, and index 1 must contain the longitude. An optional index 2 may contain the height, in meters.This call is meant to be used for coordinates stored in constants.
- Specified by:
atin interfaceLocationParameter<T>- Parameters:
coords- Array containing the latitude and longitude, in degrees.- Returns:
- itself
-
latitude
Description copied from interface:LocationParameterSets the latitude.- Specified by:
latitudein interfaceLocationParameter<T>- Parameters:
lat- Latitude, in degrees.- Returns:
- itself
-
longitude
Description copied from interface:LocationParameterSets the longitude.- Specified by:
longitudein interfaceLocationParameter<T>- Parameters:
lng- Longitude, in degrees.- Returns:
- itself
-
latitude
Description copied from interface:LocationParameterSets the latitude.- Specified by:
latitudein interfaceLocationParameter<T>- Parameters:
d- Degreesm- Minutess- Seconds (and fraction of seconds)- Returns:
- itself
-
longitude
Description copied from interface:LocationParameterSets the longitude.- Specified by:
longitudein interfaceLocationParameter<T>- Parameters:
d- Degreesm- Minutess- Seconds (and fraction of seconds)- Returns:
- itself
-
height
Description copied from interface:LocationParameterSets the height.- Specified by:
heightin interfaceLocationParameter<T>- Parameters:
h- Height, in meters above sea level. Default: 0.0 m. Negative values are silently changed to the acceptable minimum of 0.0 m.- Returns:
- itself
-
truncatedTo
Description copied from interface:TimeResultParameterTime unit to truncate the result to.- Specified by:
truncatedToin interfaceTimeResultParameter<T>- Parameters:
unit-TimeResultParameter.Unitto use. By default,TimeResultParameter.Unit.MINUTESis used.- Returns:
- itself
-
sameTimeAs
Description copied from interface:TimeParameterUses the same time as given in theTimeParameter.Changes to the source parameter will not affect this parameter, though.
- Specified by:
sameTimeAsin interfaceTimeParameter<T>- Parameters:
t-TimeParameterto be used.- Returns:
- itself
-
sameLocationAs
Description copied from interface:LocationParameterUses the same location as given in theLocationParameterat this moment.Changes to the source parameter will not affect this parameter, though.
- Specified by:
sameLocationAsin interfaceLocationParameter<T>- Parameters:
l-LocationParameterto be used.- Returns:
- itself
-
copy
Description copied from interface:GenericParameterCreates a copy of the current parameters. The copy can be changed independently.- Specified by:
copyin interfaceGenericParameter<T>
-
getLongitude
Returns the longitude.- Returns:
- Longitude, in degrees.
-
getLatitude
Returns the latitude.- Returns:
- Latitude, in degrees.
-
getLongitudeRad
Returns the longitude.- Returns:
- Longitude, in radians.
-
getLatitudeRad
Returns the latitude.- Returns:
- Latitude, in radians.
-
getHeight
Returns the height, in meters above sea level.- Returns:
- Height, meters above sea level
-
getJulianDate
Returns theJulianDateto be used.- Returns:
JulianDate
-
getTruncatedTo
Returns theTimeResultParameter.Unitto truncate to.- Returns:
TimeResultParameter.Unit- Since:
- 2.3
-
createCalendar
Creates a newCalendarinstance containing the current instant.This method can be overriden on unit tests.
- Returns:
Calendarinstance
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-