Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

these are the more complicated code improvements #233

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 43 additions & 55 deletions src/main/java/com/kosherjava/zmanim/hebrewcalendar/TefilaRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,34 +170,31 @@ public boolean isTachanunRecitedShacharis(JewishCalendar jewishCalendar) {
int day = jewishCalendar.getJewishDayOfMonth();
int month = jewishCalendar.getJewishMonth();

if (jewishCalendar.getDayOfWeek() == Calendar.SATURDAY
|| (!tachanunRecitedSundays && jewishCalendar.getDayOfWeek() == Calendar.SUNDAY)
|| (!tachanunRecitedFridays && jewishCalendar.getDayOfWeek() == Calendar.FRIDAY)
|| month == JewishDate.NISSAN
|| (month == JewishDate.TISHREI && ((!tachanunRecitedEndOfTishrei && day > 8)
|| (tachanunRecitedEndOfTishrei && (day > 8 && day < 22))))
|| (month == JewishDate.SIVAN && (tachanunRecitedWeekAfterShavuos && day < 7
|| !tachanunRecitedWeekAfterShavuos && day < (!jewishCalendar.getInIsrael()
&& !tachanunRecited13SivanOutOfIsrael ? 14: 13)))
|| (jewishCalendar.isYomTov() && (! jewishCalendar.isTaanis()
|| (!tachanunRecitedPesachSheni && holidayIndex == JewishCalendar.PESACH_SHENI))) // Erev YT is included in isYomTov()
|| (!jewishCalendar.getInIsrael() && !tachanunRecitedPesachSheni && !tachanunRecited15IyarOutOfIsrael
&& jewishCalendar.getJewishMonth() == JewishDate.IYAR && day == 15)
|| holidayIndex == JewishCalendar.TISHA_BEAV || jewishCalendar.isIsruChag()
|| jewishCalendar.isRoshChodesh()
|| (!tachanunRecitedShivasYemeiHamiluim &&
((!jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR)
|| (jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR_II)) && day > 22)
|| (!tachanunRecitedWeekOfPurim &&
((!jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR)
|| (jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR_II)) && day > 10 && day < 18)
|| (jewishCalendar.isUseModernHolidays()
&& (holidayIndex == JewishCalendar.YOM_HAATZMAUT || holidayIndex == JewishCalendar.YOM_YERUSHALAYIM))
|| (!tachanunRecitedWeekOfHod && month == JewishDate.IYAR && day > 13 && day < 21)) {
return false;
}
return true;
}
return jewishCalendar.getDayOfWeek() != Calendar.SATURDAY
&& (tachanunRecitedSundays || jewishCalendar.getDayOfWeek() != Calendar.SUNDAY)
&& (tachanunRecitedFridays || jewishCalendar.getDayOfWeek() != Calendar.FRIDAY)
&& month != JewishDate.NISSAN
&& (month != JewishDate.TISHREI || ((tachanunRecitedEndOfTishrei || day <= 8)
&& (!tachanunRecitedEndOfTishrei || (day <= 8 || day >= 22))))
&& (month != JewishDate.SIVAN || ((!tachanunRecitedWeekAfterShavuos || day >= 7)
&& (tachanunRecitedWeekAfterShavuos || day >= (!jewishCalendar.getInIsrael()
&& !tachanunRecited13SivanOutOfIsrael ? 14 : 13))))
&& (!jewishCalendar.isYomTov() || (jewishCalendar.isTaanis()
&& (tachanunRecitedPesachSheni || holidayIndex != JewishCalendar.PESACH_SHENI))) // Erev YT is included in isYomTov()
&& (jewishCalendar.getInIsrael() || tachanunRecitedPesachSheni || tachanunRecited15IyarOutOfIsrael
|| jewishCalendar.getJewishMonth() != JewishDate.IYAR || day != 15)
&& holidayIndex != JewishCalendar.TISHA_BEAV && !jewishCalendar.isIsruChag()
&& !jewishCalendar.isRoshChodesh()
&& (tachanunRecitedShivasYemeiHamiluim ||
((jewishCalendar.isJewishLeapYear() || month != JewishDate.ADAR)
&& (!jewishCalendar.isJewishLeapYear() || month != JewishDate.ADAR_II)) || day <= 22)
&& (tachanunRecitedWeekOfPurim ||
((jewishCalendar.isJewishLeapYear() || month != JewishDate.ADAR)
&& (!jewishCalendar.isJewishLeapYear() || month != JewishDate.ADAR_II)) || day <= 10 || day >= 18)
&& (!jewishCalendar.isUseModernHolidays()
|| (holidayIndex != JewishCalendar.YOM_HAATZMAUT && holidayIndex != JewishCalendar.YOM_YERUSHALAYIM))
&& (tachanunRecitedWeekOfHod || month != JewishDate.IYAR || day <= 13 || day >= 21);
}

