Fixed DateSortedList

This commit is contained in:
Caesar2011
2018-10-24 00:14:25 +02:00
parent 9d5416ab9b
commit 14cf917ec8
3 changed files with 19 additions and 9 deletions

View File

@@ -8,4 +8,9 @@ public class EventList extends DateSortedList<Event> {
public long getDateByItem(Event item) {
return item.getEndDate();
}
@Override
public boolean reversed() {
return false;
}
}

View File

@@ -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);
}