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

hope.kola.contract.Variables Maven / Gradle / Ivy

There is a newer version: 1.1.2-RELEASE
Show newest version
package hope.kola.contract;

import com.squareup.javapoet.TypeSpec;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import java.util.LinkedHashSet;
import java.util.Set;

public class Variables {

  protected Set entries = new LinkedHashSet<>();

  public void build(final TypeSpec.Builder clzBuilder) {
    if (!hasEntries()) {
      // Nothing to do
      // res.addStatement("// NO variables define");
    } else {
      for (final Variable each : entries) {
        each.build(clzBuilder);
      }
    }
  }

  public Set entries() {
    return entries;
  }

  public boolean hasEntries() {
    return entries != null && !entries.isEmpty();
  }

  /**
   * (JAVA) add {@link Variable} to the list
   *
   * @param variable {@link Variable}
   */
  public void item(final Variable variable) {
    entries.add(variable);
  }

  /**
   * Construct a new Variable
   *
   * @param name name of the variable
   * @param consumer function to manipulate the Variable
   */
  public void item(final String name, @DelegatesTo(Variable.class) Closure consumer) {
    Variable variable = new Variable(name);
    consumer.setDelegate(variable);
    consumer.call();
    entries.add(variable);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy