Class FieldSelectorBuilderImpl

java.lang.Object
org.instancio.internal.selectors.FieldSelectorBuilderImpl
All Implemented Interfaces:
DepthPredicateSelector, DepthSelector, FieldSelectorBuilder, SelectorBuilder, TargetSelector

public class FieldSelectorBuilderImpl extends Object implements FieldSelectorBuilder
  • Constructor Details

    • FieldSelectorBuilderImpl

      public FieldSelectorBuilderImpl()
  • Method Details

    • apiMethod

      protected String apiMethod()
    • createBuilder

      protected PredicateSelectorImpl.Builder createBuilder()
    • named

      public FieldSelectorBuilder named(String fieldName)
      Description copied from interface: FieldSelectorBuilder
      Matches fields with the specified name.
      Specified by:
      named in interface FieldSelectorBuilder
      Parameters:
      fieldName - exact field name to match
      Returns:
      selector builder
      See Also:
    • matching

      public FieldSelectorBuilder matching(String regex)
      Description copied from interface: FieldSelectorBuilder
      Matches field names using the specified regular expression.
      Specified by:
      matching in interface FieldSelectorBuilder
      Parameters:
      regex - for matching field names
      Returns:
      selector builder
      See Also:
    • ofType

      public FieldSelectorBuilder ofType(Class<?> fieldType)
      Description copied from interface: FieldSelectorBuilder
      Matches fields against the specified type, including subtypes. For example, selecting fields ofType(Collection.class} will match fields declared as List or Set.

      Note: this method will not match fields declared as a TypeVariable. For instance, in the following snippet, even though T is bound to String type, the selector ofType(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 interface FieldSelectorBuilder
      Parameters:
      fieldType - field type to match
      Returns:
      selector builder
    • declaredIn

      public FieldSelectorBuilder declaredIn(Class<?> type)
      Description copied from interface: FieldSelectorBuilder
      Matches fields declared in the specified class.
      Specified by:
      declaredIn in interface FieldSelectorBuilder
      Parameters:
      type - class that declares target field(s)
      Returns:
      selector builder
    • annotated

      public <A extends Annotation> FieldSelectorBuilder annotated(Class<? extends A> annotation)
      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 interface FieldSelectorBuilder
      Type Parameters:
      A - annotation type
      Parameters:
      annotation - declared annotation to match
      Returns:
      selector builder
    • addPredicate

      protected final void addPredicate(Predicate<Field> predicate)
    • description

      protected final StringBuilder description()
    • atDepth

      public final TargetSelector atDepth(int depth)
      Description copied from interface: DepthSelector
      Restricts this selector's target(s) to the specified depth.
      Specified by:
      atDepth in interface DepthSelector
      Parameters:
      depth - the depth at which selector applies
      Returns:
      selector restricted to the specified depth
    • atDepth

      public final TargetSelector atDepth(Predicate<Integer> predicate)
      Description copied from interface: DepthPredicateSelector
      Restricts this selector's target(s) to a depth that satisfies the given predicate.
      Specified by:
      atDepth in interface DepthPredicateSelector
      Parameters:
      predicate - specifying the depth
      Returns:
      selector restricted to the specified depth
    • buildPredicate

      protected final Predicate<Field> buildPredicate()
    • build

      public final PredicateSelector build()
      Description copied from interface: SelectorBuilder
      Builds a selector.
      Specified by:
      build in interface SelectorBuilder
      Returns:
      created selector instance
    • toString

      public final String toString()
      Overrides:
      toString in class Object