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

com.hubspot.jinjava.interpret.RenderResult Maven / Gradle / Ivy

The newest version!
package com.hubspot.jinjava.interpret;

import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class RenderResult {

  private final String output;
  private final Context context;
  private final List errors;

  public RenderResult(String output, Context context, List errors) {
    this.output = output;
    this.context = context;
    this.errors = errors;
  }

  public RenderResult(
    TemplateError fromException,
    Context context,
    List errors
  ) {
    this.output = "";
    this.context = context;
    this.errors =
      ImmutableList
        .builder()
        .add(fromException)
        .addAll(Optional.ofNullable(errors).orElse(Collections.emptyList()))
        .build();
  }

  public RenderResult(String result) {
    this.output = result;
    this.context = null;
    this.errors = Collections.emptyList();
  }

  public boolean hasErrors() {
    return !errors.isEmpty();
  }

  public List getErrors() {
    return errors;
  }

  public Context getContext() {
    return context;
  }

  public String getOutput() {
    return output;
  }

  public RenderResult withOutput(String newOutput) {
    return new RenderResult(newOutput, getContext(), getErrors());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy