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

tech.tablesaw.columns.strings.StringColumnFormatter Maven / Gradle / Ivy

There is a newer version: 0.43.1
Show newest version
package tech.tablesaw.columns.strings;

import java.util.function.Function;

public class StringColumnFormatter {

  private final Function formatter;
  private String missingString = "";

  public StringColumnFormatter() {
    this.formatter = null;
  }

  public StringColumnFormatter(Function formatFunction) {
    this.formatter = formatFunction;
  }

  public StringColumnFormatter(Function formatFunction, String missingString) {
    this.formatter = formatFunction;
    this.missingString = missingString;
  }

  public String format(String value) {

    if (StringColumnType.missingValueIndicator().equals(value)) {
      return missingString;
    }
    if (formatter == null) {
      return value;
    }
    return formatter.apply(value);
  }

  @Override
  public String toString() {
    return "StringColumnFormatter{"
        + "format="
        + formatter
        + ", missingString='"
        + missingString
        + '\''
        + '}';
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy