Skip to content

Commit

Permalink
Check 2 ?
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxonquall committed Apr 1, 2024
1 parent 071a884 commit ec0060c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 12 additions & 6 deletions app/src/main/java/hexlet/code/schemas/MapSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Map;


public final class MapSchema extends BaseSchema {
public final class MapSchema extends BaseSchema<Map<?, ?>> {


public MapSchema() {
Expand All @@ -22,11 +22,17 @@ public MapSchema sizeof(int size) {
}

public <T> MapSchema shape(Map<String, BaseSchema<T>> schemas) {
addCheck("shape", value -> schemas.entrySet()
.stream()
;

addCheck(
"shape",
map -> {
return schemas.entrySet().stream().allMatch(e -> {
var v = map.get(e.getKey());
var schema = e.getValue();
return schema.isValid((T) v);
});
}
);

return this;
}
}
}
3 changes: 2 additions & 1 deletion app/src/test/java/hexlet/code/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ void nestedMapNumberTest() {
void nestedMapMapTest() {
var v = new Validator();
var schema = v.map();
var schemas = new HashMap<String, BaseSchema<Map>>();
// var schemas = new HashMap<String, BaseSchema<Map>>();
var schemas = new HashMap<String, BaseSchema<Map<?, ?>>>();
schemas.put("Map1", v.map().required().sizeof(2));
schemas.put("Map2", v.map().sizeof(2));
schema.shape(schemas);
Expand Down

0 comments on commit ec0060c

Please sign in to comment.