Package org.instancio
Interface PredicateSelector
- All Superinterfaces:
ConvertibleToScope,DepthPredicateSelector,DepthSelector,GroupableSelector,LenientSelector,ScopeableSelector,TargetSelector,WithinScope
A selector for matching targets using predicates.
- Since:
- 1.6.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionatDepth(int depth) Restricts this selector's targets to the specified depth.Restricts this selector's targets to a depth that satisfies the givenpredicate.toScope()Scope representation of a selector.Specifies the scope for this selector in order to narrow down its target.Methods inherited from interface org.instancio.ScopeableSelector
lenient
-
Method Details
-
within
Specifies the scope for this selector in order to narrow down its target.For example, given the following classes:
record Phone(String countryCode, String number) {} record Person(Phone home, Phone cell) {}setting
homeandcellphone numbers to different values would require differentiating between twofield(Phone::number)selectors. This can be achieved using scopes as follows:Scope homePhone = field(Person::home).toScope(); Scope cellPhone = field(Person::cell).toScope(); Person person = Instancio.of(Person.class) .set(field(Phone::number).within(homePhone), "777-88-99") .set(field(Phone::number).within(cellPhone), "123-45-67") .create();See Selector Scopes section of the user guide for details.
- Specified by:
withinin interfaceScopeableSelector- Specified by:
withinin interfaceWithinScope- Parameters:
scopes- one or more scopes to apply- Returns:
- a selector with the specified scope
- Since:
- 4.1.0
-
atDepth
Restricts this selector's targets to a depth that satisfies the givenpredicate.For example, a predicate
atDepth(depth -> depth == 1)will restrict the selector to targets at depth 1 only.The root object is considered to be at depth 0.
- Specified by:
atDepthin interfaceDepthPredicateSelector- Parameters:
predicate- the predicate specifying the acceptable depth- Returns:
- a selector restricted to the specified depth
- See Also:
-
atDepth
Restricts this selector's targets to the specified depth. The selector will only apply to targets at the specified depth.When a selector with
atDepth(N)is converted usingtoScope(), the semantics of theSelector.within(Scope...)method still apply, meaning that the selection applies to targets at depth equal to or greater thanN.The root object is considered to be at depth 0.
- Specified by:
atDepthin interfaceDepthSelector- Parameters:
depth- the depth at which the selector should apply- Returns:
- a selector restricted to the specified depth
- See Also:
-
toScope
Scope representation of a selector.- Specified by:
toScopein interfaceConvertibleToScope- Returns:
- scope
- Since:
- 4.2.0
-