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

tech.jhipster.lite.module.domain.replacement.TextNeedleAfterReplacer Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package tech.jhipster.lite.module.domain.replacement;

import java.util.function.BiFunction;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.shared.error.domain.Assert;

public record TextNeedleAfterReplacer(ReplacementCondition condition, String text) implements ElementReplacer {
  public TextNeedleAfterReplacer {
    Assert.notNull("condition", condition);
    Assert.notBlank("text", text);
  }

  @Override
  public boolean notMatchIn(String content) {
    Assert.notNull("content", content);

    return !content.contains(text());
  }

  @Override
  public BiFunction replacement() {
    return (content, replacement) -> {
      String replacementBlock = JHipsterModule.LINE_BREAK + replacement;
      return content.replaceAll(this.text, this.text + replacementBlock);
    };
  }

  @Override
  public String searchMatcher() {
    return text();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy