Skip to content

Commit 0941132

Browse files
committed
Added missing javadoc and removed deprecated code
1 parent f4fc526 commit 0941132

File tree

7 files changed

+66
-281
lines changed

7 files changed

+66
-281
lines changed

src/main/java/dev/ditsche/validator/Validator.java

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import dev.ditsche.validator.error.ErrorBag;
44
import dev.ditsche.validator.error.FieldNotAccessibleException;
55
import dev.ditsche.validator.error.ValidationException;
6-
import dev.ditsche.validator.rule.Rule;
7-
import dev.ditsche.validator.rule.RuleInfo;
8-
import dev.ditsche.validator.rule.RuleParser;
96
import dev.ditsche.validator.rule.builder.Builder;
107
import dev.ditsche.validator.validation.Validatable;
118
import dev.ditsche.validator.validation.ValidationResult;
@@ -32,50 +29,102 @@ public class Validator {
3229
*/
3330
private List<Validatable> fields;
3431

35-
/**
36-
* Parses a pattern and creates a Rule instance dynamically if it
37-
* is registered inside the RuleMap.
38-
*/
39-
private RuleParser ruleParser;
40-
4132
/**
4233
* Create a new validator instance based on a given type.
4334
*/
4435
private Validator() {
4536
this.errorBag = new ErrorBag();
46-
this.ruleParser = new RuleParser();
4737
this.fields = new ArrayList<>();
4838
}
4939

40+
/**
41+
* Creates a validator from a given set of rules.
42+
*
43+
* @param builders The rule builders defining the fields of
44+
* the validation object.
45+
* @return A validator instance containing the provided rules.
46+
*/
5047
public static Validator fromRules(Builder ...builders) {
5148
Validator validator = new Validator();
5249
for(Builder builder : builders) {
53-
validator.add(builder);
50+
validator.addField(builder);
5451
}
5552
return validator;
5653
}
5754

58-
public static Validator fromRules(Validatable ...rules) {
55+
/**
56+
* Creates a validator from a given set of rules.
57+
*
58+
* @param validatable The rule builders defining the fields of
59+
* the validation object.
60+
* @return A validator instance containing the provided rules.
61+
*/
62+
public static Validator fromRules(Validatable ...validatable) {
5963
Validator validator = new Validator();
60-
for(Validatable validatable : rules) {
61-
validator.add(validatable);
64+
for(Validatable val : validatable) {
65+
validator.addField(val);
6266
}
6367
return validator;
6468
}
6569

70+
/**
71+
* Creates a new and empty Validator without any fields and rules.
72+
*
73+
* @return A fresh and empty validator instance.
74+
*/
6675
public static Validator empty() {
6776
return new Validator();
6877
}
6978

70-
public Validator add(Builder builder) {
71-
return add(builder.build());
79+
/**
80+
* Adds a field and the provided rules to the validator.
81+
* If the field already exists, the rules will be added.
82+
*
83+
* @param builder The rules of the field as a builder.
84+
* @return The updated validator instance.
85+
*/
86+
public Validator addField(Builder builder) {
87+
return addField(builder.build());
7288
}
7389

74-
public Validator add(Validatable validatable) {
90+
/**
91+
* Adds a field and the provided rules to the validator.
92+
* If the field already exists, the rules will be added.
93+
*
94+
* @param validatable The rules of the field as a validatable object.
95+
* @return The updated validator instance.
96+
*/
97+
public Validator addField(Validatable validatable) {
7598
this.fields.add(validatable);
7699
return this;
77100
}
78101

102+
/**
103+
* Adds multiple fields and the provided rules to the validator.
104+
* If a field already exists, the rules will be added.
105+
*
106+
* @param builders The rules of the fields as builders.
107+
* @return The updated validator instance.
108+
*/
109+
public Validator addFields(Builder ...builders) {
110+
for(Builder builder : builders) {
111+
this.addField(builder.build());
112+
}
113+
return this;
114+
}
115+
116+
/**
117+
* Adds multiple fields and the provided rules to the validator.
118+
* If a field already exists, the rules will be added.
119+
*
120+
* @param validatable The rules of the fields as validatable objects.
121+
* @return The updated validator instance.
122+
*/
123+
public Validator addFields(Validatable ...validatable) {
124+
this.fields.addAll(List.of(validatable));
125+
return this;
126+
}
127+
79128
/**
80129
* Validates an object against a schema and returns an error bag.
81130
* Sets abort early to false.

src/main/java/dev/ditsche/validator/rule/RuleInfo.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/main/java/dev/ditsche/validator/rule/RuleMap.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main/java/dev/ditsche/validator/rule/RuleParser.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/test/java/dev/ditsche/validator/rule/RuleInfoTest.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/test/java/dev/ditsche/validator/rule/RuleMapTest.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/test/java/dev/ditsche/validator/rule/RuleParserTest.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)