use of eu.hansolo.tilesfx.events.AlarmEvent in project tilesfx by HanSolo.
the class Tile method checkAlarms.
/**
* Calling this method will check the current time against all Alarm
* objects in alarms. The Alarm object will fire events in case the
* time is after the alarm time.
* @param TIME
*/
private void checkAlarms(final ZonedDateTime TIME) {
if (null == alarmsToRemove) {
alarmsToRemove = new ArrayList<>();
}
alarmsToRemove.clear();
for (Alarm alarm : alarms) {
final ZonedDateTime ALARM_TIME = alarm.getTime();
switch(alarm.getRepetition()) {
case ONCE:
if (TIME.isAfter(ALARM_TIME)) {
if (alarm.isArmed()) {
fireAlarmEvent(new AlarmEvent(alarm));
alarm.executeCommand();
}
alarmsToRemove.add(alarm);
}
break;
case HALF_HOURLY:
if ((ALARM_TIME.getMinute() == TIME.getMinute() || ALARM_TIME.plusMinutes(30).getMinute() == TIME.getMinute()) && ALARM_TIME.getSecond() == TIME.getSecond()) {
if (alarm.isArmed()) {
fireAlarmEvent(new AlarmEvent(alarm));
alarm.executeCommand();
}
}
break;
case HOURLY:
if (ALARM_TIME.getMinute() == TIME.getMinute() && ALARM_TIME.getSecond() == TIME.getSecond()) {
if (alarm.isArmed()) {
fireAlarmEvent(new AlarmEvent(alarm));
alarm.executeCommand();
}
}
break;
case DAILY:
if (ALARM_TIME.getHour() == TIME.getHour() && ALARM_TIME.getMinute() == TIME.getMinute() && ALARM_TIME.getSecond() == TIME.getSecond()) {
if (alarm.isArmed()) {
fireAlarmEvent(new AlarmEvent(alarm));
alarm.executeCommand();
}
}
break;
case WEEKLY:
if (ALARM_TIME.getDayOfWeek() == TIME.getDayOfWeek() && ALARM_TIME.getHour() == TIME.getHour() && ALARM_TIME.getMinute() == TIME.getMinute() && ALARM_TIME.getSecond() == TIME.getSecond()) {
if (alarm.isArmed()) {
fireAlarmEvent(new AlarmEvent(alarm));
alarm.executeCommand();
}
}
break;
}
}
for (Alarm alarm : alarmsToRemove) {
removeAlarm(alarm);
}
}
Aggregations