org.snapscript.tree.variable.CollectionPointer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.variable;
import static org.snapscript.core.Reserved.PROPERTY_LENGTH;
import java.util.Collection;
import org.snapscript.core.Scope;
import org.snapscript.core.Value;
import org.snapscript.core.ValueType;
public class CollectionPointer implements VariablePointer {
private final ObjectPointer pointer;
private final String name;
public CollectionPointer(String name) {
this.pointer = new ObjectPointer(name);
this.name = name;
}
@Override
public Value get(Scope scope, Collection left) {
if(name.equals(PROPERTY_LENGTH)) {
int length = left.size();
return ValueType.getConstant(length);
}
return pointer.get(scope, left);
}
}