List of usage examples for java.util GregorianCalendar getMaximum
@Override public int getMaximum(int field)
GregorianCalendar
instance. From source file:Main.java
public static void main(String[] args) { GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // get maximum for day_of_month int min = cal.getMaximum(GregorianCalendar.DAY_OF_MONTH); System.out.println("Maximum:" + min); // get maximum for YEAR min = cal.getMaximum(GregorianCalendar.YEAR); System.out.println("Maximum:" + min); }
From source file:de.randi2.services.ChartsServiceImpl.java
@Override @Transactional(propagation = Propagation.REQUIRED) public ChartData generateRecruitmentChart(Trial trial) { trial = trialDao.refresh(trial);//from ww w . j a va 2 s. com 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; }