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

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

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

import tech.jhipster.lite.shared.error.domain.Assert;

public record MandatoryReplacer(ElementReplacer replacer, String updatedValue) {
  public MandatoryReplacer {
    Assert.notNull("replacer", replacer);
    Assert.notNull("updatedValue", updatedValue);
  }

  public String apply(String content) {
    if (replacer.dontNeedReplacement(content, updatedValue())) {
      return content;
    }

    if (replacer().notMatchIn(content)) {
      throw new UnknownCurrentValueException(replacer().searchMatcher(), content);
    }

    return replacer().replacement().apply(content, updatedValue());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy