캘린더를 렌더링하는 Grid가 있으며 이벤트가 포함 된 ArrayList<CalendarEventEntity>
이 제공됩니다. 이러한 이벤트는 그리드에서 강조 표시되어야합니다. 나는 내 자신에 의해 그리드를 채우기 위해 가지고캘린더 그리드를 채우는 알고리즘을 개선하는 방법은 무엇입니까?
나는 이런 일이 :
for(loop through the days of the month){
Calendar eventDate = event.getDate();
// look for the events in the calendar that matchs this day
for(CalendarEventEntity event : events) {
// if there are events in this specific day
if(eventDate.get(Calendar.YEAR) == calendarMonth.get(Calendar.YEAR) &&
eventDate.get(Calendar.MONTH) == calendarMonth.get(Calendar.MONTH) &&
eventDate.get(Calendar.DAY_OF_MONTH) == dayIndex) {
// highlight it!!!
}
}
}
이 잘 작동을하지만 너무 느리다. 그래서 나는 그것을 속도를 내고 싶다! 나는 내부 for
전에이 추가 :
// ignore dates which does not make part of this month or year
if(eventDate.get(Calendar.YEAR) < calendarMonth.get(Calendar.YEAR) ||
eventDate.get(Calendar.MONTH) < calendarMonth.get(Calendar.MONTH) ||
eventDate.get(Calendar.DAY_OF_MONTH) != DateIdx) {
continue;
}
// stop when processing dates which are higher than this month or year
if(eventDate.get(Calendar.YEAR) > calendarMonth.get(Calendar.YEAR) ||
eventDate.get(Calendar.MONTH) > calendarMonth.get(Calendar.MONTH)
|| eventDate.get(Calendar.DAY_OF_MONTH) != DateIdx) {
break;
}
하고 빠르게 경우 만들었지 만, 그것은 여전히 너무 느리다. 이 알고리즘을 어떻게 향상시킬 수 있습니까?
저는 HashMap에 대해 생각해 보지 않았습니다. 나는 그것이 정말로 도움이되는지보기 위해 지금 시도해 볼 것입니다. 그러나, 나는 너무 복잡하게 만들고 싶지 않고, HashMap을 사용하는 것은 다음과 같을 것이다 :'HashMap>'. –
Cristian
저는 여러 번 그 패턴을 사용했습니다. 멀티 스레드 응용 프로그램을 사용하는 경우 충돌을 피하기 위해 HashMap에 대한 모든 액세스를 동기화해야합니다. –