Package org.instancio

Interface Selector

All Superinterfaces:
ConvertibleToScope, GroupableSelector, TargetSelector
All Known Implementing Classes:
MetamodelSelector, PrimitiveAndWrapperSelectorImpl, SelectorImpl

public interface Selector extends GroupableSelector, ConvertibleToScope
A selector that can be:
  • grouped with other selectors
  • narrowed down using Scope
  • converted to Scope
Since:
1.2.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    within(Scope... scopes)
    Specifies the scope for this selector in order to narrow down its target.

    Methods inherited from interface org.instancio.ConvertibleToScope

    toScope
  • Method Details

    • within

      GroupableSelector within(Scope... scopes)
      Specifies the scope for this selector in order to narrow down its target.

      For example, if the Person class has two Phone fields:

      
           class Person {
               private Phone home;
               private Phone cell;
               // snip...
           }
       

      and we want to set only the cell phone to a specific value, we can narrow down the selector as follows:

      
         // Scope can be created using:
         Scope cellPhone = scope(Person.class, "cell");
         // or selector toScope() method
         Scope cellPhone = field(Person::getCell).toScope();
      
         Person person = Instancio.of(Person.class)
             .set(field(Phone.class, "number").within(cellPhone), "123-45-67")
             .create();
       

      See Selector Scopes section of the user guide for details.

      Parameters:
      scopes - one or more scopes to apply
      Returns:
      a selector with the specified scope
      Since:
      1.3.0