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
8
9
10
11
12 public final class CounterValidators {
13
14 private CounterValidators() {}
15
16
17
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
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
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
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 }