/**
* Returns if <em>tachanun</em> is recited during <em>mincha</em> on the day in question.
Expand All @@ -209,19 +206,16 @@ public boolean isTachanunRecitedShacharis(JewishCalendar jewishCalendar) {
public boolean isTachanunRecitedMincha(JewishCalendar jewishCalendar) {
JewishCalendar tomorrow = (JewishCalendar) jewishCalendar.clone();
tomorrow.forward(Calendar.DATE, 1);

if (!tachanunRecitedMinchaAllYear
|| jewishCalendar.getDayOfWeek() == Calendar.FRIDAY
|| ! isTachanunRecitedShacharis(jewishCalendar)
|| (! isTachanunRecitedShacharis(tomorrow) &&
!(tomorrow.getYomTovIndex() == JewishCalendar.EREV_ROSH_HASHANA) &&
!(tomorrow.getYomTovIndex() == JewishCalendar.EREV_YOM_KIPPUR) &&
!(tomorrow.getYomTovIndex() == JewishCalendar.PESACH_SHENI))
|| ! tachanunRecitedMinchaErevLagBaomer && tomorrow.getYomTovIndex() == JewishCalendar.LAG_BAOMER) {
return false;
}
return true;
}

return tachanunRecitedMinchaAllYear
&& jewishCalendar.getDayOfWeek() != Calendar.FRIDAY
&& isTachanunRecitedShacharis(jewishCalendar)
&& (isTachanunRecitedShacharis(tomorrow) ||
tomorrow.getYomTovIndex() == JewishCalendar.EREV_ROSH_HASHANA ||
tomorrow.getYomTovIndex() == JewishCalendar.EREV_YOM_KIPPUR ||
tomorrow.getYomTovIndex() == JewishCalendar.PESACH_SHENI)
&& (tachanunRecitedMinchaErevLagBaomer || tomorrow.getYomTovIndex() != JewishCalendar.LAG_BAOMER);
}

/**
* Returns if it is the Jewish day (starting the evening before) to start reciting <em>Vesein Tal Umatar Livracha</em>
Expand Down Expand Up @@ -439,13 +433,9 @@ public boolean isHallelShalemRecited(JewishCalendar jewishCalendar) {
int month = jewishCalendar.getJewishMonth();
boolean inIsrael = jewishCalendar.getInIsrael();
if (isHallelRecited(jewishCalendar)) {
if ((jewishCalendar.isRoshChodesh() && ! jewishCalendar.isChanukah())
|| (month == JewishDate.NISSAN && ((inIsrael && day > 15) || (!inIsrael && day > 16)))) {
return false;
} else {
return true;
}
}
return (!jewishCalendar.isRoshChodesh() || jewishCalendar.isChanukah())
&& (month != JewishDate.NISSAN || ((!inIsrael || day <= 15) && (inIsrael || day <= 16)));
}
return false;
}

Expand Down Expand Up @@ -496,13 +486,11 @@ public boolean isMizmorLesodaRecited(JewishCalendar jewishCalendar) {
}

int holidayIndex = jewishCalendar.getYomTovIndex();
if (! isMizmorLesodaRecitedErevYomKippurAndPesach()
&& (holidayIndex == JewishCalendar.EREV_YOM_KIPPUR
|| holidayIndex == JewishCalendar.EREV_PESACH
|| jewishCalendar.isCholHamoedPesach())) {
return false;
}
return true;
return isMizmorLesodaRecitedErevYomKippurAndPesach()
|| (holidayIndex != JewishCalendar.EREV_YOM_KIPPUR
&& holidayIndex != JewishCalendar.EREV_PESACH
&& !jewishCalendar.isCholHamoedPesach());
}
}

/**
Expand Down
46 changes: 19 additions & 27 deletions src/main/java/com/kosherjava/zmanim/util/Zman.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,11 @@ public void setDescription(String description) {
* than the second.
* Please note that this class will handle cases where either the {@code Zman} is a null or {@link #getZman()} returns a null.
*/
public static final Comparator<Zman> DATE_ORDER = new Comparator<Zman>() {
public int compare(Zman zman1, Zman zman2) {
long firstTime = (zman1 == null || zman1.getZman() == null) ? Long.MAX_VALUE : zman1.getZman().getTime();
long secondTime = (zman2 == null || zman2.getZman() == null) ? Long.MAX_VALUE : zman2.getZman().getTime();
return Long.valueOf(firstTime).compareTo(Long.valueOf(secondTime));
}
};
public static final Comparator<Zman> DATE_ORDER = (zman1, zman2) -> {
long firstTime = (zman1 == null || zman1.getZman() == null) ? Long.MAX_VALUE : zman1.getZman().getTime();
long secondTime = (zman2 == null || zman2.getZman() == null) ? Long.MAX_VALUE : zman2.getZman().getTime();
return Long.compare(firstTime, secondTime);
};

