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

marcel.lang.dynamic.DynamicList Maven / Gradle / Ivy

package marcel.lang.dynamic;

import marcel.lang.DynamicObject;

import java.util.ArrayList;
import java.util.List;

public class DynamicList extends DynamicCollection implements DynamicIndexable {
  public DynamicList(List value) {
    super(value);
  }

  @Override
  public DynamicObject getAt(Object key) {
    return key instanceof Integer ? DynamicObject.of(getValue().get((Integer) key)) : super.getAt(key);
  }

  @Override
  public DynamicObject putAt(Object key, Object value) {
    return key instanceof Integer ? DynamicObject.of(getValue().set((Integer) key, value)) : super.getAt(key);
  }

  @Override
  List newEmptyInstance() {
    return new ArrayList();
  }

  @Override
  public int size() {
    return value.size();
  }

  @Override
  public DynamicObject invokeMethod(String name, Object... args) {
    try {
      return super.invokeMethod(name, args);
    } catch (MissingMethodException e) {
      return invokeMethod(List.class, name, args);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy