public Entry getExtremeForDateRange( Calendar start, Calendar stop, StatIndex stat, boolean isMax) { ArrayList<Entry> entryList = new ArrayList<Entry>(); this.statIndex = stat; double extremeValue = 0; Entry extremeEntry = null; if (!isMax) { extremeValue = 9999; } // make the dates inclusive start.add(Calendar.DATE, -1); stop.add(Calendar.DATE, 1); for (Entry e : entries) { if (e.date().after(start) && e.date().before(stop)) { if (statIndex == StatIndex.MAX_TEMP && e.maxTemp() != null) { if (isMax && e.maxTemp() >= extremeValue || !isMax && e.maxTemp() <= extremeValue) { extremeValue = e.maxTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.MIN_TEMP && e.minTemp() != null) { if (isMax && e.minTemp() >= extremeValue || !isMax && e.minTemp() <= extremeValue) { extremeValue = e.minTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.AVG_TEMP && e.avgTemp() != null) { if (isMax && e.avgTemp() >= extremeValue || !isMax && e.avgTemp() <= extremeValue) { extremeValue = e.avgTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.AVG_TEMP_DEPART && e.departTemp() != null) { if (isMax && e.departTemp() >= extremeValue || !isMax && e.departTemp() <= extremeValue) { extremeValue = e.departTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.PRECIP && e.precip() != null) { if (isMax && e.precip() >= extremeValue || !isMax && e.precip() <= extremeValue) { extremeValue = e.precip(); extremeEntry = e; } } else if (statIndex == StatIndex.SNOWFALL && e.snowfall() != null) { if (isMax && e.snowfall() >= extremeValue || !isMax && e.snowfall() <= extremeValue) { extremeValue = e.snowfall(); extremeEntry = e; } } else if (statIndex == StatIndex.SNOW_DEPTH && e.snowDepth() != null) { if (isMax && e.snowDepth() >= extremeValue || !isMax && e.snowDepth() <= extremeValue) { extremeValue = e.snowDepth(); extremeEntry = e; } } // end if } // end if } // end for return extremeEntry; }
public Entry getExtremeForDate(Calendar date, StatIndex stat, boolean isMax) { this.statIndex = stat; double extremeValue = 0; Entry extremeEntry = null; if (!isMax) { extremeValue = 9999; } for (Entry e : entries) { if (e.month() == date.get(Calendar.MONTH) && e.day() == date.get(Calendar.DATE) && e.year() < date.get(Calendar.YEAR)) { if (statIndex == StatIndex.MAX_TEMP && e.maxTemp() != null) { if (isMax && e.maxTemp() >= extremeValue || !isMax && e.maxTemp() <= extremeValue) { extremeValue = e.maxTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.MIN_TEMP && e.minTemp() != null) { if (isMax && e.minTemp() >= extremeValue || !isMax && e.minTemp() <= extremeValue) { extremeValue = e.minTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.AVG_TEMP && e.avgTemp() != null) { if (isMax && e.avgTemp() >= extremeValue || !isMax && e.avgTemp() <= extremeValue) { extremeValue = e.avgTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.AVG_TEMP_DEPART && e.departTemp() != null) { if (isMax && e.departTemp() >= extremeValue || !isMax && e.departTemp() <= extremeValue) { extremeValue = e.departTemp(); extremeEntry = e; } } else if (statIndex == StatIndex.PRECIP && e.precip() != null) { if (isMax && e.precip() >= extremeValue || !isMax && e.precip() <= extremeValue) { extremeValue = e.precip(); extremeEntry = e; } } else if (statIndex == StatIndex.SNOWFALL && e.snowfall() != null) { if (isMax && e.snowfall() >= extremeValue || !isMax && e.snowfall() <= extremeValue) { extremeValue = e.snowfall(); extremeEntry = e; } } else if (statIndex == StatIndex.SNOW_DEPTH && e.snowDepth() != null) { if (isMax && e.snowDepth() >= extremeValue || !isMax && e.snowDepth() <= extremeValue) { extremeValue = e.snowDepth(); extremeEntry = e; } } // end if } // end if } // end for return extremeEntry; }
private double avg(ArrayList<Entry> entryList) { double sum = 0; numOfValues = entryList.size(); if (statIndex == StatIndex.MAX_TEMP) { for (Entry e : entryList) { if (e.maxTemp() == null) { numOfValues--; } else { sum += e.maxTemp(); } } } else if (statIndex == StatIndex.MIN_TEMP) { for (Entry e : entryList) { if (e.minTemp() == null) { numOfValues--; } else { sum += e.minTemp(); } } } else if (statIndex == StatIndex.AVG_TEMP) { for (Entry e : entryList) { if (e.avgTemp() == null) { numOfValues--; } else { sum += e.avgTemp(); } } } else if (statIndex == StatIndex.AVG_TEMP_DEPART) { for (Entry e : entryList) { if (e.departTemp() == null) { numOfValues--; } else { sum += e.departTemp(); } } } else if (statIndex == StatIndex.PRECIP) { for (Entry e : entryList) { if (e.precip() == null) { numOfValues--; } else { sum += e.precip(); } } } else if (statIndex == StatIndex.SNOWFALL) { for (Entry e : entryList) { if (e.snowfall() == null) { numOfValues--; } else { sum += e.snowfall(); } } } else if (statIndex == StatIndex.SNOW_DEPTH) { for (Entry e : entryList) { if (e.snowDepth() == null) { numOfValues--; } else { sum += e.snowDepth(); } } } return sum / numOfValues; }