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

code improvements #230

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void main(String args[]) {
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Expand All @@ -65,7 +65,7 @@ public static void main(String args[]) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
Expand All @@ -76,8 +76,8 @@ public static void main(String args[]) {
System.out.println("- Downloading from: " + url);

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/kosherjava/zmanim/AstronomicalCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ public double getSunriseSolarDipFromOffset(double minutes) {

while (offsetByDegrees == null || ((minutes < 0.0 && offsetByDegrees.getTime() < offsetByTime.getTime()) ||
(minutes > 0.0 && offsetByDegrees.getTime() > offsetByTime.getTime()))) {
if(minutes > 0.0) {
if (minutes > 0.0) {
degrees = degrees.add(incrementor);
} else {
degrees = degrees.subtract(incrementor);
Expand Down Expand Up @@ -649,7 +649,7 @@ public double getSunsetSolarDipFromOffset(double minutes) {
BigDecimal incrementor = new BigDecimal("0.001");
while (offsetByDegrees == null || ((minutes > 0.0 && offsetByDegrees.getTime() < offsetByTime.getTime()) ||
(minutes < 0.0 && offsetByDegrees.getTime() > offsetByTime.getTime()))) {
if(minutes > 0.0) {
if (minutes > 0.0) {
degrees = degrees.add(incrementor);
} else {
degrees = degrees.subtract(incrementor);
Expand Down Expand Up @@ -677,7 +677,7 @@ public double getSunsetSolarDipFromOffset(double minutes) {
* @see GeoLocation#getLocalMeanTimeOffset()
*/
public Date getLocalMeanTime(double hours) {
if(hours < 0 || hours >= 24) {
if (hours < 0 || hours >= 24) {
throw new IllegalArgumentException("Hours must between 0 and 23.9999...");
}
return getTimeOffset(getDateFromTime(hours - getGeoLocation().getTimeZone().getRawOffset()
Expand Down Expand Up @@ -832,9 +832,11 @@ public Object clone() {
} catch (CloneNotSupportedException cnse) {
// Required by the compiler. Should never be reached since we implement clone()
}
clone.setGeoLocation((GeoLocation) getGeoLocation().clone());
clone.setCalendar((Calendar) getCalendar().clone());
clone.setAstronomicalCalculator((AstronomicalCalculator) getAstronomicalCalculator().clone());
if (clone != null) {
clone.setGeoLocation((GeoLocation) getGeoLocation().clone());
clone.setCalendar((Calendar) getCalendar().clone());
clone.setAstronomicalCalculator((AstronomicalCalculator) getAstronomicalCalculator().clone());
}
return clone;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just to get rid of a possible NullPointerException warning. I know it is not necessary, but it is still beneficial to get rid of a few warnings.

}
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ public Date getMinchaGedola30Minutes() {
* {@link AstronomicalCalendar} documentation.
*/
public Date getMinchaGedola72Minutes() {
if(isUseAstronomicalChatzosForOtherZmanim()) {
if (isUseAstronomicalChatzosForOtherZmanim()) {
return getHalfDayBasedZman(getChatzos(), getTzais72(), 0.5);
} else {
return getMinchaGedola(getAlos72(), getTzais72(), true);
Expand All @@ -1846,7 +1846,7 @@ public Date getMinchaGedola72Minutes() {
* See detailed explanation on top of the {@link AstronomicalCalendar} documentation.
*/
public Date getMinchaGedola16Point1Degrees() {
if(isUseAstronomicalChatzosForOtherZmanim()) {
if (isUseAstronomicalChatzosForOtherZmanim()) {
return getHalfDayBasedZman(getChatzos(), getTzais16Point1Degrees(), 0.5);
} else {
return getMinchaGedola(getAlos16Point1Degrees(), getTzais16Point1Degrees(), true);
Expand Down
44 changes: 20 additions & 24 deletions src/main/java/com/kosherjava/zmanim/ZmanimCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void setUseAstronomicalChatzosForOtherZmanim(boolean useAstronomicalChatz
* @see com.kosherjava.zmanim.AstronomicalCalendar#getSunrise()
*/
protected Date getElevationAdjustedSunrise() {
if(isUseElevation()) {
if (isUseElevation()) {
return super.getSunrise();
}
return getSeaLevelSunrise();
Expand All @@ -282,7 +282,7 @@ protected Date getElevationAdjustedSunrise() {
* @see com.kosherjava.zmanim.AstronomicalCalendar#getSunset()
*/
protected Date getElevationAdjustedSunset() {
if(isUseElevation()) {
if (isUseElevation()) {
return super.getSunset();
}
return getSeaLevelSunset();
Expand Down Expand Up @@ -370,11 +370,11 @@ public Date getAlos72() {
* See detailed explanation on top of the {@link AstronomicalCalendar} documentation.
*/
public Date getChatzos() {
if(useAstronomicalChatzos) {
if (useAstronomicalChatzos) {
return getSunTransit(); // can be null of the calculator does not support astronomical chatzos
} else {
Date halfDayChatzos = getChatzosAsHalfDay();
if(halfDayChatzos == null) {
if (halfDayChatzos == null) {
return getSunTransit(); // can be null if the calculator does not support astronomical chatzos
} else {
return halfDayChatzos;
Expand Down Expand Up @@ -447,7 +447,7 @@ public Date getChatzosAsHalfDay() {
* detailed explanation on top of the {@link AstronomicalCalendar} documentation.
*/
public Date getSofZmanShma(Date startOfDay, Date endOfDay, boolean synchronous) {
if(isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
if (isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
return getHalfDayBasedZman(startOfDay, getChatzos(), 3);
} else {
return getShaahZmanisBasedZman(startOfDay, endOfDay, 3);
Expand Down Expand Up @@ -588,7 +588,7 @@ public Date getCandleLighting() {
* returned. See detailed explanation on top of the {@link AstronomicalCalendar} documentation.
*/
public Date getSofZmanTfila(Date startOfDay, Date endOfDay, boolean synchronous) {
if(isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
if (isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
return getHalfDayBasedZman(startOfDay, getChatzos(), 4);
} else {
return getShaahZmanisBasedZman(startOfDay, endOfDay, 4);
Expand Down Expand Up @@ -697,7 +697,7 @@ public Date getSofZmanTfilaMGA() {
* @see #isUseAstronomicalChatzosForOtherZmanim()
*/
public Date getMinchaGedola(Date startOfDay, Date endOfDay, boolean synchronous) {
if(isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
if (isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
return getHalfDayBasedZman(getChatzos(), endOfDay, 0.5);
} else {
return getShaahZmanisBasedZman(startOfDay, endOfDay, 6.5);
Expand Down Expand Up @@ -784,7 +784,7 @@ public Date getMinchaGedola() {
* @see ComplexZmanimCalendar#getSamuchLeMinchaKetana72Minutes()
*/
public Date getSamuchLeMinchaKetana(Date startOfDay, Date endOfDay, boolean synchronous) {
if(isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
if (isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
return getHalfDayBasedZman(getChatzos(), endOfDay, 3);
} else {
return getShaahZmanisBasedZman(startOfDay, endOfDay, 9);
Expand Down Expand Up @@ -845,7 +845,7 @@ public Date getSamuchLeMinchaKetana(Date startOfDay, Date endOfDay) {
* be returned. See detailed explanation on top of the {@link AstronomicalCalendar} documentation.
*/
public Date getMinchaKetana(Date startOfDay, Date endOfDay, boolean synchronous) {
if(isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
if (isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
return getHalfDayBasedZman(getChatzos(), endOfDay, 3.5);
} else {
return getShaahZmanisBasedZman(startOfDay, endOfDay, 9.5);
Expand Down Expand Up @@ -927,7 +927,7 @@ public Date getMinchaKetana() {
* will be returned. See detailed explanation on top of the {@link AstronomicalCalendar} documentation.
*/
public Date getPlagHamincha(Date startOfDay, Date endOfDay, boolean synchronous) {
if(isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
if (isUseAstronomicalChatzosForOtherZmanim() && synchronous) {
return getHalfDayBasedZman(getChatzos(), endOfDay, 4.75);
} else {
return getShaahZmanisBasedZman(startOfDay, endOfDay, 10.75);
Expand Down Expand Up @@ -1083,16 +1083,12 @@ public boolean isAssurBemlacha(Date currentTime, Date tzais, boolean inIsrael) {
getCalendar().get(Calendar.DAY_OF_MONTH));
jewishCalendar.setInIsrael(inIsrael);

if(jewishCalendar.hasCandleLighting() && currentTime.compareTo(getElevationAdjustedSunset()) >= 0) { //erev shabbos, YT or YT sheni and after shkiah
if (jewishCalendar.hasCandleLighting() && currentTime.compareTo(getElevationAdjustedSunset()) >= 0) { //erev shabbos, YT or YT sheni and after shkiah
return true;
}

if(jewishCalendar.isAssurBemelacha() && currentTime.compareTo(tzais) <= 0) { //is shabbos or YT and it is before tzais
return true;
}

return false;
}
//is shabbos or YT and it is before tzais
return jewishCalendar.isAssurBemelacha() && currentTime.compareTo(tzais) <= 0;
}

/**
* A generic utility method for calculating any <em>shaah zmanis</em> (temporal hour) based <em>zman</em> with the
Expand Down Expand Up @@ -1143,18 +1139,18 @@ public Date getShaahZmanisBasedZman(Date startOfDay, Date endOfDay, double hours
public double getPercentOfShaahZmanisFromDegrees(double degrees, boolean sunset) {
Date seaLevelSunrise = getSeaLevelSunrise();
Date seaLevelSunset = getSeaLevelSunset();
Date twilight = null;
if(sunset) {
Date twilight;
if (sunset) {
twilight = getSunsetOffsetByDegrees(GEOMETRIC_ZENITH + degrees);
} else {
twilight = getSunriseOffsetByDegrees(GEOMETRIC_ZENITH + degrees);
}
if(seaLevelSunrise == null || seaLevelSunset == null || twilight == null) {
if (seaLevelSunrise == null || seaLevelSunset == null || twilight == null) {
return Double.MIN_VALUE;
}
double shaahZmanis = (seaLevelSunset.getTime() - seaLevelSunrise.getTime()) / 12.0;
long riseSetToTwilight;
if(sunset) {
if (sunset) {
riseSetToTwilight = twilight.getTime() - seaLevelSunset.getTime();
} else {
riseSetToTwilight = seaLevelSunrise.getTime() - twilight.getTime();
Expand Down Expand Up @@ -1197,10 +1193,10 @@ public Date getHalfDayBasedZman(Date startOfHalfDay, Date endOfHalfDay, double h
return null;
}
long shaahZmanis = getHalfDayBasedShaahZmanis(startOfHalfDay, endOfHalfDay);
if(shaahZmanis == Long.MIN_VALUE) { //defensive, should not be needed
if (shaahZmanis == Long.MIN_VALUE) { //defensive, should not be needed
return null;
}
if(hours >= 0) { // forward from start a day
if (hours >= 0) { // forward from start a day
return getTimeOffset(startOfHalfDay, shaahZmanis * hours);
} else { // subtract from end of day
return getTimeOffset(endOfHalfDay, shaahZmanis * hours);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ public class HebrewDateFormatter {
* &#x05E9;&#x05D5;&#x05D1;&#x05D4;,&#x05E9;&#x05D9;&#x05E8;&#x05D4;,&#x05D4;&#x05D2;&#x05D3;&#x05D5;&#x05DC;,
* &#x05D7;&#x05D6;&#x05D5;&#x05DF;,&#x05E0;&#x05D7;&#x05DE;&#x05D5;"</code>
*/
private EnumMap<JewishCalendar.Parsha, String> hebrewParshaMap;
private final EnumMap<JewishCalendar.Parsha, String> hebrewParshaMap;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this variable can be final as it is setup in the constructor


/**
* Default constructor sets the {@link EnumMap}s of Hebrew and default transliterated parshiyos.
*/
public HebrewDateFormatter() {
transliteratedParshaMap = new EnumMap<JewishCalendar.Parsha, String>(JewishCalendar.Parsha.class);
transliteratedParshaMap = new EnumMap<>(JewishCalendar.Parsha.class);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of Java 7, the diamond operator <> does not need explicit types. See here: https://stackoverflow.com/a/5999744

transliteratedParshaMap.put(JewishCalendar.Parsha.NONE, "");
transliteratedParshaMap.put(JewishCalendar.Parsha.BERESHIS, "Bereshis");
transliteratedParshaMap.put(JewishCalendar.Parsha.NOACH, "Noach");
Expand Down Expand Up @@ -195,7 +195,7 @@ public HebrewDateFormatter() {
transliteratedParshaMap.put(JewishCalendar.Parsha.CHAZON, "Chazon");
transliteratedParshaMap.put(JewishCalendar.Parsha.NACHAMU, "Nachamu");

hebrewParshaMap = new EnumMap<JewishCalendar.Parsha, String>(JewishCalendar.Parsha.class);
hebrewParshaMap = new EnumMap<>(JewishCalendar.Parsha.class);
hebrewParshaMap.put(JewishCalendar.Parsha.NONE, "");
hebrewParshaMap.put(JewishCalendar.Parsha.BERESHIS, "\u05D1\u05E8\u05D0\u05E9\u05D9\u05EA");
hebrewParshaMap.put(JewishCalendar.Parsha.NOACH, "\u05E0\u05D7");
Expand Down Expand Up @@ -292,7 +292,7 @@ public boolean isLongWeekFormat() {
*/
public void setLongWeekFormat(boolean longWeekFormat) {
this.longWeekFormat = longWeekFormat;
if(longWeekFormat) {
if (longWeekFormat) {
weekFormat = new SimpleDateFormat("EEEE");
} else {
weekFormat = new SimpleDateFormat("EEE");
Expand Down Expand Up @@ -496,7 +496,7 @@ public String formatRoshChodesh(JewishCalendar jewishCalendar) {
if (!jewishCalendar.isRoshChodesh()) {
return "";
}
String formattedRoshChodesh = "";

int month = jewishCalendar.getJewishMonth();
if (jewishCalendar.getJewishDayOfMonth() == 30) {
if (month < JewishCalendar.ADAR || (month == JewishCalendar.ADAR && jewishCalendar.isJewishLeapYear())) {
Expand All @@ -509,7 +509,7 @@ public String formatRoshChodesh(JewishCalendar jewishCalendar) {
// This method is only about formatting, so we shouldn't make any changes to the params passed in...
jewishCalendar = (JewishCalendar) jewishCalendar.clone();
jewishCalendar.setJewishMonth(month);
formattedRoshChodesh = hebrewFormat ? hebrewHolidays[JewishCalendar.ROSH_CHODESH]
String formattedRoshChodesh = hebrewFormat ? hebrewHolidays[JewishCalendar.ROSH_CHODESH]
: transliteratedHolidays[JewishCalendar.ROSH_CHODESH];
formattedRoshChodesh += " " + formatMonth(jewishCalendar);
return formattedRoshChodesh;
Expand Down Expand Up @@ -637,18 +637,18 @@ public void setTransliteratedMonthList(String[] transliteratedMonths) {
*/
public String formatDayOfWeek(JewishDate jewishDate) {
if (hebrewFormat) {
if(isLongWeekFormat()) {
if (isLongWeekFormat()) {
return hebrewDaysOfWeek[jewishDate.getDayOfWeek() - 1];
} else {
if(jewishDate.getDayOfWeek() == 7) {
if (jewishDate.getDayOfWeek() == 7) {
return formatHebrewNumber(300);
} else {
return formatHebrewNumber(jewishDate.getDayOfWeek());
}
}
} else {
if(jewishDate.getDayOfWeek() == 7) {
if(isLongWeekFormat()) {
if (jewishDate.getDayOfWeek() == 7) {
if (isLongWeekFormat()) {
return getTransliteratedShabbosDayOfWeek();
} else {
return getTransliteratedShabbosDayOfWeek().substring(0,3);
Expand Down Expand Up @@ -897,7 +897,7 @@ public String formatDafYomiBavli(Daf daf) {
* @return the formatted daf.
*/
public String formatDafYomiYerushalmi(Daf daf) {
if(daf == null) {
if (daf == null) {
if (hebrewFormat) {
return Daf.getYerushalmiMasechtos()[39];
} else {
Expand Down Expand Up @@ -990,7 +990,7 @@ public String formatHebrewNumber(int number) {
int tens = number / 10;
if (number % 10 == 0) { // if evenly divisable by 10
if (!singleDigitNumber) {
if(isUseFinalFormLetters()) {
if (isUseFinalFormLetters()) {
sb.append(jTenEnds[tens]); // years like 5780 will end with a final form &#x05E3;
} else {
sb.append(jTens[tens]); // years like 5780 will end with a regular &#x05E4;
Expand Down
Loading
Loading