/**
* A {@link Comparator} that will compare and sort zmanim by zmanim label order. Compares its two arguments by the zmanim label
Expand All @@ -207,13 +205,11 @@ public int compare(Zman zman1, Zman zman2) {
* Please note that this class will sort cases where either the {@code Zman} is a null or {@link #label} returns a null
* as empty {@code String}s.
*/
public static final Comparator<Zman> NAME_ORDER = new Comparator<Zman>() {
public int compare(Zman zman1, Zman zman2) {
String firstLabel = (zman1 == null || zman1.getLabel() == null) ? "" : zman1.getLabel();
String secondLabel = (zman2 == null || zman2.getLabel() == null) ? "" : zman2.getLabel();
return firstLabel.compareTo(secondLabel);
}
};
public static final Comparator<Zman> NAME_ORDER = (zman1, zman2) -> {
String firstLabel = (zman1 == null || zman1.getLabel() == null) ? "" : zman1.getLabel();
String secondLabel = (zman2 == null || zman2.getLabel() == null) ? "" : zman2.getLabel();
return firstLabel.compareTo(secondLabel);
};

/**
* A {@link Comparator} that will compare and sort duration based <em>zmanim</em> such as
Expand All @@ -223,23 +219,19 @@ public int compare(Zman zman1, Zman zman2) {
* 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 sort cases where {@code Zman} is a null.
*/
public static final Comparator<Zman> DURATION_ORDER = new Comparator<Zman>() {
public int compare(Zman zman1, Zman zman2) {
long firstDuration = zman1 == null ? Long.MAX_VALUE : zman1.getDuration();
long secondDuration = zman2 == null ? Long.MAX_VALUE : zman2.getDuration();
return firstDuration == secondDuration ? 0 : firstDuration > secondDuration ? 1 : -1;
}
};
public static final Comparator<Zman> DURATION_ORDER = (zman1, zman2) -> {
long firstDuration = zman1 == null ? Long.MAX_VALUE : zman1.getDuration();
long secondDuration = zman2 == null ? Long.MAX_VALUE : zman2.getDuration();
return Long.compare(firstDuration, secondDuration);
};

/**
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("\nLabel:\t\t\t").append(this.getLabel());
sb.append("\nZman:\t\t\t").append(getZman());
sb.append("\nDuration:\t\t\t").append(getDuration());
sb.append("\nDescription:\t\t\t").append(getDescription());
return sb.toString();
return "\nLabel:\t\t\t" + this.getLabel() +
"\nZman:\t\t\t" + getZman() +
"\nDuration:\t\t\t" + getDuration() +
"\nDescription:\t\t\t" + getDescription();
}
}
Loading
Loading