Package org.instancio.internal.selectors
Class SelectorImpl
- java.lang.Object
-
- org.instancio.internal.selectors.SelectorImpl
-
- All Implemented Interfaces:
GroupableSelector
,Flattener
,Selector
,TargetSelector
,ToScopeConvertible
public final class SelectorImpl extends Object implements Selector, GroupableSelector, Flattener
-
-
Constructor Summary
Constructors Constructor Description SelectorImpl(SelectorTargetKind selectorTargetKind, Class<?> targetClass, String fieldName)
SelectorImpl(SelectorTargetKind selectorTargetKind, Class<?> targetClass, String fieldName, List<Scope> scopes, Selector parent)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
List<SelectorImpl>
flatten()
String
getFieldName()
Selector
getParent()
List<Scope>
getScopes()
Class<?>
getTargetClass()
int
hashCode()
SelectorTargetKind
selectorType()
Scope
toScope()
Scope representation of a selector.String
toString()
Selector
within(Scope... scopes)
Specifies the scope for this selector in order to narrow down the selector target.
-
-
-
Constructor Detail
-
SelectorImpl
public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable Class<?> targetClass, @Nullable String fieldName, @Nullable List<Scope> scopes, @Nullable Selector parent)
Constructor.- Parameters:
selectorTargetKind
- selector target's kindtargetClass
- target classfieldName
- field name, applicable to field selectors onlyscopes
- scopes specified top-down, from outermost to innermostparent
- required only forPrimitiveAndWrapperSelectorImpl
for checking unused selectors
-
SelectorImpl
public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable Class<?> targetClass, @Nullable String fieldName)
-
-
Method Detail
-
within
public Selector within(Scope... scopes)
Description copied from interface:Selector
Specifies the scope for this selector in order to narrow down the selector target.For example, if the
Person
class has twoPhone
fields:class Person { private Phone home; private Phone cell; // snip... }
and we want to set only the
cell
phone to a specific value, we can narrow down the selector as follows:Person person = Instancio.of(Person.class) .set(field(Phone.class, "number").within(scope(Person.class, "cell")), "123-45-67") .create();
Multiple scopes can be specified top-down, that is starting from the outermost class.
-
toScope
public Scope toScope()
Description copied from interface:ToScopeConvertible
Scope representation of a selector.- Specified by:
toScope
in interfaceToScopeConvertible
- Returns:
- scope
-
flatten
public List<SelectorImpl> flatten()
-
getParent
public Selector getParent()
-
selectorType
public SelectorTargetKind selectorType()
-
getTargetClass
public Class<?> getTargetClass()
-
getFieldName
public String getFieldName()
-
equals
public boolean equals(Object o)
Performs equality check with all fields except
parent
.
-
hashCode
public int hashCode()
Calculates hashcode using all fields except
parent
.
-
-