Fixed DateSortedList
This commit is contained in:
@@ -8,4 +8,9 @@ public class EventList extends DateSortedList<Event> {
|
||||
public long getDateByItem(Event item) {
|
||||
return item.getEndDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reversed() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,30 +11,29 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
|
||||
public T getPast(int index) {
|
||||
if (split < 0)
|
||||
sort();
|
||||
if (index >= split)
|
||||
if (index >= this.sizePast())
|
||||
throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d past events found!", index, split));
|
||||
if (reversed())
|
||||
index = sizePast() - index - 1;
|
||||
index += sizeUpcoming();
|
||||
return this.get(index);
|
||||
}
|
||||
|
||||
public T getUpcoming(int index) {
|
||||
if (split < 0)
|
||||
sort();
|
||||
index += split;
|
||||
if (index >= this.size())
|
||||
if (index >= this.sizeUpcoming())
|
||||
throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d upcoming events found!", index-split, this.size()-split));
|
||||
if (reversed())
|
||||
index = sizeUpcoming() - index - 1;
|
||||
if (!reversed())
|
||||
index += this.sizePast();
|
||||
return this.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
//if (split < 0)
|
||||
// sort();
|
||||
if (split < 0)
|
||||
sort();
|
||||
if (reversed())
|
||||
index = size() - index - 1;
|
||||
index = size() - 1 - index;
|
||||
return super.get(index);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user