Package org.instancio
Class Select
- java.lang.Object
-
- org.instancio.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 classall(Example.class)
- select all instances of Example classall(SelectorGroup...)
- convenience method for combining multiple selector groupsallStrings()
- select all StringsallInts()
- select allInteger
objects andint
primitives
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SelectorGroup
all(Class<?> type)
Select all instances of the given type, not including subtypes.static SelectorGroup
all(SelectorGroup... selectorGroups)
Convenience method for combining multiple selections, for example:static SelectorGroup
allBooleans()
Selects all booleans, primitive and wrapper.static SelectorGroup
allBytes()
Selects all bytes, primitive and wrapper.static SelectorGroup
allChars()
Selects all characters, primitive and wrapper.static SelectorGroup
allDoubles()
Selects all doubles, primitive and wrapper.static SelectorGroup
allFloats()
Selects all floats, primitive and wrapper.static SelectorGroup
allInts()
Selects all integers, primitive and wrapper.static SelectorGroup
allLongs()
Selects all longs, primitive and wrapper.static SelectorGroup
allShorts()
Selects all shorts, primitive and wrapper.static SelectorGroup
allStrings()
Shorthand forall(String.class)
.static SelectorGroup
field(Class<?> declaringClass, String fieldName)
Selects a field of the specified class.static SelectorGroup
field(String fieldName)
Selects a field that belongs to the class being created.
-
-
-
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 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 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 fieldfieldName
- 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 forall(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
-
-