Class SelectorImpl

java.lang.Object
org.instancio.internal.selectors.SelectorImpl
All Implemented Interfaces:
ConvertibleToScope, GroupableSelector, Flattener, UnusedSelectorDescription, Selector, TargetSelector
Direct Known Subclasses:
MetamodelSelector

public class SelectorImpl extends Object implements Selector, GroupableSelector, Flattener, UnusedSelectorDescription
  • Constructor Details

    • SelectorImpl

      public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable @Nullable Class<?> targetClass, @Nullable @Nullable String fieldName, @Nullable @Nullable List<Scope> scopes, @Nullable @Nullable Selector parent, @Nullable @Nullable Throwable stackTraceHolder)
      Constructor.
      Parameters:
      selectorTargetKind - selector target's kind
      targetClass - target class
      fieldName - field name, applicable to field selectors only
      scopes - scopes specified top-down, from outermost to innermost
      parent - required only for PrimitiveAndWrapperSelectorImpl for checking unused selectors
    • SelectorImpl

      public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable @Nullable Class<?> targetClass, @Nullable @Nullable String fieldName, @Nullable @Nullable List<Scope> scopes, @Nullable @Nullable Selector parent)
    • SelectorImpl

      public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable @Nullable Class<?> targetClass, @Nullable @Nullable String fieldName)
  • Method Details

    • root

      public static SelectorImpl root()
    • getStackTraceHolder

      public Throwable getStackTraceHolder()
    • getDescription

      public String getDescription()
      Description copied from interface: UnusedSelectorDescription
      Returns selector description, including line number where it was used.
      Specified by:
      getDescription in interface UnusedSelectorDescription
      Returns:
      selector description
    • within

      public Selector within(@NotNull @NotNull Scope... scopes)
      Description copied from interface: Selector
      Specifies the scope for this selector in order to narrow down the selector 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:

      
           Person person = Instancio.of(Person.class)
               .set(field(Phone.class, "number").within(scope(Person.class, "cell")), "123-45-67")
               .create();
       

      Multiple scopes can be specified top-down, that is starting from the outermost class.

      Specified by:
      within in interface Selector
      Parameters:
      scopes - one or more scopes to apply
      Returns:
      a selector with the specified scope
    • toScope

      public Scope toScope()
      Description copied from interface: ConvertibleToScope
      Scope representation of a selector.
      Specified by:
      toScope in interface ConvertibleToScope
      Returns:
      scope
    • flatten

      public List<TargetSelector> flatten()
      Description copied from interface: Flattener
      Flattens selectors into a list.
      Specified by:
      flatten in interface Flattener
      Returns:
      flat list of selectors
    • getParent

      public Selector getParent()
    • getScopes

      public List<Scope> getScopes()
    • getSelectorTargetKind

      public SelectorTargetKind getSelectorTargetKind()
    • getTargetClass

      public Class<?> getTargetClass()
    • getFieldName

      public String getFieldName()
    • equals

      public final boolean equals(Object o)

      Performs equality check with all fields except parent and stackTraceHolder.

      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()

      Calculates hashcode using all fields except parent and stackTraceHolder.

      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object