Major update

- Fix major bug causing storing elements at a given index to crash
This commit is contained in:
Gabriel Tofvesson 2016-12-06 11:14:48 +04:00
parent 04fc48e406
commit 5796fc3c87
2 changed files with 13 additions and 4 deletions

View File

@ -233,4 +233,8 @@ public class Async<T> {
* @param millis Milliseconds to delay. * @param millis Milliseconds to delay.
*/ */
public static void sleep(long millis){ sleep(millis, 0); } public static void sleep(long millis){ sleep(millis, 0); }
public static void iSleep(long millis, int micros){ try{ Thread.sleep(millis, micros); } catch(Exception ignored) {} }
public static void iSleep(long millis){ iSleep(millis, 0); }
} }

View File

@ -161,6 +161,7 @@ public class ShiftingList<E> implements List<E> {
entries = new Object[1]; entries = new Object[1];
} }
@Override
public int indexOf(Object o){ public int indexOf(Object o){
for(int i = 0; i<pop; ++i) for(int i = 0; i<pop; ++i)
if(entries[i].equals(o)) return i; if(entries[i].equals(o)) return i;
@ -204,6 +205,10 @@ public class ShiftingList<E> implements List<E> {
}else if(j+1==entries.length) return; // Found all populated entries }else if(j+1==entries.length) return; // Found all populated entries
} }
/**
* Prepares entry array for population of new values.
* @param accountFor New values to account for (in pop variable hasn't been updated).
*/
protected void preparePopulate(int accountFor){ protected void preparePopulate(int accountFor){
if(accountFor+pop>entries.length) adaptLoad(accountFor); // If new elements exceed limit, adapt load if(accountFor+pop>entries.length) adaptLoad(accountFor); // If new elements exceed limit, adapt load
if(accountFor>entries.length) return; // No need to delete elements if new values exceed limit if(accountFor>entries.length) return; // No need to delete elements if new values exceed limit
@ -220,17 +225,17 @@ public class ShiftingList<E> implements List<E> {
public E set(int index, E element) { public E set(int index, E element) {
if(index > pop) return null; if(index > pop) return null;
E e = get(index); E e = get(index);
entries[index] = element; entries[index] = element==null?empty:element;
return e; return e;
} }
@Override @Override
public void add(int index, E element) { public void add(int index, E element) {
if(index>=entries.length || index<0 || contains(element)) return; if(index<0 || contains(element)) return;
Object o = element==null?empty:element; Object o = element==null?empty:element;
pop = pop==maxSize?pop:pop+1; pop = pop==maxSize?pop:pop+1;
if(pop==entries.length) adaptLoad(); adaptLoad();
if(index==entries.length-1){ if((index>=entries.length?index=Math.min(entries.length-1, pop):index)==entries.length-1){
entries[index] = o; entries[index] = o;
return; return;
} }