|
1 | 1 | package com.manoelcampos.randomorg; |
2 | 2 |
|
3 | | -import lombok.AccessLevel; |
4 | | -import lombok.Getter; |
5 | | -import lombok.Setter; |
6 | | -import lombok.experimental.Accessors; |
7 | | - |
8 | 3 | /** |
9 | | - * @author Manoel Campos da Silva Filho |
| 4 | + * @param n The number of random integers to generate |
| 5 | + * @param min The minimum value for a generated random int. |
| 6 | + * @param max The maximum value for a generated random int. |
| 7 | + * @param replacement Enable generation of duplicated integers (true) or not (false). |
| 8 | + * @author Manoel Campos da Silva Filho |
10 | 9 | */ |
11 | | -@Getter @Setter @Accessors(chain = true) |
12 | | -class GenerateIntegersRequestParams { |
| 10 | +record GenerateIntegersRequestParams(int n, int min, int max, boolean replacement, String apiKey) |
| 11 | +{ |
13 | 12 | public static final int MIN_VALUE = -100000000; |
14 | | - public static final int MAX_VALUE = 100000000; |
15 | | - |
16 | | - @Setter(AccessLevel.PROTECTED) |
17 | | - private String apiKey; |
| 13 | + public static final int MAX_VALUE = 100000000; |
18 | 14 |
|
19 | | - /** The number of random integers to generate */ |
20 | | - private final int n; |
| 15 | + GenerateIntegersRequestParams { |
| 16 | + if(n <= 0) |
| 17 | + throw new IllegalArgumentException("n must be greater than 0"); |
21 | 18 |
|
22 | | - /** The minimum value for a generated random int. */ |
23 | | - private final int min; |
| 19 | + if(min < GenerateIntegersRequestParams.MIN_VALUE) |
| 20 | + throw new IllegalArgumentException("minValue cannot be smaller than " + MIN_VALUE); |
24 | 21 |
|
25 | | - /** The maximum value for a generated random int. */ |
26 | | - private final int max; |
| 22 | + if(max > GenerateIntegersRequestParams.MAX_VALUE) |
| 23 | + throw new IllegalArgumentException("minValue cannot be higher than " + MAX_VALUE); |
| 24 | + } |
27 | 25 |
|
28 | 26 | /** |
29 | | - * Enable generation of duplicated integers (true) or not (false). |
| 27 | + * Clones the object, copying all fields from the source object, |
| 28 | + * except the {@link #apiKey}, that is set to the informed value. |
| 29 | + * |
| 30 | + * @param apiKey the API key to set in the new object |
30 | 31 | */ |
31 | | - private boolean replacement; |
| 32 | + GenerateIntegersRequestParams of(final String apiKey){ |
| 33 | + return new GenerateIntegersRequestParams(n, min, max, replacement, apiKey); |
| 34 | + } |
32 | 35 |
|
33 | 36 | /** |
34 | 37 | * Instantiates a GenerateIntegersRequestParams that indicates to |
@@ -64,27 +67,7 @@ class GenerateIntegersRequestParams { |
64 | 67 | this(n, min, max, true); |
65 | 68 | } |
66 | 69 |
|
67 | | - /** |
68 | | - * Instantiates a GenerateIntegersRequestParams that indicates to |
69 | | - * generate random integers between a given [min .. max] interval. |
70 | | - * @param n the number of random integers to generate |
71 | | - * @param min the minimum value for a generated random int |
72 | | - * @param max the maximum value for a generated random int |
73 | | - * @param replacement Enable generation of duplicated integers (true) or not (false). |
74 | | - */ |
75 | | - GenerateIntegersRequestParams(final int n, final int min, final int max, final boolean replacement) { |
76 | | - if(n <= 0) |
77 | | - throw new IllegalArgumentException("n must be greater than 0"); |
78 | | - |
79 | | - if(min < GenerateIntegersRequestParams.MIN_VALUE) |
80 | | - throw new IllegalArgumentException("minValue cannot be smaller than " + MIN_VALUE); |
81 | | - |
82 | | - if(max > GenerateIntegersRequestParams.MAX_VALUE) |
83 | | - throw new IllegalArgumentException("minValue cannot be higher than " + MAX_VALUE); |
84 | | - |
85 | | - this.n = n; |
86 | | - this.min = min; |
87 | | - this.max = max; |
88 | | - this.replacement = replacement; |
| 70 | + GenerateIntegersRequestParams(final int n, final int min, final int max, final boolean replacement){ |
| 71 | + this(n, min, max, replacement, ""); |
89 | 72 | } |
90 | 73 | } |
0 commit comments