Мой вопрос касается 100 тыс. Записей и их dateList, итерация занимает так много времени. Есть ли способ повторить намного быстрее в Java?
public class TestIteration {
public static void main(String[] args) {
List<LocalDate> returnList = getDatesList();
// `returnList` will have `[2018-03-14, 2018-03-15, 2018-03-16, 2018-03-17, 2018-03-18, 2018-03-19, 2018-03-20, 2018-03-21, ...]`
Employee e = new Employee();
for(int i=0;i<100000;i++) {
// parent loop that will run for 100k records
for(LocalDate returnDate : returnList) {
// list of dates, need to iterate all dates and set in emp obj along with other setters
e.setValue(i);
e.setDate(returnDate);
}
}
}
private static List<LocalDate> getDatesList(){
LocalDate fromDays = LocalDate.parse("2018-03-14");
LocalDate toDays = LocalDate.parse("2018-12-24");
String checkDays = "1234567";
Long range = ChronoUnit.DAYS.between(fromDays, toDays);
System.out.println("range>>"+range);
List<LocalDate> list = Stream.iterate(fromDays, d->d.plusDays(1)).limit(range+1)
.collect(Collectors.toList());
System.out.println("dtlist>>"+list);
String dayOfDate;
List<LocalDate> dateList = new ArrayList();
for(LocalDate d : list) {
dayOfDate = String.valueOf(d.getDayOfWeek().getValue());
if(checkDays.contains(dayOfDate)) {
dateList.add(d);
}
}
return dateList;
}
}