org.snapscript.tree.collection.ListValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.collection;
import java.util.List;
import org.snapscript.core.Value;
import org.snapscript.core.convert.ProxyWrapper;
public class ListValue extends Value {
private final ProxyWrapper wrapper;
private final Integer index;
private final List list;
public ListValue(ProxyWrapper wrapper, List list, int index) {
this.wrapper = wrapper;
this.index = index;
this.list = list;
}
@Override
public Class getType() {
return Object.class;
}
@Override
public Object getValue(){
Object value = list.get(index);
if(value != null) {
return wrapper.fromProxy(value);
}
return value;
}
@Override
public void setValue(Object value){
Object proxy = wrapper.toProxy(value);
int length = list.size();
for(int i = length; i <= index; i++) {
list.add(null);
}
list.set(index, proxy);
}
@Override
public String toString() {
return String.valueOf(list);
}
}