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.virtusa.akura.student.controller.StudentAttendenceController.java
/** * get all days without special holidays and Saturday,Sunday for given Date range. map key contains date * and value contains AttendeceStatus object with default values(as absent day) * /*from w ww . j av a 2s . c o m*/ * @param from from date * @param to to date * @return map * @throws AkuraAppException when exception occurs */ private Map<String, AttendeceStatus> getDaysWithoutHolydays(Date from, Date to) throws AkuraAppException { Calendar calFrom = Calendar.getInstance(); Calendar calTo = Calendar.getInstance(); calFrom.setTime(from); calTo.setTime(to); List<Holiday> holidayList = commonService.findHolidayByYear(from, to); Map<String, AttendeceStatus> allDaysBetween = new TreeMap<String, AttendeceStatus>(); // to get name ex Sunday ,Monday .. DateFormatSymbols symbols = new DateFormatSymbols(); String[] weekDays = symbols.getWeekdays(); while (calFrom.before(calTo) || calFrom.equals(calTo)) { int dyaOfWeek = calFrom.get(Calendar.DAY_OF_WEEK); // remove weekends and special holidays if (dyaOfWeek != Calendar.SATURDAY && dyaOfWeek != Calendar.SUNDAY && !DateUtil.isHoliday(holidayList, calFrom.getTime())) { AttendeceStatus attSttus = new AttendeceStatus(); attSttus.setDay(weekDays[dyaOfWeek]); allDaysBetween.put(DateUtil.getFormatDate(calFrom.getTime()), attSttus); } calFrom.set(Calendar.DATE, calFrom.get(Calendar.DATE) + 1); } return allDaysBetween; }
From source file:GenAppStoreSales.java
private static void readSales(String periodTime, boolean restoreSales, boolean computeSales) throws IOException { countryLabels = new ArrayList<String>(); countryUnits = new ArrayList<ArrayList<Integer>>(); countryInAppLabels = new ArrayList<String>(); countryInAppUnits = new ArrayList<ArrayList<Integer>>(); int t = 0, periodDays = 0; boolean anotherDay = true; if (periodTime.equals("day")) periodDays = 1;// w w w .ja v a 2 s . c o m else if (periodTime.equals("week")) periodDays = 7; else if (periodTime.equals("month")) periodDays = rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); else if (periodTime.equals("year")) periodDays = rollCalendar.getActualMaximum(Calendar.DAY_OF_YEAR); else if (periodTime.equals("custom")) { while (rollCalendar.compareTo(customCalendar) > 0) { rollCalendar.add(Calendar.DATE, -1); periodDays++; } rollCalendar.add(Calendar.DATE, periodDays); } while (anotherDay) { String dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); String reportName = "S_D_" + appID + "_" + dateCode + ".txt"; File salesFile = new File(sourcePath + "/" + reportName); if (salesFile.isFile()) { String SKU, productCountry; int productUnits; boolean update; float productPrice; BufferedReader salesFileReader = new BufferedReader(new FileReader(sourcePath + "/" + reportName)); String line = salesFileReader.readLine(); // skips the first line while ((line = salesFileReader.readLine()) != null) { String[] columns = line.split("\t"); // SKU SKU = columns[2]; // Product Units if (columns[6].equals("7T")) update = true; else update = false; productUnits = Integer.parseInt(columns[7]); // Product Price productPrice = Float.parseFloat(columns[8]); // Country Code productCountry = columns[12]; // System.out.println("SKU " + SKU + " Units " + productUnits + " Country Code " + productCountry); if (SKU.equals(appSKU)) { if (periodTime.equals("day")) { dayUnits += productUnits; } if (computeSales) { totalUnits += productUnits; if (update) { totalUpdateUnits += productUnits; } } if (restoreSales) { int index = countryLabels.indexOf(productCountry); if (index < 0) { countryLabels.add(productCountry); countryUnits.add(new ArrayList<Integer>(Collections.nCopies(periodDays, 0))); countryUnits.get(countryUnits.size() - 1).set(t, productUnits); } else countryUnits.get(index).set(t, productUnits); } } else { if (periodTime.equals("day")) { dayINAPPUnits += productUnits; } if (computeSales) { totalInAppUnits += productUnits; } if (restoreSales) { int index = countryInAppLabels.indexOf(productCountry); if (index < 0) { countryInAppLabels.add(productCountry); countryInAppUnits.add(new ArrayList<Integer>(Collections.nCopies(periodDays, 0))); countryInAppUnits.get(countryInAppUnits.size() - 1).set(t, productUnits); } else countryInAppUnits.get(index).set(t, productUnits); } } } salesFileReader.close(); } if (periodTime.equals("day")) { anotherDay = false; } else if (periodTime.equals("week")) { if (rollCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) { anotherDay = false; } } else if (periodTime.equals("month")) { if (rollCalendar.get(Calendar.DAY_OF_MONTH) == 1) { anotherDay = false; } } else if (periodTime.equals("year")) { if (rollCalendar.get(Calendar.DAY_OF_YEAR) == 1) { anotherDay = false; } } else if (periodTime.equals("custom")) { if (rollCalendar.compareTo(customCalendar) <= 0) { anotherDay = false; } } rollCalendar.add(Calendar.DATE, -1); updateRollCalendar(); t++; } }
From source file:org.jfree.data.time.Week.java
/** * Returns the first millisecond of the week, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond of the week. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>./*from w w w .j av a 2 s . co m*/ */ @Override public long getFirstMillisecond(Calendar calendar) { Calendar c = (Calendar) calendar.clone(); c.clear(); c.set(Calendar.YEAR, this.year); c.set(Calendar.WEEK_OF_YEAR, this.week); c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); }
From source file:models.Schedule.java
private List<Integer> identifyNonDefaultUnits() { List<Integer> nonDefaultUnits = new ArrayList<Integer>(); if (!isDefaultRange(startMinute, endMinute, MINUTE_START, MINUTE_END)) { nonDefaultUnits.add(Calendar.MINUTE); }// ww w .j a va 2 s.co m if (!isDefaultRange(startHourOfDay, endHourOfDay, HOUR_OF_DAY_START, HOUR_OF_DAY_END)) { nonDefaultUnits.add(Calendar.HOUR_OF_DAY); } if (!isDefaultRange(startDayOfMonth, endDayOfMonth, DAY_OF_MONTH_START, DAY_OF_MONTH_END)) { nonDefaultUnits.add(Calendar.DAY_OF_MONTH); } if (!isDefaultRange(startDayOfWeek, endDayOfWeek, DAY_OF_WEEK_START, DAY_OF_WEEK_END)) { nonDefaultUnits.add(Calendar.DAY_OF_WEEK); } if (!isDefaultRange(startYear, endYear, YEAR_START, YEAR_END)) { nonDefaultUnits.add(Calendar.YEAR); } return nonDefaultUnits; }
From source file:CalendarUtils.java
/** * This constructs an Iterator that will start and stop over a date * range based on the focused date and the range style. For instance, * passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return * an Iterator that starts with Sunday, June 30, 2002 and ends with * Saturday, August 3, 2002.//from w ww. jav a 2 s .com */ public static Iterator getCalendarIterator(Calendar focus, int rangeStyle) { Calendar start = null; Calendar end = null; int startCutoff = Calendar.SUNDAY; int endCutoff = Calendar.SATURDAY; switch (rangeStyle) { case RANGE_MONTH_SUNDAY: case RANGE_MONTH_MONDAY: //Set start to the first of the month start = trunc(focus, Calendar.MONTH); //Set end to the last of the month end = (Calendar) start.clone(); end.add(Calendar.MONTH, 1); end.add(Calendar.DATE, -1); //Loop start back to the previous sunday or monday if (rangeStyle == RANGE_MONTH_MONDAY) { startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; } break; case RANGE_WEEK_SUNDAY: case RANGE_WEEK_MONDAY: case RANGE_WEEK_RELATIVE: case RANGE_WEEK_CENTER: //Set start and end to the current date start = trunc(focus, Calendar.DATE); end = trunc(focus, Calendar.DATE); switch (rangeStyle) { case RANGE_WEEK_SUNDAY: //already set by default break; case RANGE_WEEK_MONDAY: startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; break; case RANGE_WEEK_RELATIVE: startCutoff = focus.get(Calendar.DAY_OF_WEEK); endCutoff = startCutoff - 1; break; case RANGE_WEEK_CENTER: startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3; endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3; break; } break; default: throw new RuntimeException("The range style " + rangeStyle + " is not valid."); } if (startCutoff < Calendar.SUNDAY) { startCutoff += 7; } if (endCutoff > Calendar.SATURDAY) { endCutoff -= 7; } while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) { start.add(Calendar.DATE, -1); } while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) { end.add(Calendar.DATE, 1); } final Calendar startFinal = start; final Calendar endFinal = end; Iterator it = new Iterator() { Calendar spot = null; { spot = startFinal; spot.add(Calendar.DATE, -1); } public boolean hasNext() { return spot.before(endFinal); } public Object next() { if (spot.equals(endFinal)) { throw new NoSuchElementException(); } spot.add(Calendar.DATE, 1); return spot.clone(); } public void remove() { throw new UnsupportedOperationException(); } }; return it; }
From source file:com.alkacon.opencms.calendar.CmsCalendarMonthBean.java
/** * Returns the days of a month to display in a matrix, depending on the start day of the week.<p> * /*from w w w . jav a 2 s. com*/ * The month matrix starts with index "1" and uses 7 columns per row to display one week in a row. * The value returns null if no date should be shown at the current index position.<p> * * @param year the year of the month to display * @param month the month to display * @param calendarLocale the Locale for the calendar to determine the start day of the week * @return the days of a month to display in a matrix, depending on the start day of the week */ public Map getMonthDaysMatrix(int year, int month, Locale calendarLocale) { Map monthDays = new TreeMap(); Calendar startDay = new GregorianCalendar(year, month, 1); Calendar runDay = startDay; int index = 1; // calculate the start day of the week Calendar calendar = new GregorianCalendar(calendarLocale); int weekStart = calendar.getFirstDayOfWeek(); // create empty indexes before the first day of the month while (runDay.get(Calendar.DAY_OF_WEEK) != weekStart) { monthDays.put(new Integer(index), null); index++; if (weekStart == Calendar.SATURDAY) { weekStart = Calendar.SUNDAY; } else { weekStart++; } } // create the indexes for the month dates while (true) { monthDays.put(new Integer(index), runDay.clone()); // increase day to next day runDay.roll(Calendar.DAY_OF_MONTH, true); index++; if (runDay.get(Calendar.DAY_OF_MONTH) == 1) { // runDay has switched to the next month, stop loop break; } } // create empty indexes after the last day of the month int rest = (index - 1) % 7; if (rest > 0) { rest = 7 - rest; } for (int i = 0; i < rest; i++) { monthDays.put(new Integer(index), null); index++; } return monthDays; }
From source file:org.eevolution.form.VSCRP.java
public CategoryDataset createWeightDataset(Timestamp start, MResource r) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);//from w ww .j ava 2 s .c om gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id ) )From mpc_order mo Where ad_client_id=?", r.getAD_Client_ID()); // fjviejo e-evolution machineqty capacidad por el numero de maquinas // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID()); double dailyCapacity = DB.getSQLValue(null, "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID()); System.out.println("***** Capacidad diaria " + dailyCapacity); // e-evolution end double utilization = DB.getSQLValue(null, "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID()); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:org.jfree.data.time.Week.java
/** * Returns the last millisecond of the week, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the week. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>./* w w w .ja v a 2 s . c o m*/ */ @Override public long getLastMillisecond(Calendar calendar) { Calendar c = (Calendar) calendar.clone(); c.clear(); c.set(Calendar.YEAR, this.year); c.set(Calendar.WEEK_OF_YEAR, this.week + 1); c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis() - 1; }
From source file:DateUtil.java
/** * Returns an array of two strings yielding a textual representation of the * time under the current cursor when striding. Neither string will be null, * but either may be the empty ("") string. Typically, the second string will * be empty rather than the first, and will contain additional information * about the label, such as the the month when the days roll over into the * next month, or the day of the week. This method sets an internal marker * recording if current label has rolled past a period boundary, such as from * one week to the next or one year to the next, which is queryable via * {@link #isUnitChanged()}/*w w w .j a v a 2 s .c o m*/ * * @param p * The Period in which to format the output. * @return String[2], containing two description strings of the date/time. The * first string will be withing the Period <code>p</code>, and the * second is typically auxiliary information. */ public String[] getLabel(Period p) { String[] strings = new String[2]; int minute; int hour; int day; int month; int year; int dow; mUnitChange = false; switch (p) { case YEAR: strings[0] = "" + mCal.get(Calendar.YEAR); strings[1] = ""; break; case QUARTER: year = mCal.get(Calendar.YEAR); month = mCal.get(Calendar.MONTH); if (month >= 9) strings[0] = QUARTERS[3]; else if (month >= 6) strings[0] = QUARTERS[2]; else if (month >= 3) strings[0] = QUARTERS[1]; else strings[0] = QUARTERS[0]; strings[1] = ""; if (year != mBase.mYear) { strings[1] = "" + mCal.get(Calendar.YEAR); mUnitChange = true; } break; case MONTH: year = mCal.get(Calendar.YEAR); month = mCal.get(Calendar.MONTH); strings[0] = MONTHS[month]; if (year != mBase.mYear) { strings[1] = "" + mCal.get(Calendar.YEAR); mUnitChange = true; } else { strings[1] = ""; } break; case WEEK: case DAY: month = mCal.get(Calendar.MONTH); day = mCal.get(Calendar.DAY_OF_MONTH); strings[0] = "" + day; if (month != mBase.mMonth) { strings[1] = MONTHS[month]; mUnitChange = true; } else { dow = mCal.get(Calendar.DAY_OF_WEEK); strings[1] = DAYS[dow - 1]; if (dow == 1) mUnitChange = true; } break; case AMPM: case HOUR: day = mCal.get(Calendar.DAY_OF_MONTH); hour = mCal.get(Calendar.HOUR_OF_DAY); if (hour == 0) { strings[0] = "12a"; strings[1] = "midnight"; } else if (hour == 12) { strings[0] = "12p"; strings[1] = "noon"; } else if (hour > 11) { strings[0] = (hour - 12) + "p"; strings[1] = ""; } else { strings[0] = hour + "a"; strings[1] = ""; } if (day != mBase.mDay) { dow = mCal.get(Calendar.DAY_OF_WEEK); strings[0] = mCal.get(Calendar.MONTH) + 1 + "/" + day; strings[1] = DAYS[dow - 1]; mUnitChange = true; } break; case MINUTE: default: minute = mCal.get(Calendar.MINUTE); hour = mCal.get(Calendar.HOUR_OF_DAY); strings[0] = l2pad(minute); strings[1] = ""; if (hour != mBase.mHour) { if (hour == 0) { day = mCal.get(Calendar.DAY_OF_MONTH); dow = mCal.get(Calendar.DAY_OF_WEEK); strings[0] = mCal.get(Calendar.MONTH) + 1 + "/" + day; strings[1] = DAYS[dow - 1]; } else if (hour == 12) { strings[0] = "12"; strings[1] = "noon"; } else if (hour > 11) { strings[0] = (hour - 12) + "p"; } else { strings[0] = hour + "a"; } mUnitChange = true; } else break; } return strings; }
From source file:UserInterface.TMAnalystRole.TMAnaylstWorkAreaJPanel.java
private void generateGraph(Train selectedTrain) { ArrayList<TrainOffered> selectedTrainOfferedListWEEKDAYS = new ArrayList<>(); ArrayList<TrainOffered> selectedTrainOfferedListWEEKENDS = new ArrayList<>(); int days = (int) spnrRecord.getValue(); Date today = new Date(); Date olderThanToday = new Date(); olderThanToday.setTime(today.getTime() + (long) (-days) * 1000 * 60 * 60 * 24); long todayDate = (today.getTime()) / (1000 * 60 * 60 * 24); long olderDate = (olderThanToday.getTime()) / (1000 * 60 * 60 * 24); for (TrainOffered selectedTrainOffered : enterprise.getTrainsOfferedHistory().getTrainsOffered()) { if (selectedTrainOffered.getTrain().equals(selectedTrain)) { long selectedDate = (selectedTrainOffered.getDayOffered().getTime()) / (1000 * 60 * 60 * 24); if (selectedDate >= olderDate && selectedDate <= todayDate) { Calendar date = Calendar.getInstance(); date.setTime(selectedTrainOffered.getDayOffered()); if ((date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || ((date.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY))) { if (!selectedTrainOfferedListWEEKENDS.contains(selectedTrainOffered)) { selectedTrainOfferedListWEEKENDS.add(selectedTrainOffered); }// w ww . ja v a2 s. co m } else { if (!selectedTrainOfferedListWEEKDAYS.contains(selectedTrainOffered)) { selectedTrainOfferedListWEEKDAYS.add(selectedTrainOffered); } } } } } Map<TimeSlot.TimeSlotRange, Integer> weekendData = new HashMap<TimeSlot.TimeSlotRange, Integer>(); for (TrainOffered selectedTrainOfferedOnWeekend : selectedTrainOfferedListWEEKENDS) { for (TrainStatus rt : selectedTrainOfferedOnWeekend.getRunningTrains()) { if (weekendData.containsKey(rt.getTrainSchedule().getTimeSlot())) { Integer previousValue = weekendData.get(rt.getTrainSchedule().getTimeSlot()); weekendData.put(rt.getTrainSchedule().getTimeSlot(), previousValue + rt.getRunningCapacity()); } else { weekendData.put(rt.getTrainSchedule().getTimeSlot(), rt.getRunningCapacity()); } } } ArrayList<Integer> sortedWeekendData = new ArrayList<>(); if (weekendData.size() > 0) { for (TimeSlot.TimeSlotRange tsr : TimeSlot.TimeSlotRange.values()) { sortedWeekendData.add(weekendData.get(tsr)); } } Map<TimeSlot.TimeSlotRange, Integer> weekdayData = new HashMap<>(); for (TrainOffered selectedTrainOfferedOnWeekDays : selectedTrainOfferedListWEEKDAYS) { for (TrainStatus rt : selectedTrainOfferedOnWeekDays.getRunningTrains()) { if (weekdayData.containsKey(rt.getTrainSchedule().getTimeSlot())) { Integer previousValue = weekdayData.get(rt.getTrainSchedule().getTimeSlot()); weekdayData.put(rt.getTrainSchedule().getTimeSlot(), previousValue + rt.getRunningCapacity()); } else { weekdayData.put(rt.getTrainSchedule().getTimeSlot(), rt.getRunningCapacity()); } } } ArrayList<Integer> sortedWeekDayDataList = new ArrayList<>(); if (weekdayData.size() > 0) { for (TimeSlot.TimeSlotRange tsr : TimeSlot.TimeSlotRange.values()) { sortedWeekDayDataList.add(weekdayData.get(tsr)); } } CategoryDataset dataset; String series1 = "Weekdays"; String series2 = "Weekends"; String series3 = "Maximum Capcity"; DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); for (int i = 0; i < sortedWeekendData.size(); i++) { dataset1.addValue(Math.round(sortedWeekendData.get(i) / selectedTrainOfferedListWEEKENDS.size()), series2, TimeSlot.TimeSlotRange.values()[i].getValue()); } for (int i = 0; i < sortedWeekDayDataList.size(); i++) { // System.out.println("Key = " + entry.getKey().getValue() + ", Value = " + Math.round(entry.getValue()/selectedTrainOfferedListWEEKENDS.size())); dataset1.addValue(Math.round(sortedWeekDayDataList.get(i) / selectedTrainOfferedListWEEKDAYS.size()), series1, TimeSlot.TimeSlotRange.values()[i].getValue()); } for (int i = 0; i < 15; i++) { // System.out.println("Key = " + entry.getKey().getValue() + ", Value = " + Math.round(entry.getValue()/selectedTrainOfferedListWEEKENDS.size())); dataset1.addValue(selectedTrain.getTrainCapacity(), series3, TimeSlot.TimeSlotRange.values()[i].getValue()); } dataset = dataset1; final JFreeChart chart = ChartFactory.createLineChart( "Average Congestion of Train : " + selectedTrain.getTrainName(), // chart title "Time Slot", // domain axis label "Congestion Level", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); ChartFrame chartPanel = new ChartFrame("Line Chart of Train", chart); chartPanel.setSize(this.getWidth(), this.getHeight() + 200); chartPanel.setVisible(true); }