java.lang.Object
com.streamconverter.command.rule.impl.composite.ChainRule
All Implemented Interfaces:
IRule

public class ChainRule extends Object implements IRule
Chains multiple transformation rules to be applied in sequence.

This rule allows combining multiple IRule instances to create complex transformations by applying them one after another. The output of each rule becomes the input for the next rule in the chain.

Examples:


 // Trim whitespace then convert to snake_case
 IRule chainedRule = ChainRule.builder()
     .addRule(new TrimRule())
     .addRule(CamelToSnakeCaseRule.create())
     .build();

 // Multiple transformations
 IRule complexRule = ChainRule.of(
     new TrimRule(),
     new LowerCaseRule(),
     CamelToSnakeCaseRule.create()
 );
 

Thread Safety: This class is thread-safe as long as the individual rules in the chain are thread-safe.

Since:
1.0
  • Method Details

    • apply

      public String apply(String input)
      Description copied from interface: IRule
      ルールの適用を実行します。

      このメソッドは、ストリーム変換の際にルールを適用するために使用されます。 具体的なルールの実装は、このメソッドをオーバーライドして定義します。 変換対象とする箇所を特定したあとにこのメソッドを呼び出すことを想定しています。

      Specified by:
      apply in interface IRule
      Parameters:
      input - 変換対象の文字列
      Returns:
      String output 変換結果を格納する文字列
    • size

      public int size()
      Gets the number of rules in this chain.
      Returns:
      number of rules
    • getRules

      public List<IRule> getRules()
      Gets an unmodifiable view of the rules in this chain.
      Returns:
      unmodifiable list of rules
    • builder

      public static ChainRule.Builder builder()
      Creates a builder for configuring the ChainRule.
      Returns:
      new builder instance
    • of

      public static ChainRule of(IRule... rules)
      Creates a ChainRule with the specified rules.
      Parameters:
      rules - rules to chain together
      Returns:
      new ChainRule instance
      Throws:
      IllegalArgumentException - if rules array is null or empty
    • of

      public static ChainRule of(List<IRule> rules)
      Creates a ChainRule with the specified rules.
      Parameters:
      rules - list of rules to chain together
      Returns:
      new ChainRule instance
      Throws:
      IllegalArgumentException - if rules list is null or empty
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object