@Immutable public final class Field extends Object
Configuration instance.| Modifier and Type | Class and Description |
|---|---|
static interface |
Field.Validator
A functional interface that can be used to validate field values.
|
| Modifier and Type | Field and Description |
|---|---|
private Supplier<String> |
defaultValueGenerator |
private String |
desc |
private String |
name |
private Field.Validator |
validator |
| Modifier | Constructor and Description |
|---|---|
protected |
Field(String name,
String description,
Supplier<String> defaultValueGenerator,
Field.Validator validator) |
| Modifier and Type | Method and Description |
|---|---|
static Field |
create(String name)
Create an immutable
Field instance with the given property name. |
static Field |
create(String name,
String description)
Create an immutable
Field instance with the given property name and description. |
static Field |
create(String name,
String description,
boolean defaultValue)
Create an immutable
Field instance with the given property name, description, and default value. |
static Field |
create(String name,
String description,
BooleanSupplier defaultValueGenerator)
Create an immutable
Field instance with the given property name, description, and default value. |
static Field |
create(String name,
String description,
int defaultValue)
Create an immutable
Field instance with the given property name, description, and default value. |
static Field |
create(String name,
String description,
IntSupplier defaultValueGenerator)
Create an immutable
Field instance with the given property name, description, and default value. |
static Field |
create(String name,
String description,
long defaultValue)
Create an immutable
Field instance with the given property name, description, and default value. |
static Field |
create(String name,
String description,
LongSupplier defaultValueGenerator)
Create an immutable
Field instance with the given property name, description, and default value. |
static Field |
create(String name,
String description,
String defaultValue)
Create an immutable
Field instance with the given property name, description, and default value. |
static Field |
create(String name,
String description,
Supplier<String> defaultValueGenerator)
Create an immutable
Field instance with the given property name, description, and default value. |
String |
defaultValue()
Get the default value of the field.
|
String |
description()
Get the description of the field.
|
boolean |
equals(Object obj) |
int |
hashCode() |
static int |
isBoolean(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isClassName(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isInteger(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isLong(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isNonNegativeInteger(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isNonNegativeLong(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isPositiveInteger(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isPositiveLong(Configuration config,
Field field,
Consumer<String> problems) |
static int |
isRequired(Configuration config,
Field field,
Consumer<String> problems) |
String |
name()
Get the name of the field.
|
String |
toString() |
boolean |
validate(Configuration config,
Consumer<String> problems)
Validate the supplied value for this field, and report any problems to the designated consumer.
|
Field |
withDefault(boolean defaultValue)
Create and return a new Field instance that is a copy of this field but with the given default value.
|
Field |
withDefault(BooleanSupplier defaultValueGenerator)
Create and return a new Field instance that is a copy of this field but with the given default value.
|
Field |
withDefault(int defaultValue)
Create and return a new Field instance that is a copy of this field but with the given default value.
|
Field |
withDefault(IntSupplier defaultValueGenerator)
Create and return a new Field instance that is a copy of this field but with the given default value.
|
Field |
withDefault(long defaultValue)
Create and return a new Field instance that is a copy of this field but with the given default value.
|
Field |
withDefault(LongSupplier defaultValueGenerator)
Create and return a new Field instance that is a copy of this field but with the given default value.
|
Field |
withDefault(String defaultValue)
Create and return a new Field instance that is a copy of this field but with the given default value.
|
Field |
withDescription(String description)
Create and return a new Field instance that is a copy of this field but with the given description.
|
Field |
withNoValidation()
Create and return a new Field instance that is a copy of this field but that uses no validation.
|
Field |
withValidation(Field.Validator... validators)
Create and return a new Field instance that is a copy of this field but that uses the supplied validation function during
validate(Configuration, Consumer). |
Field |
withValidation(Function<String,?>... conversionCheck)
Create and return a new Field instance that is a copy of this field but that uses the supplied conversion check function
during
validate(Configuration, Consumer). |
Field |
withValidation(Predicate<String>... predicates)
Create and return a new Field instance that that is a copy of this field but that uses the supplied predicate during
validate(Configuration, Consumer). |
private final String name
private final String desc
private final Field.Validator validator
protected Field(String name, String description, Supplier<String> defaultValueGenerator, Field.Validator validator)
public static Field create(String name)
Field instance with the given property name.name - the name of the field; may not be nullpublic static Field create(String name, String description)
Field instance with the given property name and description.name - the name of the field; may not be nulldescription - the descriptionpublic static Field create(String name, String description, String defaultValue)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValue - the default value for the fieldpublic static Field create(String name, String description, int defaultValue)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValue - the default value for the fieldpublic static Field create(String name, String description, long defaultValue)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValue - the default value for the fieldpublic static Field create(String name, String description, boolean defaultValue)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValue - the default value for the fieldpublic static Field create(String name, String description, Supplier<String> defaultValueGenerator)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValueGenerator - the generator for the default value for the fieldpublic static Field create(String name, String description, BooleanSupplier defaultValueGenerator)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValueGenerator - the generator for the default value for the fieldpublic static Field create(String name, String description, IntSupplier defaultValueGenerator)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValueGenerator - the generator for the default value for the fieldpublic static Field create(String name, String description, LongSupplier defaultValueGenerator)
Field instance with the given property name, description, and default value.name - the name of the field; may not be nulldescription - the descriptiondefaultValueGenerator - the generator for the default value for the fieldpublic String name()
public String defaultValue()
public String description()
public boolean validate(Configuration config, Consumer<String> problems)
config - the field values keyed by their name; may not be nullproblems - the consumer to be called with each problem; never nulltrue if the value is considered valid, or false if it is not validpublic Field withDescription(String description)
description - the new description for the new fieldpublic Field withDefault(String defaultValue)
defaultValue - the new default value for the new fieldpublic Field withDefault(boolean defaultValue)
defaultValue - the new default value for the new fieldpublic Field withDefault(int defaultValue)
defaultValue - the new default value for the new fieldpublic Field withDefault(long defaultValue)
defaultValue - the new default value for the new fieldpublic Field withDefault(BooleanSupplier defaultValueGenerator)
defaultValueGenerator - the supplier for the new default value for the new field, called whenever a default value
is neededpublic Field withDefault(IntSupplier defaultValueGenerator)
defaultValueGenerator - the supplier for the new default value for the new field, called whenever a default value
is neededpublic Field withDefault(LongSupplier defaultValueGenerator)
defaultValueGenerator - the supplier for the new default value for the new field, called whenever a default value
is neededpublic Field withNoValidation()
public Field withValidation(Field.Validator... validators)
validate(Configuration, Consumer).validators - the validation function(s); may be nullpublic Field withValidation(Function<String,?>... conversionCheck)
validate(Configuration, Consumer).conversionCheck - the functions that attempt to validate the object; may be nullpublic Field withValidation(Predicate<String>... predicates)
validate(Configuration, Consumer).predicates - the functions that attempt to validate the object; may be nullpublic static int isClassName(Configuration config, Field field, Consumer<String> problems)
public static int isRequired(Configuration config, Field field, Consumer<String> problems)
public static int isBoolean(Configuration config, Field field, Consumer<String> problems)
public static int isInteger(Configuration config, Field field, Consumer<String> problems)
public static int isPositiveInteger(Configuration config, Field field, Consumer<String> problems)
public static int isNonNegativeInteger(Configuration config, Field field, Consumer<String> problems)
public static int isLong(Configuration config, Field field, Consumer<String> problems)
public static int isPositiveLong(Configuration config, Field field, Consumer<String> problems)
public static int isNonNegativeLong(Configuration config, Field field, Consumer<String> problems)
Copyright © 2016 JBoss by Red Hat. All rights reserved.