Package com.kosherjava.zmanim.util
Class Zman
java.lang.Object
com.kosherjava.zmanim.util.Zman
A wrapper class for a astronomical times / zmanim that is mostly intended to allow sorting collections of astronomical times.
It has fields for both date/time and duration based zmanim, name / labels as well as a longer description or explanation of a
zman.
Here is an example of various ways of sorting zmanim.
First create the Calendar for the location you would like to calculate:
String locationName = "Lakewood, NJ";
double latitude = 40.0828; // Lakewood, NJ
double longitude = -74.2094; // Lakewood, NJ
double elevation = 20; // optional elevation correction in Meters
// the String parameter in getTimeZone() has to be a valid timezone listed in TimeZone.getAvailableIDs()
TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone);
ComplexZmanimCalendar czc = new ComplexZmanimCalendar(location);
Zman sunset = new Zman(czc.getSunset(), "Sunset");
Zman shaah16 = new Zman(czc.getShaahZmanis16Point1Degrees(), "Shaah zmanis 16.1");
Zman sunrise = new Zman(czc.getSunrise(), "Sunrise");
Zman shaah = new Zman(czc.getShaahZmanisGra(), "Shaah zmanis GRA");
ArrayList<Zman> zl = new ArrayList<Zman>();
zl.add(sunset);
zl.add(shaah16);
zl.add(sunrise);
zl.add(shaah);
//will sort sunset, shaah 1.6, sunrise, shaah GRA
System.out.println(zl);
Collections.sort(zl, Zman.DATE_ORDER);
// will sort sunrise, sunset, shaah, shaah 1.6 (the last 2 are not in any specific order)
Collections.sort(zl, Zman.DURATION_ORDER);
// will sort sunrise, sunset (the first 2 are not in any specific order), shaah GRA, shaah 1.6
Collections.sort(zl, Zman.NAME_ORDER);
// will sort shaah 1.6, shaah GRA, sunrise, sunset
- Author:
- © Eliyahu Hershfeld 2007-2020
- TODO:
- Add secondary sorting. As of now the
Comparator
s in this class do not sort by secondary order. This means that when sorting aCollection
of zmanim and using theDATE_ORDER
Comparator
will have the duration based zmanim at the end, but they will not be sorted by duration. This should be N/A for label based sorting.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Comparator<Zman>
AComparator
that will compare and sort zmanim by date/time order.private String
A longer description or explanation of a zman.private long
The duration if the zman is atemporal hour
(or the various shaah zmanis base times such asshaah Zmanis GRA
orshaah Zmanis 16.1°
).static final Comparator<Zman>
AComparator
that will compare and sort duration based zmanim such astemporal hour
(or the various shaah zmanis times such asshaah zmanis GRA
orshaah zmanis 16.1°
).private String
The name / label of the zman.static final Comparator<Zman>
AComparator
that will compare and sort zmanim by zmanim label order.private Date
TheDate
of the zman -
Constructor Summary
ConstructorDescriptionThe constructor setting a duration based zman such astemporal hour
(or the various shaah zmanis times such asshaah zmanis GRA
orshaah Zmanis 16.1°
) and label.The constructor setting aDate
based zman and a label. -
Method Summary
Modifier and TypeMethodDescriptionReturns the longer description or explanation of a zman.long
Returns a duration based zman such astemporal hour
(or the various shaah zmanis times such asshaah zmanis GRA
orshaah zmanis 16.1°
).getLabel()
Returns the name / label of the zman such as "Sof Zman Krias Shema GRA".getZman()
Returns theDate
based zman.void
setDescription
(String description) Sets the longer description or explanation of a zman.void
setDuration
(long duration) Sets a duration based zman such astemporal hour
(or the various shaah zmanis times asshaah zmanis GRA
orshaah zmanis 16.1°
).void
Sets the the name / label of the zman such as "Sof Zman Krias Shema GRA".void
Sets aDate
based zman.toString()
-
Field Details
-
label
The name / label of the zman. -
zman
TheDate
of the zman -
duration
The duration if the zman is atemporal hour
(or the various shaah zmanis base times such asshaah Zmanis GRA
orshaah Zmanis 16.1°
). -
description
A longer description or explanation of a zman. -
DATE_ORDER
AComparator
that will compare and sort zmanim by date/time order. Compares its two arguments by the zman's date/time order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Please note that this class will handle cases where either theZman
is a null orgetZman()
returns a null. -
NAME_ORDER
AComparator
that will compare and sort zmanim by zmanim label order. Compares its two arguments by the zmanim label name order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Please note that this class will will sort cases where either theZman
is a null orlabel
returns a null as emptyString
s. -
DURATION_ORDER
AComparator
that will compare and sort duration based zmanim such astemporal hour
(or the various shaah zmanis times such asshaah zmanis GRA
orshaah zmanis 16.1°
). Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Please note that this class will will sort cases whereZman
is a null.
-
-
Constructor Details
-
Zman
The constructor setting aDate
based zman and a label.- Parameters:
date
- the Date of the zman.label
- the label of the zman such as "Sof Zman Krias Shema GRA".- See Also:
-
Zman
The constructor setting a duration based zman such astemporal hour
(or the various shaah zmanis times such asshaah zmanis GRA
orshaah Zmanis 16.1°
) and label.- Parameters:
duration
- a duration based zman such as (AstronomicalCalendar.getTemporalHour()
label
- the label of the zman such as "Shaah Zmanis GRA".- See Also:
-
-
Method Details
-
getZman
Returns theDate
based zman.- Returns:
- the zman.
- See Also:
-
setZman
Sets aDate
based zman.- Parameters:
date
- aDate
based zman- See Also:
-
getDuration
Returns a duration based zman such astemporal hour
(or the various shaah zmanis times such asshaah zmanis GRA
orshaah zmanis 16.1°
).- Returns:
- the duration based zman.
- See Also:
-
setDuration
Sets a duration based zman such astemporal hour
(or the various shaah zmanis times asshaah zmanis GRA
orshaah zmanis 16.1°
).- Parameters:
duration
- duration based zman such asAstronomicalCalendar.getTemporalHour()
.- See Also:
-
getLabel
Returns the name / label of the zman such as "Sof Zman Krias Shema GRA". There are no automatically set labels and you must set them usingsetLabel(String)
.- Returns:
- the name/label of the zman.
- See Also:
-
setLabel
Sets the the name / label of the zman such as "Sof Zman Krias Shema GRA".- Parameters:
label
- the name / label to set for the zman.- See Also:
-
getDescription
Returns the longer description or explanation of a zman. There is no default value for this and it must be set usingsetDescription(String)
- Returns:
- the description or explanation of a zman.
- See Also:
-
setDescription
Sets the longer description or explanation of a zman.- Parameters:
description
- the zman description to set.- See Also:
-
toString
-