Package org.instancio
Class Bindings
- java.lang.Object
-
- org.instancio.Bindings
-
public class Bindings extends Object
A collection of static factory methods for creatingBinding
s.A binding allows targeting a specific class or field.
Examples:
field(Example.class, "someField")
- target some field of Example classall(Example.class)
- target all instances of Example classof(Binding...)
- convenience method for targeting multiple bindingsallStrings()
- target all StringsallInts()
- target allInteger
objects andint
primitives
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Binding
all(Class<?> type)
Creates a binding for the given type.static Binding
allBooleans()
Binding for all booleans, primitive and wrapper.static Binding
allBytes()
Binding for all bytes, primitive and wrapper.static Binding
allChars()
Binding for all characters, primitive and wrapper.static Binding
allDoubles()
Binding for all doubles, primitive and wrapper.static Binding
allFloats()
Binding for all floats, primitive and wrapper.static Binding
allInts()
Binding for all integers, primitive and wrapper.static Binding
allLongs()
Binding for all longs, primitive and wrapper.static Binding
allShorts()
Binding for all shorts, primitive and wrapper.static Binding
allStrings()
Shorthand forall(String.class)
.static Binding
field(Class<?> declaringClass, String fieldName)
Creates a binding for the given class's field.static Binding
field(String fieldName)
Creates a binding for a field that belongs to the class being created.static Binding
of(Binding... bindings)
-
-
-
Method Detail
-
field
public static Binding field(Class<?> declaringClass, String fieldName)
Creates a binding for the given class's field.- Parameters:
declaringClass
- class declaring the fieldfieldName
- field name to bind- Returns:
- binding
-
field
public static Binding field(String fieldName)
Creates a binding for 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 bind- Returns:
- binding
-
all
public static Binding all(Class<?> type)
Creates a binding for the given type.If the type is a primitive or wrapper, this method will only bind the specified type. For example:
all(int.class)
- binds primitiveint
; does not includeInteger
all(Integer.class)
- bindsInteger
wrapper; does not include primitiveint
In order to bind both, primitive
int
and wrapper, use theallInts()
.- Parameters:
type
- to bind- Returns:
- binding
-
allStrings
public static Binding allStrings()
Shorthand forall(String.class)
.- Returns:
- binding for all Strings
-
allBytes
public static Binding allBytes()
Binding for all bytes, primitive and wrapper.- Returns:
- binding for all bytes
-
allFloats
public static Binding allFloats()
Binding for all floats, primitive and wrapper.- Returns:
- binding for all floats
-
allShorts
public static Binding allShorts()
Binding for all shorts, primitive and wrapper.- Returns:
- binding for all shorts
-
allInts
public static Binding allInts()
Binding for all integers, primitive and wrapper.- Returns:
- binding for all integers
-
allLongs
public static Binding allLongs()
Binding for all longs, primitive and wrapper.- Returns:
- binding for all longs
-
allDoubles
public static Binding allDoubles()
Binding for all doubles, primitive and wrapper.- Returns:
- binding for all doubles
-
allBooleans
public static Binding allBooleans()
Binding for all booleans, primitive and wrapper.- Returns:
- binding for all booleans
-
allChars
public static Binding allChars()
Binding for all characters, primitive and wrapper.- Returns:
- binding for all characters
-
-