Class CollapseWhitespaceSanitizer

java.lang.Object
io.github.rabinarayanpatra.sanitizer.builtin.CollapseWhitespaceSanitizer
All Implemented Interfaces:
FieldSanitizer<String>

public class CollapseWhitespaceSanitizer extends Object implements FieldSanitizer<String>
Sanitizer that trims leading and trailing whitespace and collapses internal whitespace sequences into a single space.

Useful for cleaning up user input where excessive spacing may be present, such as names or addresses.

 
 String input = "  John   Doe  ";
 String sanitized = new CollapseWhitespaceSanitizer().sanitize(input); // "John Doe"
 
 
Since:
1.0.0
See Also:
  • Constructor Details

    • CollapseWhitespaceSanitizer

      public CollapseWhitespaceSanitizer()
      Default constructor.
  • Method Details

    • sanitize

      public @Nullable String sanitize(@Nullable String in)
      Trims the input and replaces all runs of whitespace with a single space.
      Specified by:
      sanitize in interface FieldSanitizer<String>
      Parameters:
      in - the input string to sanitize
      Returns:
      the sanitized string, or null if the input was null