my request for help is kinda weird. I'll try to be short.
I have this line where i parse a schedule of Ex. 18:00-19:00 ; 22:00-23:00 The schedule 18:00 to 19:00 is one object and the other 22:00 to 23:00 is seperated by ";". Which mean you can add infinite schedules.
Now i parse this line using:
Arrays.asList(schedule.replaceAll("\\s", "").split(";")).forEach(s -> _schedules.add(new ScheduleCalendar(Integer.parseInt(s.split("-")[0].split(":")[0]), Integer.parseInt(s.split("-")[0].split(":")[1]), Integer.parseInt(s.split("-")[1].split(":")[0]), Integer.parseInt(s.split("-")[1].split(":")[1]))));
And i use this class
public static class ScheduleCalendar
{
private final Calendar[] _calendar = new Calendar[2];
public ScheduleCalendar(final int startingHour, final int startingMinute, final int endingHour, final int endingMinute)
{
final Calendar starting = Calendar.getInstance();
starting.set(Calendar.HOUR_OF_DAY, startingHour);
starting.set(Calendar.MINUTE, startingMinute);
starting.set(Calendar.SECOND, 0);
starting.set(Calendar.MILLISECOND, 0);
_calendar[0] = starting;
final Calendar ending = Calendar.getInstance();
ending.set(Calendar.HOUR_OF_DAY, endingHour);
ending.set(Calendar.MINUTE, endingMinute);
ending.set(Calendar.SECOND, 0);
ending.set(Calendar.MILLISECOND, 0);
_calendar[1] = ending;
}
public boolean isBefore(final ScheduleCalendar schedule)
{
return false;
}
public Calendar[] getCalendars()
{
return _calendar;
}
public boolean isNow()
{
return _calendar[0].getTimeInMillis() > System.currentTimeMillis() && _calendar[1].getTimeInMillis() < System.currentTimeMillis();
}
}
and finally store in
private final List<ScheduleCalendar> _schedules = new ArrayList<>();
Now i want to make a method which retrieve the closest schedule or active if is possible. Is there any fancy and fast way using java 8-16 to reproduce this code without having to write so long code? Any library maybe or so?