public IntervalListMonth(ColumnGroup columnGroup) { super(columnGroup); intervalMap = new HashMap<Integer, Interval>(); Month firstMonth = columnGroup.getFirstMonthOfYear(); int monthIndex = firstMonth.getIndex(); Month[] months = Month.getAll(); for (int i = 0; i < months.length; i++) { Month month = months[monthIndex-1]; Interval interval = new Interval(Integer.toString(month.getIndex()), i); interval.setType(columnGroup.getIntervalSize()); this.add(interval); intervalMap.put(monthIndex-1, interval); monthIndex = Month.nextIndex(monthIndex); } }
for (Month m : Month.values()) { if (m.name().equals(A)) { //found } }
@Test public void testViewInitialization() { timeFrameEditor.init(TEN_DAYS, changeCommand); assertEquals(timeFrameView, timeFrameEditor.view); verify(timeFrameView).init(timeFrameEditor); verify(timeFrameView).clearFirstMonthSelector(); verify(timeFrameView, times(Month.values().length)).addFirstMonthItem(any(Month.class)); verify(timeFrameView).setSelectedFirstMonthIndex(Month.MARCH.getIndex() - 1); }
@Test public void monthIndex() { int expectedIndex = 1; for (Month month : Month.getAll()) { assertEquals(expectedIndex++, month.getIndex()); assertEquals(month, Month.getByIndex(month.getIndex())); } }
int firstMonthYear = columnGroup.getFirstMonthOfYear().getIndex(); int rest = Quarter.getPositionInQuarter(firstMonthYear, currentMonth + 1); c.add(Calendar.MONTH, rest * -1);
public IntervalListQuarter(ColumnGroup columnGroup) { super(columnGroup); intervalMap = new HashMap<Integer, Interval>(); Month firstMonth = columnGroup.getFirstMonthOfYear(); int monthIndex = firstMonth.getIndex(); for (int i = 0; i < 4; i++) { Quarter quarter = Quarter.getByIndex(i+1); Interval interval = new Interval((Integer.toString(quarter.getIndex())), i); interval.setType(columnGroup.getIntervalSize()); this.add(interval); for (int j = 0; j < 3; j++) { intervalMap.put(monthIndex-1, interval); monthIndex = Month.nextIndex(monthIndex); } } }
/** * Given a month (from 1 to 12) it calculates the ordinal within the quarter it belongs. * * @param firstMonthOfYear The first month of the year considered the first month of the first quarter. * @param targetMonth The month we want to evaluate. * @return The position (from 0 to 2) of the target within the quarter. */ public static int getPositionInQuarter(int firstMonthOfYear, int targetMonth) { int index = firstMonthOfYear; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { if (index == targetMonth) return j; index = Month.nextIndex(index); } } throw new RuntimeException("Month not found : " + targetMonth); } }
protected void initFirstMonthSelector() { view.clearFirstMonthSelector(); Month current = getFirstMonthOfYear(); Month[] entries = Month.values(); for (int i = 0; i < entries.length; i++) { Month entry = entries[i]; view.addFirstMonthItem(entry); if (current != null && current.equals(entry)) { view.setSelectedFirstMonthIndex(i); } } }
void onFirstMonthSelected() { Month month = Month.getByIndex(view.getSelectedFirstMonthIndex()+1); columnGroup.setFirstMonthOfYear(month); changeEvent.fire(new DataSetGroupDateChanged(columnGroup)); } }
/** * @return index of month from 1 (JANUARY) to 12 (DECEMBER) */ public int getIndex() { return ordinal() + 1; }
final Integer getDaysPerMonth(final Month month, final int year) { if (isLeapYear(year) && month.equals(Month.FEBRUARY)) { return DAYS_PER_MONTH.get(month) + 1; } return DAYS_PER_MONTH.get(month); } final boolean isLeapYear(final int year) { return (0 == year % 4); }
@Test public void testNullInitialization() { timeFrameEditor.init(UNDEFINED, changeCommand); assertEquals(timeFrameView, timeFrameEditor.view); verify(timeFrameView).init(timeFrameEditor); verify(timeFrameView).clearFirstMonthSelector(); verify(timeFrameView, times(Month.values().length)).addFirstMonthItem(any(Month.class)); verify(timeFrameView).setSelectedFirstMonthIndex(Month.JANUARY.getIndex() - 1); }
@Test public void monthIndex() { int expectedIndex = 1; for (Month month : Month.getAll()) { assertEquals(expectedIndex++, month.getIndex()); assertEquals(month, Month.getByIndex(month.getIndex())); } }
int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 1000); startDate.setMonth(firstMonthOfYear.getIndex()-1); startDate.setDate(1); startDate.setHours(0); int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 100); startDate.setMonth(firstMonthOfYear.getIndex()-1); startDate.setDate(1); startDate.setHours(0); int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 10); startDate.setMonth(firstMonthOfYear.getIndex()-1); startDate.setDate(1); startDate.setHours(0); int firstMonth = firstMonthOfYear.getIndex()-1; int yearInc = 0; if (TimeMode.BEGIN.equals(timeMode)) yearInc = month < firstMonth ? -1 : 0; int firstMonth = Quarter.getQuarterFirstMonth(firstMonthOfYear.getIndex(), month + 1)-1; int yearInc = 0; int monthInc = 3;
/** * Given a month (from 1 to 12) it calculates the ordinal within the quarter it belongs. * * @param firstMonthOfYear The first month of the year considered the first month of the first quarter. * @param targetMonth The month we want to evaluate. * @return The position (from 0 to 2) of the target within the quarter. */ public static int getPositionInQuarter(int firstMonthOfYear, int targetMonth) { int index = firstMonthOfYear; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { if (index == targetMonth) return j; index = Month.nextIndex(index); } } throw new RuntimeException("Month not found : " + targetMonth); } }
protected void initFirstMonthSelector() { view.clearFirstMonthSelector(); Month current = getFirstMonthOfYear(); Month[] entries = Month.values(); for (int i = 0; i < entries.length; i++) { Month entry = entries[i]; view.addFirstMonthItem(entry); if (current != null && current.equals(entry)) { view.setSelectedFirstMonthIndex(i); } } }
void onFirstMonthSelected() { Month month = Month.getByIndex(view.getSelectedFirstMonthIndex()+1); columnGroup.setFirstMonthOfYear(month); changeEvent.fire(new DataSetGroupDateChanged(columnGroup)); } }
/** * @return index of month from 1 (JANUARY) to 12 (DECEMBER) */ public int getIndex() { return ordinal() + 1; }
@Test public void testViewInitialization() { timeFrameEditor.init(TEN_DAYS, changeCommand); assertEquals(timeFrameView, timeFrameEditor.view); verify(timeFrameView).init(timeFrameEditor); verify(timeFrameView).clearFirstMonthSelector(); verify(timeFrameView, times(Month.values().length)).addFirstMonthItem(any(Month.class)); verify(timeFrameView).setSelectedFirstMonthIndex(Month.MARCH.getIndex() - 1); }