001package com.streamconverter.command.rule.impl.string; 002 003import com.streamconverter.command.rule.IRule; 004 005/** 006 * Trims leading and trailing whitespace from strings. 007 * 008 * <p>This rule removes whitespace characters from the beginning and end of the input string. 009 * Whitespace includes spaces, tabs, newlines, and other Unicode whitespace characters. 010 * 011 * <p>Examples: 012 * 013 * <ul> 014 * <li>{@code " hello "} → {@code "hello"} 015 * <li>{@code "\t\nworld\r\n"} → {@code "world"} 016 * <li>{@code "already trimmed"} → {@code "already trimmed"} 017 * </ul> 018 * 019 * <p>Usage: 020 * 021 * <pre>{@code 022 * IRule rule = new TrimRule(); 023 * IStreamCommand command = JsonNavigateCommand.create("$.name", rule); 024 * }</pre> 025 * 026 * @since 1.0 027 */ 028public class TrimRule implements IRule { 029 030 @Override 031 public String apply(String input) { 032 return input != null ? input.trim() : null; 033 } 034 035 @Override 036 public String toString() { 037 return "TrimRule{}"; 038 } 039 040 @Override 041 public boolean equals(Object obj) { 042 return obj instanceof TrimRule; 043 } 044 045 @Override 046 public int hashCode() { 047 return TrimRule.class.hashCode(); 048 } 049}