private void checkAlarms ( final ZonedDateTime TIME ) { 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 ( Clock . this , 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 ( Clock . this , alarm ) ) ; alarm . executeCommand ( ) ; } } break ; case HOURLY : if ( ALARM_TIME . getMinute ( ) == TIME . getMinute ( ) && ALARM_TIME . getSecond ( ) == TIME . getSecond ( ) ) { if ( alarm . isArmed ( ) ) { fireAlarmEvent ( new AlarmEvent ( Clock . this , 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 ( Clock . this , 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 ( Clock . this , alarm ) ) ; alarm . executeCommand ( ) ; } } break ; } } for ( Alarm alarm : alarmsToRemove ) { removeAlarm ( alarm ) ; } }
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 .