|
1 | 1 | package hexlet.code; |
2 | 2 |
|
3 | | -import hexlet.code.schemas.StringSchema; |
| 3 | +import hexlet.code.schemas.BaseSchema; |
| 4 | + |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.Map; |
4 | 7 |
|
5 | 8 | public class App { |
6 | 9 | public static void main(String[] args) { |
7 | 10 | Validator v = new Validator(); |
8 | | - StringSchema schema = v.string(); |
9 | 11 |
|
10 | | - System.out.println(schema.isValid("")); // true |
11 | | - System.out.println(schema.isValid(null)); // true |
| 12 | + MapSchema schema = v.map(); |
| 13 | + |
| 14 | + Map<String, BaseSchema<?>> schemas = new HashMap<>(); |
| 15 | + schemas.put("name", v.string().required()); |
| 16 | + schemas.put("age", v.number().positive()); |
12 | 17 |
|
13 | | - schema.required(); |
| 18 | + schema.shape(schemas); |
14 | 19 |
|
15 | | - System.out.println(schema.isValid(null)); // false |
16 | | - System.out.println(schema.isValid("")); // false |
17 | | - System.out.println(schema.isValid("what does the fox say")); // true |
18 | | - System.out.println(schema.isValid("hexlet")); // true |
| 20 | + Map<String, Object> human1 = new HashMap<>(); |
| 21 | + human1.put("name", "Alice"); |
| 22 | + human1.put("age", 25); |
19 | 23 |
|
20 | | - schema.contains("wh").isValid("what does the fox say"); // true |
21 | | - schema.contains("what").isValid("what does the fox say"); // true |
22 | | - schema.contains("whatthe").isValid("what does the fox say"); // false |
| 24 | + System.out.println(schema.isValid(human1)); |
23 | 25 |
|
24 | | - System.out.println(schema.isValid("what does the fox say")); // false |
| 26 | + Map<String, Object> human2 = new HashMap<>(); |
| 27 | + human2.put("name", "Bob"); |
| 28 | + human2.put("age", -5); |
25 | 29 |
|
26 | | - StringSchema schema1 = v.string(); |
27 | | - System.out.println(schema1.minLength(10).minLength(4).isValid("Hexlet")); // true |
| 30 | + System.out.println(schema.isValid(human2)); |
28 | 31 | } |
29 | 32 | } |
0 commit comments