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

io.burt.jmespath.function.JoinFunction Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
package io.burt.jmespath.function;

import java.util.List;
import java.util.Iterator;

import io.burt.jmespath.Adapter;
import io.burt.jmespath.JmesPathType;

public class JoinFunction extends BaseFunction {
  public JoinFunction() {
    super(
      ArgumentConstraints.typeOf(JmesPathType.STRING),
      ArgumentConstraints.arrayOf(ArgumentConstraints.typeOf(JmesPathType.STRING))
    );
  }

  @Override
  protected  T callFunction(Adapter runtime, List> arguments) {
    T glue = arguments.get(0).value();
    T components = arguments.get(1).value();
    Iterator values = runtime.toList(components).iterator();
    if (values.hasNext()) {
      StringBuilder buffer = new StringBuilder();
      String glueString = runtime.toString(glue);
      buffer.append(runtime.toString(values.next()));
      while (values.hasNext()) {
        buffer.append(glueString);
        buffer.append(runtime.toString(values.next()));
      }
      return runtime.createString(buffer.toString());
    } else {
      return runtime.createString("");
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy