List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:com.frameworkset.platform.sanylog.action.CounterController.java
/**?? */// www. j a v a 2 s.c o m public @ResponseBody(datatype = "json") String statisticOperCounterImmediately() { Calendar today = Calendar.getInstance(); String todayTime = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN); String week = String.valueOf(today.get(Calendar.WEEK_OF_YEAR)); week = todayTime.substring(0, 4) + "-" + week; Calendar startDate = Calendar.getInstance(); int offset = startDate.get(Calendar.DAY_OF_WEEK); startDate.add(Calendar.DAY_OF_MONTH, offset - (offset * 2 - 1)); String startTime = DateUtils.format(startDate.getTime(), DateUtils.ISO8601_DATE_PATTERN); TransactionManager tm = new TransactionManager(); try { tm.begin(TransactionManager.RW_TRANSACTION); // counterManager.deleteOperCounterByWeek(week); counterManager.staticOperCounterByWeek(startTime, todayTime, week); // counterManager.deleteOperCounterByDay(todayTime); counterManager.staticOperCounterByDay(todayTime); // counterManager.deleteOperCounterByMonth(todayTime.substring(0, 7)); counterManager.staticOperCounterByMonth(todayTime.substring(0, 7)); // counterManager.deleteOperCounterByYear(todayTime.substring(0, 4)); counterManager.staticOperCounterByYear(todayTime.substring(0, 4)); tm.commit(); return "success"; } catch (Exception e) { e.printStackTrace(); return e.getLocalizedMessage(); } finally { tm.release(); } }
From source file:com.projity.contrib.calendar.ContribIntervals.java
void eliminateWeekdayDuplicates(boolean weekDays[]) { Calendar cal = calendarInstance(); for (Iterator i = iterator(); i.hasNext();) { //a more optimized version can be found DateSpan interval = (DateSpan) i.next(); cal.setTimeInMillis(interval.getStart()); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK) - 1; // remove any days which correspond to a selected week day for (int d = 0; d < 7; d++) { if (weekDays[d] && d == dayOfWeek) { i.remove();/*from w w w . j a v a 2 s. c o m*/ } } } }
From source file:com.liferay.ide.server.remote.AbstractRemoteServerPublisher.java
protected void addToZip(IPath path, IResource resource, ZipOutputStream zip, boolean adjustGMTOffset) throws IOException, CoreException { switch (resource.getType()) { case IResource.FILE: ZipEntry zipEntry = new ZipEntry(path.toString()); zip.putNextEntry(zipEntry);/*from www . j a v a 2s . c om*/ InputStream contents = ((IFile) resource).getContents(); if (adjustGMTOffset) { TimeZone currentTimeZone = TimeZone.getDefault(); Calendar currentDt = new GregorianCalendar(currentTimeZone, Locale.getDefault()); // Get the Offset from GMT taking current TZ into account int gmtOffset = currentTimeZone.getOffset(currentDt.get(Calendar.ERA), currentDt.get(Calendar.YEAR), currentDt.get(Calendar.MONTH), currentDt.get(Calendar.DAY_OF_MONTH), currentDt.get(Calendar.DAY_OF_WEEK), currentDt.get(Calendar.MILLISECOND)); zipEntry.setTime(System.currentTimeMillis() + (gmtOffset * -1)); } try { IOUtils.copy(contents, zip); } finally { contents.close(); } break; case IResource.FOLDER: case IResource.PROJECT: IContainer container = (IContainer) resource; IResource[] members = container.members(); for (IResource res : members) { addToZip(path.append(res.getName()), res, zip, adjustGMTOffset); } } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.exams.RoomSearchDA.java
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DynaValidatorForm roomSearchForm = (DynaValidatorForm) form; // date//from w w w.j a v a2 s . co m Calendar searchDate = Calendar.getInstance(); Integer day = new Integer((String) roomSearchForm.get("day")); Integer month = new Integer((String) roomSearchForm.get("month")); Integer year = new Integer((String) roomSearchForm.get("year")); request.setAttribute("day", day.toString()); request.setAttribute("month", month.toString()); request.setAttribute("year", year.toString()); searchDate.set(Calendar.YEAR, year.intValue()); searchDate.set(Calendar.MONTH, month.intValue() - 1); searchDate.set(Calendar.DAY_OF_MONTH, day.intValue()); if (searchDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { ActionError actionError = new ActionError("error.sunday"); ActionErrors actionErrors = new ActionErrors(); actionErrors.add("error.sunday", actionError); saveErrors(request, actionErrors); return prepare(mapping, form, request, response); } // exam start time Calendar searchStartTime = Calendar.getInstance(); Integer startHour = new Integer((String) roomSearchForm.get("beginningHour")); Integer startMinute = new Integer((String) roomSearchForm.get("beginningMinute")); request.setAttribute("beginningHour", startHour.toString()); request.setAttribute("beginningMinute", startMinute.toString()); searchStartTime.set(Calendar.HOUR_OF_DAY, startHour.intValue()); searchStartTime.set(Calendar.MINUTE, startMinute.intValue()); searchStartTime.set(Calendar.SECOND, 0); // exam end time Calendar searchEndTime = Calendar.getInstance(); Integer endHour = new Integer((String) roomSearchForm.get("endHour")); Integer endMinute = new Integer((String) roomSearchForm.get("endMinute")); request.setAttribute("endHour", endHour.toString()); request.setAttribute("endMinute", endMinute.toString()); searchEndTime.set(Calendar.HOUR_OF_DAY, endHour.intValue()); searchEndTime.set(Calendar.MINUTE, endMinute.intValue()); searchEndTime.set(Calendar.SECOND, 0); if (searchStartTime.after(searchEndTime)) { ActionError actionError = new ActionError("error.timeSwitched"); ActionErrors actionErrors = new ActionErrors(); actionErrors.add("error.timeSwitched", actionError); saveErrors(request, actionErrors); return prepare(mapping, form, request, response); } int dayOfWeekInt = searchDate.get(Calendar.DAY_OF_WEEK); DiaSemana dayOfWeek = new DiaSemana(dayOfWeekInt); List<InfoRoom> availableInfoRoom = null; availableInfoRoom = SpaceUtils.allocatableSpace(YearMonthDay.fromCalendarFields(searchDate), YearMonthDay.fromCalendarFields(searchDate), HourMinuteSecond.fromCalendarFields(searchStartTime), HourMinuteSecond.fromCalendarFields(searchEndTime), dayOfWeek, null, null, false); String sdate = roomSearchForm.get("day") + "/" + roomSearchForm.get("month") + "/" + roomSearchForm.get("year"); String startTime = roomSearchForm.get("beginningHour") + ":" + roomSearchForm.get("beginningMinute"); String endTime = roomSearchForm.get("endHour") + ":" + roomSearchForm.get("endMinute"); request.setAttribute(PresentationConstants.DATE, sdate); request.setAttribute(PresentationConstants.START_TIME, startTime); request.setAttribute(PresentationConstants.END_TIME, endTime); Integer exam = null; Integer normal = null; List<InfoRoom> newAvailableInfoRoom = new ArrayList<InfoRoom>(); if (availableInfoRoom != null && !availableInfoRoom.isEmpty()) { try { exam = new Integer((String) roomSearchForm.get("exam")); } catch (NumberFormatException ex) { // the user didn't speciefy a exam minimum capacity } try { normal = new Integer((String) roomSearchForm.get("normal")); } catch (NumberFormatException ex) { // the user didn't speciefy a normal minimum capacity } if (normal != null || exam != null) { Iterator<InfoRoom> iter = availableInfoRoom.iterator(); while (iter.hasNext()) { InfoRoom elem = iter.next(); if (!((normal != null && elem.getCapacidadeNormal().intValue() < normal.intValue()) || (exam != null && elem.getCapacidadeExame().intValue() < exam.intValue()))) { newAvailableInfoRoom.add(elem); } } } else { newAvailableInfoRoom = availableInfoRoom; } } if (newAvailableInfoRoom != null && !newAvailableInfoRoom.isEmpty()) { Collections.sort(newAvailableInfoRoom, new BeanComparator("nome")); String[] availableRoomId = new String[newAvailableInfoRoom.size()]; Iterator<InfoRoom> iter = newAvailableInfoRoom.iterator(); int i = 0; while (iter.hasNext()) { InfoRoom elem = iter.next(); availableRoomId[i] = elem.getExternalId().toString(); } request.setAttribute(PresentationConstants.AVAILABLE_ROOMS_ID, availableRoomId); } request.setAttribute(PresentationConstants.AVAILABLE_ROOMS, newAvailableInfoRoom); return mapping.findForward("showRooms"); }
From source file:org.ambraproject.BaseTest.java
/** * Helper method to compare dates. This compares down to the minute, and checks that the seconds are within 1, since * rounding can occur when storing to an hsql db * * @param actual - the date from mysql to compare * @param expected - the date from topaz to compare *///from ww w .ja v a 2s.c o m protected static void assertMatchingDates(Date actual, Date expected) { if (actual == null || expected == null) { assertTrue(actual == null && expected == null, "one date was null and the other wasn't"); } else { Calendar actualCal = new GregorianCalendar(); actualCal.setTime(actual); Calendar expectedCal = new GregorianCalendar(); expectedCal.setTime(expected); assertEquals(actualCal.get(Calendar.YEAR), expectedCal.get(Calendar.YEAR), "Dates didn't have matching years"); assertEquals(actualCal.get(Calendar.MONTH), expectedCal.get(Calendar.MONTH), "dates didn't have matching months"); assertEquals(actualCal.get(Calendar.DAY_OF_MONTH), expectedCal.get(Calendar.DAY_OF_MONTH), "dates didn't have matching days of month"); assertEquals(actualCal.get(Calendar.DAY_OF_WEEK), expectedCal.get(Calendar.DAY_OF_WEEK), "dates didn't have matching days of week"); assertEquals(actualCal.get(Calendar.HOUR), expectedCal.get(Calendar.HOUR), "dates didn't have matching hours"); assertEquals(actualCal.get(Calendar.MINUTE), expectedCal.get(Calendar.MINUTE), "dates didn't have matching minutes"); int secondMin = expectedCal.get(Calendar.SECOND) - 1; int secondMax = expectedCal.get(Calendar.SECOND) + 1; int actualSecond = actualCal.get(Calendar.SECOND); assertTrue(secondMin <= actualSecond && actualSecond <= secondMax, "date didn't have correct second; expected something in [" + secondMin + "," + secondMax + "]; but got " + actualSecond); } }
From source file:com.ozpathway.sw.erms.webapp.action.schedule.ScheduleBean.java
public void addSampleEntries(ActionEvent event) { if (model == null) return;/* w ww . j a va 2 s .com*/ Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(model.getSelectedDate()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); calendar.set(Calendar.HOUR_OF_DAY, 14); DefaultScheduleEntry entry1 = new DefaultScheduleEntry(); // every entry in a schedule must have a unique id entry1.setId(RandomStringUtils.randomNumeric(32)); entry1.setStartTime(calendar.getTime()); calendar.add(Calendar.MINUTE, 45); entry1.setEndTime(calendar.getTime()); entry1.setTitle("Test MyFaces schedule component"); entry1.setSubtitle("my office"); entry1.setDescription("We need to get this thing out of the sandbox ASAP"); model.addEntry(entry1); DefaultScheduleEntry entry2 = new DefaultScheduleEntry(); entry2.setId(RandomStringUtils.randomNumeric(32)); // entry2 overlaps entry1 calendar.add(Calendar.MINUTE, -20); entry2.setStartTime(calendar.getTime()); calendar.add(Calendar.HOUR, 2); entry2.setEndTime(calendar.getTime()); entry2.setTitle("Show schedule component to boss"); entry2.setSubtitle("my office"); entry2.setDescription("Convince him to get time to thoroughly test it"); model.addEntry(entry2); DefaultScheduleEntry entry3 = new DefaultScheduleEntry(); entry3.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.DATE, 1); calendar.set(Calendar.HOUR_OF_DAY, 9); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); entry3.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 17); entry3.setEndTime(calendar.getTime()); entry3.setTitle("Thoroughly test schedule component"); model.addEntry(entry3); DefaultScheduleEntry entry4 = new DefaultScheduleEntry(); entry4.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.MONTH, -1); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); calendar.set(Calendar.HOUR_OF_DAY, 11); entry4.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 14); entry4.setEndTime(calendar.getTime()); entry4.setTitle("Long lunch"); model.addEntry(entry4); DefaultScheduleEntry entry5 = new DefaultScheduleEntry(); entry5.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.MONTH, 2); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 1); entry5.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 5); entry5.setEndTime(calendar.getTime()); entry5.setTitle("Fishing trip"); model.addEntry(entry5); // Let's add a zero length entry... DefaultScheduleEntry entry6 = new DefaultScheduleEntry(); calendar.setTime(model.getSelectedDate()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); calendar.set(Calendar.HOUR_OF_DAY, 16); entry6.setId(RandomStringUtils.randomNumeric(32)); entry6.setStartTime(calendar.getTime()); entry6.setEndTime(calendar.getTime()); entry6.setTitle("Zero length entry"); entry6.setDescription("Is only rendered when the 'renderZeroLengthEntries' attribute is 'true'"); model.addEntry(entry6); // And also an allday event DefaultScheduleEntry entry7 = new DefaultScheduleEntry(); entry7.setId(RandomStringUtils.randomNumeric(32)); entry7.setTitle("All day event"); entry7.setSubtitle("This event renders as an all-day event"); entry7.setAllDay(true); model.addEntry(entry7); model.refresh(); }
From source file:org.kuali.mobility.events.controllers.CalendarController.java
@RequestMapping(value = "/month", method = RequestMethod.GET) public String month(HttpServletRequest request, Model uiModel, @RequestParam(required = false) String date) { User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat my = new SimpleDateFormat("yyyyMM"); Calendar selectedDate = Calendar.getInstance(); try {/*from w ww.j a v a 2 s .co m*/ if (date != null) { selectedDate.setTime(my.parse(date)); } } catch (ParseException e) { } try { Filter filter = (Filter) request.getSession().getAttribute("calendar.event.filterId"); MonthViewEvents monthEvents = calendarEventOAuthService.retrieveMonthEvents(user.getUserId(), selectedDate.getTime(), filter != null ? filter.getFilterId() : null); uiModel.addAttribute("viewData", monthEvents.getViewData()); uiModel.addAttribute("appData", monthEvents.getAppData()); int days = selectedDate.getActualMaximum(Calendar.DATE); Calendar startDate = (Calendar) selectedDate.clone(); startDate.set(Calendar.DATE, selectedDate.getActualMinimum(Calendar.DATE)); days += startDate.get(Calendar.DAY_OF_WEEK) - 1; Calendar endDate = (Calendar) selectedDate.clone(); endDate.set(Calendar.DATE, selectedDate.getActualMaximum(Calendar.DATE)); days += 7 - endDate.get(Calendar.DAY_OF_WEEK); startDate.set(Calendar.DAY_OF_WEEK, 1); Map<String, MobileDayOfMonth> daysInMonth = new LinkedHashMap<String, MobileDayOfMonth>(); uiModel.addAttribute("selectedDate", sdf.format(selectedDate.getTime())); for (int i = 0; i < days; i++) { MobileDayOfMonth mobileDayOfMonth = new MobileDayOfMonth(startDate.get(Calendar.DATE)); mobileDayOfMonth.setCurrentMonth(startDate.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH)); if (!mobileDayOfMonth.isCurrentMonth()) { mobileDayOfMonth.setBeforeCurrentMonth( startDate.get(Calendar.MONTH) < selectedDate.get(Calendar.MONTH)); } mobileDayOfMonth.setMonthYear(my.format(startDate.getTime())); mobileDayOfMonth.setDayOfWeek(startDate.get(Calendar.DAY_OF_WEEK)); daysInMonth.put(sdf.format(startDate.getTime()), mobileDayOfMonth); startDate.add(Calendar.DATE, 1); } for (Iterator iterator = monthEvents.getEvents().entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, List<CalendarViewEvent>> entry = (Map.Entry<String, List<CalendarViewEvent>>) iterator .next(); MobileDayOfMonth dayInMonth = daysInMonth.get(entry.getKey()); dayInMonth.setHasEvents(true); dayInMonth.setEvents(entry.getValue()); } uiModel.addAttribute("events", daysInMonth); Calendar previousCalendar = (Calendar) selectedDate.clone(); previousCalendar.set(Calendar.DATE, 1); previousCalendar.getTime(); previousCalendar.add(Calendar.MONTH, -1); Calendar nextCalendar = (Calendar) selectedDate.clone(); nextCalendar.set(Calendar.DATE, 1); nextCalendar.getTime(); nextCalendar.add(Calendar.MONTH, 1); uiModel.addAttribute("previousMonth", my.format(previousCalendar.getTime())); uiModel.addAttribute("nextMonth", my.format(nextCalendar.getTime())); uiModel.addAttribute("monthYear", my.format(selectedDate.getTime())); uiModel.addAttribute("today", sdf.format(new Date())); uiModel.addAttribute("filter", filter); } catch (PageLevelException pageLevelException) { uiModel.addAttribute("message", pageLevelException.getMessage()); return "calendar/message"; } return "calendar/month"; }
From source file:com.krawler.common.util.SchedulingUtilities.java
public static Date calculateEndDate(Date sDate, String duration, int[] NonWorkDays, String[] CmpHoliDays, String userid) throws ParseException, ServiceException { Date dt = new Date(); java.text.SimpleDateFormat sdfLong = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String edate = ""; Calendar c = Calendar.getInstance(); dt = sDate;/* ww w.jav a2 s. c om*/ double d = getDurationInDays(duration); c.setTime(dt); if (d > 0) { c.add(Calendar.DATE, (int) (d - 1)); } else { c.add(Calendar.DATE, (int) d); } Date nDate = dt; int flag = 0; int nwd = nonWorkingDays(nDate, c.getTime(), NonWorkDays, CmpHoliDays); while (nwd != 0) { nDate = c.getTime(); if (nwd == 1 && flag == 0) { c.add(Calendar.DATE, nwd); flag = 1; } else { c.add(Calendar.DATE, nwd - 1); } nwd = nonWorkingDays(nDate, c.getTime(), NonWorkDays, CmpHoliDays); } dt = c.getTime(); edate = sdfLong.format(dt); if (Arrays.binarySearch(NonWorkDays, (c.get(Calendar.DAY_OF_WEEK) - 1)) > -1) { edate = getNextWorkingDay(edate, NonWorkDays, CmpHoliDays); } dt = sdfLong.parse(edate); return dt; }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.AddBookingRoomViewParamsController.java
@Override public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { Map map = new HashMap<String, Object>(); int filterGroup = Integer.parseInt(request.getParameter("filterGroup")); String filterDate = request.getParameter("filterDate"); if (filterDate.compareTo("") == 0) filterDate = null;/*from w w w .j a v a 2 s. co m*/ int repType = Integer.parseInt(request.getParameter("repType")); int repCount = Integer.parseInt(request.getParameter("repCount")); String date = request.getParameter("date"); String startStr = request.getParameter("startTime"); String endStr = request.getParameter("endTime"); GregorianCalendar cal = BookingRoomUtils.getCalendar(startStr); boolean collisions = false; //reservations in not visible time period if (repCount > 0) { GregorianCalendar nextS = BookingRoomUtils.getCalendar(startStr); GregorianCalendar nextE = BookingRoomUtils.getCalendar(endStr); List<Reservation> coll = BookingRoomUtils.getCollisions(reservationDao, repCount, repType, nextS, nextE); map.put("collisionsInNext", coll); map.put("collisionsInNextCount", coll.size()); if (coll.size() > 0) collisions = true; } //reservations in currently visible time period cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); GregorianCalendar weekStart = BookingRoomUtils.getCalendar(BookingRoomUtils.getDate(cal) + " 00:00:00"); GregorianCalendar weekEnd = (GregorianCalendar) weekStart.clone(); weekEnd.add(Calendar.DAY_OF_YEAR, 7); weekEnd.add(Calendar.SECOND, -1); map.put("reservations", reservationDao.getReservationsBetween(weekStart, weekEnd, filterDate, filterGroup)); map.put("timerange", date + " " + BookingRoomUtils.getHoursAndMinutes(startStr) + " - " + BookingRoomUtils.getHoursAndMinutes(endStr)); String displayed = String.format( messageSource.getMessage("bookRoom.displayed.week", null, RequestContextUtils.getLocale(request)), BookingRoomUtils.getDate(weekStart), BookingRoomUtils.getDate(weekEnd)); boolean filtered = false; if (filterDate != null) {//filter of date filtered = true; displayed = messageSource.getMessage("bookRoom.displayed.day", null, RequestContextUtils.getLocale(request)) + " " + filterDate; } if (filterGroup > 0) { filtered = true; displayed += (filterDate == null ? "," : " and") + " " + messageSource.getMessage("bookRoom.displayed.group", null, RequestContextUtils.getLocale(request)) + " " + getResearchGroup(filterGroup).getTitle(); } if (filtered) {//we must verify that there are no reservations in selected range GregorianCalendar start = BookingRoomUtils.getCalendar(startStr); GregorianCalendar end = BookingRoomUtils.getCalendar(endStr); List<Reservation> coll = reservationDao.getReservationsBetween(start, end); if (coll.size() > 0) { //if the collision exists collisions = true; map.put("collisions", coll); map.put("collisionsCount", coll.size()); } } map.put("displayed", displayed); map.put("collisionsExist", (collisions) ? "1" : "0"); /* -- JSP can get this from params object -- map.put("repCount", repCount); map.put("repType", repType); map.put("group", group); map.put("date", date);*/ map.put("startTime", BookingRoomUtils.getHoursAndMinutes(startStr).replaceAll(":", "")); map.put("endTime", BookingRoomUtils.getHoursAndMinutes(endStr).replaceAll(":", "")); map.put("loggedUser", personDao.getLoggedPerson()); GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); return map; }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
/** * Generate the histogram buckets based on the time frame requested and the interval. This will * add an entry for each 'slot' or 'bucket' in the histogram, setting the count to 0. * @param rval// w w w. j a v a2 s .c om * @param from * @param to * @param interval */ public static <T extends HistogramDataPoint, K> Map<K, T> generateHistogramSkeleton(HistogramBean<T> rval, DateTime from, DateTime to, HistogramIntervalType interval, Class<T> dataType, Class<K> keyType) { Map<K, T> index = new HashMap<>(); Calendar fromCal = from.toGregorianCalendar(); Calendar toCal = to.toGregorianCalendar(); switch (interval) { case day: fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case hour: fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case minute: fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case month: fromCal.set(Calendar.DAY_OF_MONTH, 1); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case week: fromCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; default: break; } while (fromCal.before(toCal)) { String label = formatDateWithMillis(fromCal); T point; try { point = dataType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } point.setLabel(label); rval.addDataPoint(point); if (keyType == String.class) { index.put((K) label, point); } else { index.put((K) new Long(fromCal.getTimeInMillis()), point); } switch (interval) { case day: fromCal.add(Calendar.DAY_OF_YEAR, 1); break; case hour: fromCal.add(Calendar.HOUR_OF_DAY, 1); break; case minute: fromCal.add(Calendar.MINUTE, 1); break; case month: fromCal.add(Calendar.MONTH, 1); break; case week: fromCal.add(Calendar.WEEK_OF_YEAR, 1); break; default: break; } } return index; }