Created
November 6, 2013 09:43
-
-
Save palmerc/7333484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ChartItem getChartItem(int costType, int monthNumber, Map<Integer, Map<Integer, Integer>> mapAmounts){ | |
Map<Integer, Integer> mapValue = mapAmounts.get(monthNumber); | |
if(mapValue == null) | |
return null; | |
int year1 = 0, year2 = 0, value1 = 0, value2 = 0; | |
Iterator<Integer> itr = mapValue.keySet().iterator(); | |
while(itr.hasNext()){ | |
Integer year = (Integer) itr.next(); | |
Integer value = (Integer) mapValue.get(year); | |
if(year1 == 0){ | |
year1 = year; | |
value1 = value; | |
} | |
else if(year2 == 0){ | |
year2 = year; | |
value2 = value; | |
} | |
else{ | |
if(costType == CURRENT_YEAR_TYPE){ | |
if(year > year1 || year > year2){ | |
if(year1 < year2){ | |
year1 = year; | |
value1 = value; | |
} | |
else{ | |
year2 = year; | |
value2 = value; | |
} | |
} | |
} | |
else{ | |
if(year < year1 || year < year2){ | |
if(year1 > year2){ | |
year1 = year; | |
value1 = value; | |
} | |
else{ | |
year2 = year; | |
value2 = value; | |
} | |
} | |
} | |
} | |
} | |
int lessYear = 0, greaterYear = 0, lessYearValue = 0, greaterYearValue = 0; | |
if(year1 > year2){ | |
lessYear = year2; | |
lessYearValue = value2; | |
greaterYear = year1; | |
greaterYearValue = value1; | |
} | |
else{ | |
lessYear = year1; | |
lessYearValue = value1; | |
greaterYear = year2; | |
greaterYearValue = value2; | |
} | |
String monthName = DataManager.getShortMonthNameByNumber(monthNumber); | |
lessYear = (lessYear == 0) ? greaterYear - 1 : lessYear; | |
String hintLabelPrev = monthName + " " + Integer.toString(lessYear); | |
String hintLabelCurr = monthName + " " + Integer.toString(greaterYear); | |
ChartItem item = new ChartItem(); | |
item.setUnitName(UNIT_LABEL); | |
item.setMonthName(monthName); | |
item.setPrevYearValue(lessYearValue); | |
item.setCurrentYearValue(greaterYearValue); | |
item.setHintMonthLabelPrev(hintLabelPrev); | |
item.setHintMonthLabelCurr(hintLabelCurr); | |
return item; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment