[astro] Correcting some SAT finding and a blocking point (#8964)

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2020-11-08 21:09:08 +01:00 committed by GitHub
parent bb9a286167
commit 370c367bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -13,6 +13,7 @@
package org.openhab.binding.astro.internal.calc;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import org.openhab.binding.astro.internal.model.Eclipse;
@ -233,7 +234,7 @@ public class MoonCalc {
rounded = Math.floor(rounded) + riseMinute;
BigDecimal bd = new BigDecimal(Double.toString(rounded));
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.doubleValue();
}

View File

@ -49,7 +49,7 @@ public class SunZodiacCalc {
zodiacsByYear.put(year, zodiacs);
}
return zodiacs.stream().filter(z -> z.isValid(calendar)).findFirst();
return zodiacs != null ? zodiacs.stream().filter(z -> z.isValid(calendar)).findFirst() : Optional.empty();
}
/**

View File

@ -105,8 +105,12 @@ public class SunHandler extends AstroThingHandler {
public @Nullable ZonedDateTime getEventTime(SunPhaseName sunPhase, ZonedDateTime date, boolean begin) {
Range eventRange = getSunAt(date).getAllRanges().get(sunPhase);
Calendar cal = begin ? eventRange.getStart() : eventRange.getEnd();
return ZonedDateTime.ofInstant(cal.toInstant(), date.getZone());
if (eventRange != null) {
Calendar cal = begin ? eventRange.getStart() : eventRange.getEnd();
return ZonedDateTime.ofInstant(cal.toInstant(), date.getZone());
} else {
return null;
}
}
@Override

View File

@ -91,7 +91,11 @@ public class PropertyUtils {
Method m = instance.getClass().getMethod(toGetterString(propertyName), null);
Object result = m.invoke(instance, (Object[]) null);
if (nestedIndex + 1 < properties.length) {
return getPropertyValue(result, properties, nestedIndex + 1);
if (result != null) {
return getPropertyValue(result, properties, nestedIndex + 1);
} else {
throw new NullPointerException();
}
}
return result;
}