All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.tree.variable.CollectionPointer Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
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);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy