public static class Validator.Entry extends Object
Predicate
to the value of the field and uses a
default value (see defaultTo(Object)
if the predicate fails. It can also apply an arbitrary
conversion using castTo(Function)
. These are all applied when you call
normalize(BulletConfig)
with a BulletConfig
containing a field that matches the Entry.
You can also ask that the check cause a failure using orFail()
.Modifier and Type | Method and Description |
---|---|
Validator.Entry |
castTo(Function<Object,Object> adapter)
Apply a cast to the value in the
BulletConfig after validation and defaults are applied. |
Validator.Entry |
checkIf(Predicate<Object> validator)
Add a
Predicate to check for the field represented by the entry. |
Validator.Entry |
defaultTo(Object defaultValue)
Use a default value for the field represented by this Entry.
|
Object |
getDefaultValue()
Get the defaultValue in the Entry after applying the cast, if present.
|
Validator.Entry |
orFail()
Fail if this entry fails to hold.
|
Validator.Entry |
unless(Predicate<Object> guard)
Add a
Predicate to guard the checks in this entry. |
public Validator.Entry unless(Predicate<Object> guard)
Predicate
to guard the checks in this entry. This predicate should take the value of the
field and return true if you do not want to run the checks added to the entry. This will also not
default to the provided defaults.guard
- The non-null guard to use for this Entry.public Validator.Entry checkIf(Predicate<Object> validator)
Predicate
to check for the field represented by the entry. This predicate should take the
value of the field and return true to represent a successful validation and false otherwise. You can add
more checks by repeatedly calling this method. All your predicates added so far will be ANDed to the latest
check.validator
- The non-null validator to use for this Entry.public Validator.Entry orFail()
public Validator.Entry defaultTo(Object defaultValue)
castTo(Function)
will be applied to this if present.defaultValue
- The value to use for the field in the BulletConfig
if validation fails.public Validator.Entry castTo(Function<Object,Object> adapter)
BulletConfig
after validation and defaults are applied. Use this to
convert values in the config to their final types if you find yourself type-casting or checking for their
types repeatedly.adapter
- The function that takes the field (or the default value) represented and converts it to another.public Object getDefaultValue()
Copyright © 2021. All rights reserved.