Package org.instancio.internal.selectors
Class FieldSelectorBuilderImpl
java.lang.Object
org.instancio.internal.selectors.FieldSelectorBuilderImpl
- All Implemented Interfaces:
FieldSelectorBuilder
,SelectorBuilder
,TargetSelector
public class FieldSelectorBuilderImpl
extends Object
implements FieldSelectorBuilder, SelectorBuilder
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<A extends Annotation>
FieldSelectorBuilderMatches fields annotated with the specified annotation, ignoring inherited annotations.build()
Builds a selector.declaredIn
(Class<?> type) Matches fields declared in the specified class.Matches field names using the specified regular expression.Matches fields with the specified name.Matches fields against the specified type, including subtypes.toString()
-
Constructor Details
-
FieldSelectorBuilderImpl
public FieldSelectorBuilderImpl()
-
-
Method Details
-
named
Description copied from interface:FieldSelectorBuilder
Matches fields with the specified name.- Specified by:
named
in interfaceFieldSelectorBuilder
- Parameters:
fieldName
- exact field name to match- Returns:
- selector builder
- See Also:
-
matching
Description copied from interface:FieldSelectorBuilder
Matches field names using the specified regular expression.- Specified by:
matching
in interfaceFieldSelectorBuilder
- Parameters:
regex
- for matching field names- Returns:
- selector builder
- See Also:
-
ofType
Description copied from interface:FieldSelectorBuilder
Matches fields against the specified type, including subtypes. For example, selecting fieldsofType(Collection.class
} will match fields declared asList
orSet
.Note: this method will not match fields declared as a
TypeVariable
. For instance, in the following snippet, even thoughT
is bound toString
type, the selectorofType(String.class)
will not match the field. In this case, targeting the field by name would be a better option.class Item<T> { private T value; } Item<String> result = Instancio.of(new TypeToken<Item<String>>() {}) .set(fields().ofType(String.class), "foo") // will not match Item.value .create(); assertThat(result.getValue()).isNotEqualTo("foo");
- Specified by:
ofType
in interfaceFieldSelectorBuilder
- Parameters:
fieldType
- field type to match- Returns:
- selector builder
-
declaredIn
Description copied from interface:FieldSelectorBuilder
Matches fields declared in the specified class.- Specified by:
declaredIn
in interfaceFieldSelectorBuilder
- Parameters:
type
- class that declares target field(s)- Returns:
- selector builder
-
annotated
Description copied from interface:FieldSelectorBuilder
Matches fields annotated with the specified annotation, ignoring inherited annotations.The method can be chained to require multiple annotations.
- Specified by:
annotated
in interfaceFieldSelectorBuilder
- Type Parameters:
A
- annotation type- Parameters:
annotation
- declared annotation to match- Returns:
- selector builder
-
build
Description copied from interface:SelectorBuilder
Builds a selector.- Specified by:
build
in interfaceSelectorBuilder
- Returns:
- created selector instance
-
toString
-