Class FieldSelectorBuilderImpl

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

public class FieldSelectorBuilderImpl extends Object implements FieldSelectorBuilder, SelectorBuilder
  • Constructor Details

    • FieldSelectorBuilderImpl

      public FieldSelectorBuilderImpl()
  • Method Details

    • named

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

      public FieldSelectorBuilder ofType(@NotNull @NotNull 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(@NotNull @NotNull 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(@NotNull @NotNull 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
    • build

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

      public String toString()
      Overrides:
      toString in class Object