Because of the setters on private Calendar startDate, endDate; the SunPhase class is not thread safe. And since com.florianmski.suncalc.SunCalc which calls the setters is in a different package from com.florianmski.suncalc.models.SunPhase, the setter can't even be made package private for better encapsulation.
Perhaps we SunPhase should only house the the existing constructor's final variables:
private final Name name;
private final double startAngle, endAngle;
private final boolean startRise, endRise;
and then, once the date is known, we construct and return a new SunPhaseDay class once the date is specified in SunCalc#getPhases that includes:
private final Name name;
private final double startAngle, endAngle;
private final boolean startRise, endRise;
private final Calendar startDate, endDate;
Because of the setters on
private Calendar startDate, endDate;theSunPhaseclass is not thread safe. And sincecom.florianmski.suncalc.SunCalcwhich calls the setters is in a different package fromcom.florianmski.suncalc.models.SunPhase, the setter can't even be made package private for better encapsulation.Perhaps we
SunPhaseshould only house the the existing constructor's final variables:and then, once the date is known, we construct and return a new
SunPhaseDayclass once the date is specified inSunCalc#getPhasesthat includes: