Package org.instancio.internal.selectors
Class FieldSelectorBuilderImpl
java.lang.Object
org.instancio.internal.selectors.FieldSelectorBuilderImpl
- All Implemented Interfaces:
DepthPredicateSelector
,DepthSelector
,FieldSelectorBuilder
,SelectorBuilder
,TargetSelector
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final void
addPredicate
(Predicate<Field> predicate) <A extends Annotation>
FieldSelectorBuilderMatches fields annotated with the specified annotation, ignoring inherited annotations.protected String
final TargetSelector
atDepth
(int depth) Restricts this selector's target(s) to the specified depth.final TargetSelector
Restricts this selector's target(s) to a depth that satisfies the givenpredicate
.final PredicateSelector
build()
Builds a selector.protected PredicateSelectorImpl.Builder
declaredIn
(Class<?> type) Matches fields declared in the specified class.protected final StringBuilder
Matches field names using the specified regular expression.Matches fields with the specified name.Matches fields against the specified type, including subtypes.final String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.instancio.FieldSelectorBuilder
atDepth, atDepth
-
Constructor Details
-
FieldSelectorBuilderImpl
public FieldSelectorBuilderImpl()
-
-
Method Details
-
apiMethod
-
createBuilder
-
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
-
addPredicate
-
description
-
atDepth
Description copied from interface:DepthSelector
Restricts this selector's target(s) to the specified depth.- Specified by:
atDepth
in interfaceDepthSelector
- Parameters:
depth
- the depth at which selector applies- Returns:
- selector restricted to the specified depth
-
atDepth
Description copied from interface:DepthPredicateSelector
Restricts this selector's target(s) to a depth that satisfies the givenpredicate
.- Specified by:
atDepth
in interfaceDepthPredicateSelector
- Parameters:
predicate
- specifying the depth- Returns:
- selector restricted to the specified depth
-
buildPredicate
-
build
Description copied from interface:SelectorBuilder
Builds a selector.- Specified by:
build
in interfaceSelectorBuilder
- Returns:
- created selector instance
-
toString
-