-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package hexlet.code; | ||
|
||
import hexlet.code.schemas.NumberSchema; | ||
import hexlet.code.schemas.StringSchema; | ||
|
||
public class Validator { | ||
public StringSchema string() { | ||
return new StringSchema(); | ||
} | ||
public NumberSchema number() { | ||
return new NumberSchema(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package hexlet.code.schemas; | ||
|
||
import lombok.NoArgsConstructor; | ||
import java.util.function.Predicate; | ||
|
||
@NoArgsConstructor | ||
public class NumberSchema extends BaseSchema<Integer> { | ||
@Override | ||
public NumberSchema required() { | ||
Predicate<Integer> requiredFunction = ((value) -> value != null); | ||
checkers.put("required", requiredFunction); | ||
return this; | ||
} | ||
|
||
public NumberSchema positive() { | ||
Predicate<Integer> positiveFunction = ((value) -> value > 0); | ||
checkers.put("positive", positiveFunction); | ||
return this; | ||
} | ||
|
||
public NumberSchema range(int startIndex, int finalIndex) { | ||
Predicate<Integer> rangeFunction = ((value) -> value >= startIndex || value <= finalIndex); | ||
checkers.put("range", rangeFunction); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters