Package org.instancio
Class Select
java.lang.Object
org.instancio.Select
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
Modifier and TypeMethodDescriptionstatic Selector
Select all instances of the given type, not including subtypes.static SelectorGroup
all
(GroupableSelector... selectors) A convenience method for combining multiple selectors.static Selector
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
Selects all doubles, primitive and wrapper.static Selector
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
Selects all shorts, primitive and wrapper.static Selector
Shorthand forall(String.class)
.static Selector
Selects a field of the specified class.static Selector
Selects a field that belongs to the class being created.static Scope
Creates a selector scope for narrowing down a selector's target to the specified class.static Scope
Creates a scope for narrowing down a selector's target to a field of the specified class.
-
Method Details
-
all
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
A convenience method for combining multiple selectors.- Parameters:
selectors
- to combine- Returns:
- a group containing given selectors
-
field
Selects a field of the specified class.- Parameters:
declaringClass
- class declaring the fieldfieldName
- field name to select- Returns:
- a selector for given field
-
field
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
Shorthand forall(String.class)
.- Returns:
- selector for all Strings
-
allBytes
Selects all bytes, primitive and wrapper.- Returns:
- selector for all bytes
-
allFloats
Selects all floats, primitive and wrapper.- Returns:
- selector for all floats
-
allShorts
Selects all shorts, primitive and wrapper.- Returns:
- selector for all shorts
-
allInts
Selects all integers, primitive and wrapper.- Returns:
- selector for all integers
-
allLongs
Selects all longs, primitive and wrapper.- Returns:
- selector for all longs
-
allDoubles
Selects all doubles, primitive and wrapper.- Returns:
- selector for all doubles
-
allBooleans
Selects all booleans, primitive and wrapper.- Returns:
- selector for all booleans
-
allChars
Selects all characters, primitive and wrapper.- Returns:
- selector for all characters
-
scope
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
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
-