Skip to content

Commit

Permalink
these are the more complicated code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ely committed Jan 14, 2024
1 parent 2638fc3 commit 0e509fa
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 228 deletions.
97 changes: 42 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 @@ -210,19 +207,16 @@ public boolean isTachanunRecitedMincha(JewishCalendar jewishCalendar) {
JewishCalendar tomorrow = new 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 @@ -446,12 +440,8 @@ 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 @@ -503,14 +493,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());
}

/**
* Is <em>tachanun</em> set to be recited during the week of Purim, from the 11th through the 17th of {@link
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

0 comments on commit 0e509fa

Please sign in to comment.