long now = System.currentTimeMillis();
long nextTime = Long.MAX_VALUE;
Profile nextProfile = null;
for (Profile p : profiles) {
Schedule s = p.getSchedule();
if (p.isEnabled() && (s != null)) {
long o = s.getNextOccurrence(now);
if (nextTime > o) {
nextTime = o;
nextProfile = p;
}
}