View Javadoc
1   package com.guinetik.hexafun.examples.counter;
2   
3   import com.guinetik.hexafun.fun.Result;
4   import com.guinetik.hexafun.examples.counter.CounterInputs.*;
5   
6   /**
7    * Validation functions for counter operations.
8    *
9    * <p>Each validator is a pure function: Input -> Result&lt;Input&gt;
10   * Can be composed/chained in the DSL.
11   */
12  public final class CounterValidators {
13  
14      private CounterValidators() {}
15  
16      /**
17       * Validates that the counter in IncrementInput is not null.
18       */
19      public static Result<IncrementInput> validateIncrement(IncrementInput input) {
20          if (input == null) {
21              return Result.fail("Input cannot be null");
22          }
23          if (input.counter() == null) {
24              return Result.fail("Counter cannot be null");
25          }
26          return Result.ok(input);
27      }
28  
29      /**
30       * Validates that the counter in DecrementInput is not null.
31       */
32      public static Result<DecrementInput> validateDecrement(DecrementInput input) {
33          if (input == null) {
34              return Result.fail("Input cannot be null");
35          }
36          if (input.counter() == null) {
37              return Result.fail("Counter cannot be null");
38          }
39          return Result.ok(input);
40      }
41  
42      /**
43       * Validates that the counter in AddInput is not null.
44       */
45      public static Result<AddInput> validateAddCounter(AddInput input) {
46          if (input == null) {
47              return Result.fail("Input cannot be null");
48          }
49          if (input.counter() == null) {
50              return Result.fail("Counter cannot be null");
51          }
52          return Result.ok(input);
53      }
54  
55      /**
56       * Validates that the amount in AddInput is within bounds [-100, 100].
57       */
58      public static Result<AddInput> validateAddAmount(AddInput input) {
59          if (input.amount() < -100 || input.amount() > 100) {
60              return Result.fail("Amount must be between -100 and 100");
61          }
62          return Result.ok(input);
63      }
64  }