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
-
Method Summary
Modifier and TypeMethodDescriptionat
(double[] coords) Sets the geolocation.at
(double lat, double lng) Sets the geolocation.protected Object
clone()
copy()
Creates a copy of the current parameters.protected Calendar
Creates a newCalendar
instance containing the current instant.double
Returns the height, in meters above sea level.Returns theJulianDate
to be used.double
Returns the latitude.double
Returns the latitude.double
Returns the longitude.double
Returns the longitude.Returns theTimeResultParameter.Unit
to 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 givenCalendar
instance.Uses the givenDate
instance.plusDays
(int days) Adds a number of days to the current date.Uses the same location as given in theLocationParameter
at 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:TimeParameter
Sets midnight of the year, month and date. Uses the system's time zone unless a different time zone is given.- Specified by:
on
in interfaceTimeParameter<T>
- Parameters:
year
- Yearmonth
- Month (1 = January, 2 = February, ...)date
- Day of month- Returns:
- itself
-
on
Description copied from interface:TimeParameter
Sets 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:
on
in 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:TimeParameter
Uses the givenDate
instance. Uses the system's time zone unless a different time zone is given.- Specified by:
on
in interfaceTimeParameter<T>
- Parameters:
date
-Date
. A copy of the date is used. TheDate
instance may be reused after that.- Returns:
- itself
-
on
Description copied from interface:TimeParameter
Uses the givenCalendar
instance.- Specified by:
on
in interfaceTimeParameter<T>
- Parameters:
calendar
-Calendar
. A copy of the date, time, and time zone is used. TheCalendar
instance may be reused after that.- Returns:
- itself
-
plusDays
Description copied from interface:TimeParameter
Adds a number of days to the current date.- Specified by:
plusDays
in interfaceTimeParameter<T>
- Parameters:
days
- Number of days to add- Returns:
- itself
-
today
Description copied from interface:TimeParameter
Sets today, midnight.It is the same as
now().midnight()
.- Specified by:
today
in interfaceTimeParameter<T>
- Returns:
- itself
-
tomorrow
Description copied from interface:TimeParameter
Sets tomorrow, midnight.It is the same as
now().midnight().plusDays(1)
.- Specified by:
tomorrow
in interfaceTimeParameter<T>
- Returns:
- itself
-
now
Description copied from interface:TimeParameter
Sets the current date and time. This is the default.- Specified by:
now
in interfaceTimeParameter<T>
- Returns:
- itself
-
midnight
Description copied from interface:TimeParameter
Sets the time to the start of the current date ("last midnight").- Specified by:
midnight
in interfaceTimeParameter<T>
- Returns:
- itself
-
timezone
Description copied from interface:TimeParameter
Sets the givenTimeZone
.- Specified by:
timezone
in interfaceTimeParameter<T>
- Parameters:
tz
-TimeZone
to be used.- Returns:
- itself
-
timezone
Description copied from interface:TimeParameter
Sets the givenTimeZone
. This is a convenience method that just invokesTimeZone.getTimeZone(String)
.- Specified by:
timezone
in 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:TimeParameter
Sets the time zone to UTC.- Specified by:
utc
in interfaceTimeParameter<T>
- Returns:
- itself
-
localTime
Description copied from interface:TimeParameter
Sets the system'sTimeZone
. This is the default.- Specified by:
localTime
in interfaceTimeParameter<T>
- Returns:
- itself
-
at
Description copied from interface:LocationParameter
Sets the geolocation.- Specified by:
at
in interfaceLocationParameter<T>
- Parameters:
lat
- Latitude, in degrees.lng
- Longitude, in degrees.- Returns:
- itself
-
at
Description copied from interface:LocationParameter
Sets 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:
at
in interfaceLocationParameter<T>
- Parameters:
coords
- Array containing the latitude and longitude, in degrees.- Returns:
- itself
-
latitude
Description copied from interface:LocationParameter
Sets the latitude.- Specified by:
latitude
in interfaceLocationParameter<T>
- Parameters:
lat
- Latitude, in degrees.- Returns:
- itself
-
longitude
Description copied from interface:LocationParameter
Sets the longitude.- Specified by:
longitude
in interfaceLocationParameter<T>
- Parameters:
lng
- Longitude, in degrees.- Returns:
- itself
-
latitude
Description copied from interface:LocationParameter
Sets the latitude.- Specified by:
latitude
in interfaceLocationParameter<T>
- Parameters:
d
- Degreesm
- Minutess
- Seconds (and fraction of seconds)- Returns:
- itself
-
longitude
Description copied from interface:LocationParameter
Sets the longitude.- Specified by:
longitude
in interfaceLocationParameter<T>
- Parameters:
d
- Degreesm
- Minutess
- Seconds (and fraction of seconds)- Returns:
- itself
-
height
Description copied from interface:LocationParameter
Sets the height.- Specified by:
height
in 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:TimeResultParameter
Time unit to truncate the result to.- Specified by:
truncatedTo
in interfaceTimeResultParameter<T>
- Parameters:
unit
-TimeResultParameter.Unit
to use. By default,TimeResultParameter.Unit.MINUTES
is used.- Returns:
- itself
-
sameTimeAs
Description copied from interface:TimeParameter
Uses the same time as given in theTimeParameter
.Changes to the source parameter will not affect this parameter, though.
- Specified by:
sameTimeAs
in interfaceTimeParameter<T>
- Parameters:
t
-TimeParameter
to be used.- Returns:
- itself
-
sameLocationAs
Description copied from interface:LocationParameter
Uses the same location as given in theLocationParameter
at this moment.Changes to the source parameter will not affect this parameter, though.
- Specified by:
sameLocationAs
in interfaceLocationParameter<T>
- Parameters:
l
-LocationParameter
to be used.- Returns:
- itself
-
copy
Description copied from interface:GenericParameter
Creates a copy of the current parameters. The copy can be changed independently.- Specified by:
copy
in 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 theJulianDate
to be used.- Returns:
JulianDate
-
getTruncatedTo
Returns theTimeResultParameter.Unit
to truncate to.- Returns:
TimeResultParameter.Unit
- Since:
- 2.3
-
createCalendar
Creates a newCalendar
instance containing the current instant.This method can be overriden on unit tests.
- Returns:
Calendar
instance
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-