Class UniqueNameValidator

java.lang.Object
net.mcreator.ui.validation.validators.UniqueNameValidator
All Implemented Interfaces:
Validator
Direct Known Subclasses:
ModElementNameValidator

public class UniqueNameValidator extends Object implements Validator
While serving as a wrapper for the main component validator (if specified), a unique name validator also checks if that component provides a non-empty identifier that has no duplicates in the given elements list.
  • Constructor Details

    • UniqueNameValidator

      public UniqueNameValidator(String name, Supplier<String> uniqueNameGetter, Supplier<Stream<String>> otherNames, Validator extraValidator)
      Parameters:
      name - The text used to describe the purpose of the holder.
      uniqueNameGetter - Supplier to get unique name from the holder's text.
      otherNames - Supplier of names of other elements in the same list. Those must all be unique names.
      extraValidator - The main validator for the holder.
    • UniqueNameValidator

      public UniqueNameValidator(String name, Supplier<String> uniqueNameGetter, Supplier<Stream<String>> otherNames, List<String> forbiddenNames, Validator extraValidator)
      Parameters:
      name - The text used to describe the purpose of the holder.
      uniqueNameGetter - Supplier to get unique name from the holder's text.
      otherNames - Supplier of names of other elements in the same list. Those must all be unique names.
      forbiddenNames - List of strings that must not be used as a name, e.g. names of built-in properties.
      extraValidator - The main validator for the holder.
  • Method Details

    • setIsPresentOnList

      public UniqueNameValidator setIsPresentOnList(boolean isPresentOnList)
      Use this method to define if the validated name is present on otherNames list.
      Parameters:
      isPresentOnList - Whether the validated name is present on otherNames list.
      Returns:
      This validator instance with isPresentOnList parameter set to passed value.
    • setIsPresentOnList

      public UniqueNameValidator setIsPresentOnList(Supplier<Boolean> isPresentOnList)
      Use this method to define if the validated name is present on otherNames list.
      Parameters:
      isPresentOnList - Supplier that controls whether the validated name is present on otherNames list.
      Returns:
      This validator instance with isPresentOnList parameter set to passed value.
    • setIgnoreCase

      public UniqueNameValidator setIgnoreCase(boolean ignoreCase)
      Use this method to define if case of validated name doesn't have to match case of otherNames.
      Parameters:
      ignoreCase - Whether case of validated name doesn't have to match case of otherNames.
      Returns:
      This validator instance with ignoreCase parameter set to passed value.
    • wrapValidator

      public UniqueNameValidator wrapValidator(Validator extraValidator)
      Returns a copy of this UniqueNameValidator with main validator changed to the passed one.
      Parameters:
      extraValidator - The new main validator for the validated element.
    • getExtraValidator

      public Validator getExtraValidator()
      Returns the main validator for the validated element.
      Returns:
      The main validator for the validated element.
    • validate

      public Validator.ValidationResult validate()
      Specified by:
      validate in interface Validator