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

io.vertx.codegen.doc.Text Maven / Gradle / Ivy

There is a newer version: 3.6.3
Show newest version
package io.vertx.codegen.doc;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * A structured text, it can be evaluated as a stream of tokens.
 *
 * @author Julien Viet
 */
public class Text {

  final String value;
  final List tokens;

  public Text(String value) {
    this.value = value;
    this.tokens = Token.tokenize(value);
  }

  private Text(String value, List tokens) {
    this.value = value;
    this.tokens = tokens;
  }

  /**
   * @return the text value
   */
  public String getValue() {
    return value;
  }

  /**
   * Returns a new text object with tokens mapped by the {@code mapper} function.
   *
   * @param mapping the mapping function
   * @return the new text object
   */
  public Text map(Function mapping) {
    return new Text(value, tokens.stream().map(mapping).collect(Collectors.toList()));
  }

  /**
   * @return the tokens of this comment
   */
  public List getTokens() {
    return tokens;
  }

  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (o instanceof Text) {
      Text that = (Text) o;
      return value.equals(that.value);
    }
    return false;
  }

  @Override
  public String toString() {
    return value;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy