Package org.instancio
Class Select
- java.lang.Object
-
- org.instancio.Select
-
public final class Select extends Object
A collection of static factory methods selecting fields and classes.Examples:
field(Example.class, "someField")
- select some field of Example classall(Example.class)
- select all instances of Example classall(GroupableSelector...)
- convenience method for combining multiple selectorsallStrings()
- select all StringsallInts()
- select allInteger
objects andint
primitives
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Selector
all(Class<?> type)
Select all instances of the given type, not including subtypes.static SelectorGroup
all(GroupableSelector... selectors)
A convenience method for combining multiple selectors.static Selector
allBooleans()
Selects all booleans, primitive and wrapper.static Selector
allBytes()
Selects all bytes, primitive and wrapper.static Selector
allChars()
Selects all characters, primitive and wrapper.static Selector
allDoubles()
Selects all doubles, primitive and wrapper.static Selector
allFloats()
Selects all floats, primitive and wrapper.static Selector
allInts()
Selects all integers, primitive and wrapper.static Selector
allLongs()
Selects all longs, primitive and wrapper.static Selector
allShorts()
Selects all shorts, primitive and wrapper.static Selector
allStrings()
Shorthand forall(String.class)
.static Selector
field(Class<?> declaringClass, String fieldName)
Selects a field of the specified class.static Selector
field(String fieldName)
Selects a field that belongs to the class being created.static Scope
scope(Class<?> targetClass)
Creates a selector scope for narrowing down a selector's target to the specified class.static Scope
scope(Class<?> targetClass, String fieldName)
Creates a scope for narrowing down a selector's target to a field of the specified class.
-
-
-
Method Detail
-
all
public static Selector 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 primitiveint
but notInteger
all(Integer.class)
- selectsInteger
wrapper but not primitiveint
In order to select both, primitive
int
and wrapper, use theallInts()
.- Parameters:
type
- to select- Returns:
- a selector for given class
-
all
public static SelectorGroup all(GroupableSelector... selectors)
A convenience method for combining multiple selectors.- Parameters:
selectors
- to combine- Returns:
- a group containing given selectors
-
field
public static Selector field(Class<?> declaringClass, String fieldName)
Selects a field of the specified class.- Parameters:
declaringClass
- class declaring the fieldfieldName
- field name to select- Returns:
- a selector for given field
-
field
public static Selector 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 for given field
-
allStrings
public static Selector allStrings()
Shorthand forall(String.class)
.- Returns:
- selector for all Strings
-
allBytes
public static Selector allBytes()
Selects all bytes, primitive and wrapper.- Returns:
- selector for all bytes
-
allFloats
public static Selector allFloats()
Selects all floats, primitive and wrapper.- Returns:
- selector for all floats
-
allShorts
public static Selector allShorts()
Selects all shorts, primitive and wrapper.- Returns:
- selector for all shorts
-
allInts
public static Selector allInts()
Selects all integers, primitive and wrapper.- Returns:
- selector for all integers
-
allLongs
public static Selector allLongs()
Selects all longs, primitive and wrapper.- Returns:
- selector for all longs
-
allDoubles
public static Selector allDoubles()
Selects all doubles, primitive and wrapper.- Returns:
- selector for all doubles
-
allBooleans
public static Selector allBooleans()
Selects all booleans, primitive and wrapper.- Returns:
- selector for all booleans
-
allChars
public static Selector allChars()
Selects all characters, primitive and wrapper.- Returns:
- selector for all characters
-
scope
public static Scope scope(Class<?> targetClass, String fieldName)
Creates a scope for narrowing down a selector's target to a field of the specified class.For example, the following will set all lists within
Person.address
object to an empty list.Person person = Instancio.of(Person.class) .set(all(List.class).within(scope(Person.class, "address")), Collections.emptyList()) .create();
- Parameters:
targetClass
- of the scopefieldName
- declared by the target class- Returns:
- a scope for fine-tuning a selector
- Since:
- 1.3.0
-
scope
public static Scope scope(Class<?> targetClass)
Creates a selector scope for narrowing down a selector's target to the specified class.For example, assuming a
Customer
class that has aCustomerConsent
class. the following will set all booleans withinCustomerConsent
totrue
.Customer customer = Instancio.of(Customer.class) .set(allBooleans().within(scope(CustomerConsent.class)), true) .create();
- Parameters:
targetClass
- of the scope- Returns:
- a scope for fine-tuning a selector
- Since:
- 1.3.0
-
-