Skip to content

Commit 461c64b

Browse files
committed
add
1 parent 450de03 commit 461c64b

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

app/src/main/java/hexlet/code/schemas/BaseSchema.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package hexlet.code.schemas;
22

3-
public abstract class BaseSchema<T> {
3+
public abstract class BaseSchema<T extends BaseSchema<T>> {
44
protected boolean isRequired = false;
55

6+
@SuppressWarnings("unchecked")
67
public T required() {
78
this.isRequired = true;
89
return (T) this;

app/src/main/java/hexlet/code/schemas/MapSchema.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ public class MapSchema extends BaseSchema<MapSchema> {
66
private int requiredSize = -1;
77
private Map<String, BaseSchema<?>> schemas;
88

9+
@Override
10+
public MapSchema required() {
11+
return super.required();
12+
}
13+
14+
public MapSchema sizeof(int size) {
15+
this.requiredSize = size;
16+
return this;
17+
}
18+
19+
public MapSchema shape(Map<String, BaseSchema<?>> shapeSchemas) {
20+
this.schemas = shapeSchemas;
21+
return this;
22+
}
23+
924
@Override
1025
public boolean isValid(Object value) {
1126
if (isRequired && value == null) {
@@ -24,22 +39,12 @@ public boolean isValid(Object value) {
2439
if (schemas != null) {
2540
for (Map.Entry<String, BaseSchema<?>> entry : schemas.entrySet()) {
2641
String key = entry.getKey();
27-
BaseSchema<String> schema = (BaseSchema<String>) entry.getValue();
42+
BaseSchema<?> schema = entry.getValue();
2843
if (!map.containsKey(key) || !schema.isValid(map.get(key))) {
2944
return false;
3045
}
3146
}
3247
}
3348
return true;
3449
}
35-
36-
public MapSchema sizeof(int size) {
37-
this.requiredSize = size;
38-
return this;
39-
}
40-
41-
public MapSchema shape(Map<String, BaseSchema<?>> shapeSchemas) {
42-
this.schemas = shapeSchemas;
43-
return this;
44-
}
4550
}

app/src/main/java/hexlet/code/schemas/NumberSchema.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ public class NumberSchema extends BaseSchema<NumberSchema> {
55
private int minRange = Integer.MIN_VALUE;
66
private int maxRange = Integer.MAX_VALUE;
77

8+
@Override
9+
public NumberSchema required() {
10+
return super.required();
11+
}
12+
813
public NumberSchema positive() {
914
this.isPositive = true;
1015
return this;

app/src/main/java/hexlet/code/schemas/StringSchema.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ public class StringSchema extends BaseSchema<StringSchema> {
44
private int minLength = 0;
55
private String containsSubstring = null;
66

7+
@Override
8+
public StringSchema required() {
9+
return super.required();
10+
}
11+
712
public StringSchema minLength(int length) {
813
this.minLength = length;
914
return this;

0 commit comments

Comments
 (0)