Package org.instancio

Class Select


  • public class Select
    extends Object
    A collection of static factory methods selecting fields and classes.

    Examples:

    • field(Example.class, "someField") - select some field of Example class
    • all(Example.class) - select all instances of Example class
    • all(SelectorGroup...) - convenience method for combining multiple selector groups
    • allStrings() - select all Strings
    • allInts() - select all Integer objects and int primitives
    • Method Detail

      • all

        public static SelectorGroup all​(Class<?> type)
        Select all instances of the given type, not including subtypes.

        If the type is a primitive or wrapper, this method only selects the specified type. For example:

        • all(int.class) - selects primitive int but not Integer
        • all(Integer.class) - selects Integer wrapper but not primitive int

        In order to select both, primitive int and wrapper, use the allInts().

        Parameters:
        type - to select
        Returns:
        a selector group composed of a single type selector
      • all

        public static SelectorGroup all​(SelectorGroup... selectorGroups)
        Convenience method for combining multiple selections, for example:
        
           all(
              field(Address.class, "city"),
              field(Address.class, "state"),
              field(Address.class, "country"));
         
        Parameters:
        selectorGroups - to combine
        Returns:
        a group composed of given arguments
      • field

        public static SelectorGroup field​(Class<?> declaringClass,
                                          String fieldName)
        Selects a field of the specified class.
        Parameters:
        declaringClass - class declaring the field
        fieldName - field name to select
        Returns:
        a selector group composed of a single field selector
      • field

        public static SelectorGroup field​(String fieldName)
        Selects a field that belongs to the class being created.

        Example

        
             Person person = Instancio.of(Person.class)
                     .ignore(field("fullName")) // Person.fullName
                     .create();
         
        Parameters:
        fieldName - field name to select
        Returns:
        a selector group composed of a single field selector
      • allStrings

        public static SelectorGroup allStrings()
        Shorthand for all(String.class).
        Returns:
        selector for all Strings
      • allBytes

        public static SelectorGroup allBytes()
        Selects all bytes, primitive and wrapper.
        Returns:
        selector for all bytes
      • allFloats

        public static SelectorGroup allFloats()
        Selects all floats, primitive and wrapper.
        Returns:
        selector for all floats
      • allShorts

        public static SelectorGroup allShorts()
        Selects all shorts, primitive and wrapper.
        Returns:
        selector for all shorts
      • allInts

        public static SelectorGroup allInts()
        Selects all integers, primitive and wrapper.
        Returns:
        selector for all integers
      • allLongs

        public static SelectorGroup allLongs()
        Selects all longs, primitive and wrapper.
        Returns:
        selector for all longs
      • allDoubles

        public static SelectorGroup allDoubles()
        Selects all doubles, primitive and wrapper.
        Returns:
        selector for all doubles
      • allBooleans

        public static SelectorGroup allBooleans()
        Selects all booleans, primitive and wrapper.
        Returns:
        selector for all booleans
      • allChars

        public static SelectorGroup allChars()
        Selects all characters, primitive and wrapper.
        Returns:
        selector for all characters