Package org.instancio
Interface Selector
- All Superinterfaces:
ConvertibleToScope
,DepthSelector
,GroupableSelector
,ScopeableSelector
,TargetSelector
,WithinScope
Represents regular field and class selectors,
including primitive and wrapper selectors.
- Since:
- 1.2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionatDepth
(int depth) Restricts this selector's target(s) to the specified depth.Specifies the scope for this selector in order to narrow down its target.Methods inherited from interface org.instancio.ConvertibleToScope
toScope
-
Method Details
-
atDepth
Restricts this selector's target(s) to the specified depth.When a selector
atDepth(N)
is convertedtoScope()
, the semantics ofwithin(Scope...)
method still hold, meaning: at depth equal to or greater thanN
.- Specified by:
atDepth
in interfaceDepthSelector
- Parameters:
depth
- the depth at which selector applies- Returns:
- selector restricted to the specified depth
- Since:
- 3.0.0
-
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
home
andcell
phone 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:
within
in interfaceScopeableSelector
- Specified by:
within
in interfaceWithinScope
- Parameters:
scopes
- one or more scopes to apply- Returns:
- a selector with the specified scope
- Since:
- 1.3.0
-