List of usage examples for java.util GregorianCalendar getMinimum
@Override public int getMinimum(int field)
GregorianCalendar
instance. From source file:Main.java
public static void main(String[] args) { GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // get minimum for day_of_month int min = cal.getMinimum(GregorianCalendar.DAY_OF_MONTH); System.out.println("Minimum:" + min); // get minimum for YEAR min = cal.getMinimum(GregorianCalendar.YEAR); System.out.println("Minimum:" + min); }
From source file:gr.abiss.calipso.controller.AbstractServiceBasedRestController.java
@RequestMapping(value = "reports", produces = { "application/json" }, method = RequestMethod.GET) @ResponseBody//from ww w.j a v a 2 s. com //@ApiOperation(value = "reports", httpMethod = "GET") public Page<ReportDataSet> getReportDatasets( @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @RequestParam(value = "size", required = false, defaultValue = "10") Integer size, @RequestParam(value = "properties", required = false, defaultValue = "id") String sort, @RequestParam(value = "direction", required = false, defaultValue = "ASC") String direction, @RequestParam(value = "timeUnit", required = false, defaultValue = "DAY") TimeUnit timeUnit, @RequestParam(value = "dateField", required = false, defaultValue = "createdDate") String dateField, @RequestParam(value = "period", required = false) String period, @RequestParam(value = "reportType", required = false) String reportType) { if (StringUtils.isBlank(period)) { GregorianCalendar now = new GregorianCalendar(); StringBuffer buff = new StringBuffer(); if (timeUnit.equals(TimeUnit.DAY)) { buff.append(now.get(Calendar.MONTH)).append('/'); } period = buff.append(now.get(Calendar.YEAR)).toString(); } LOGGER.info("getReportDatasets, timeUnit: " + timeUnit + ", dateField: " + dateField + ", period: " + period + ", reportName: " + reportType); GregorianCalendar start = null; GregorianCalendar end = null; if (timeUnit.equals(TimeUnit.DAY)) { String[] monthYear = period.split("/"); start = new GregorianCalendar(Integer.parseInt(monthYear[1]), Integer.parseInt(monthYear[0]) - 1, 0); end = new GregorianCalendar(Integer.parseInt(monthYear[1]), Integer.parseInt(monthYear[0]) - 1, 0); end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH)); } else { start = new GregorianCalendar(Integer.parseInt(period), 0, 0); end = new GregorianCalendar(Integer.parseInt(period), 11, 0); end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH)); } start.set(Calendar.HOUR_OF_DAY, start.getMinimum(Calendar.HOUR_OF_DAY)); start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE)); start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND)); start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND)); end.set(Calendar.HOUR_OF_DAY, end.getMinimum(Calendar.HOUR_OF_DAY)); end.set(Calendar.MINUTE, end.getMinimum(Calendar.MINUTE)); end.set(Calendar.SECOND, end.getMinimum(Calendar.SECOND)); end.set(Calendar.MILLISECOND, end.getMinimum(Calendar.MILLISECOND)); Map<String, String[]> paramsMap = request.getParameterMap(); LOGGER.info("getReportDatasets, timeUnit: " + timeUnit + ", dateField: " + dateField + ", dateFrom: " + start + ", dateTo: " + end + ", reportName: " + reportType); Pageable pageable = buildPageable(page, size, sort, direction, paramsMap); Page<ReportDataSet> results = this.service.getReportDatasets(pageable, timeUnit, dateField, start.getTime(), end.getTime(), reportType); LOGGER.info("getReportDatasets returning " + results.getTotalElements()); return results; }
From source file:de.randi2.services.ChartsServiceImpl.java
@Override @Transactional(propagation = Propagation.REQUIRED) public ChartData generateRecruitmentChart(Trial trial) { trial = trialDao.refresh(trial);/* w w w . j a v a 2 s . c o m*/ ChartData tempD = new ChartData(); int plannedSubjects = 0; for (TreatmentArm arm : trial.getTreatmentArms()) { plannedSubjects += arm.getPlannedSubjects(); } List<double[]> data = new ArrayList<double[]>(); GregorianCalendar startDate = trial.getStartDate(); GregorianCalendar endDate = trial.getEndDate(); int monthStart = startDate.get(GregorianCalendar.MONTH); int monthEnd = endDate.get(GregorianCalendar.MONTH); ArrayList<String> xL = new ArrayList<String>(); for (int year = startDate.get(GregorianCalendar.YEAR); year <= endDate .get(GregorianCalendar.YEAR); year++) { if (year != endDate.get(GregorianCalendar.YEAR)) { monthEnd = startDate.getMaximum(GregorianCalendar.MONTH); } else { monthEnd = endDate.get(GregorianCalendar.MONTH); } for (int month = monthStart; month <= monthEnd; month++) { double[] values = new double[2]; values[0] = 0; if (data.size() > 0) { values[1] = data.get(data.size() - 1)[1]; } else values[1] = 0; for (TrialSubject subject : trial.getSubjects()) { if (subject.getCreatedAt().get(GregorianCalendar.MONTH) == month && subject.getCreatedAt().get(GregorianCalendar.YEAR) == year) { values[1] = values[1] + 1.0; } } xL.add((month + 1) + "." + year); data.add(values); } monthStart = startDate.getMinimum(GregorianCalendar.MONTH); } for (int i = 1; i <= data.size(); i++) { data.get(i - 1)[0] = i * (plannedSubjects / data.size()); } tempD.setXLabels(xL); tempD.setData(data); return tempD; }