Package org.instancio.internal.selectors
Class SelectorImpl
java.lang.Object
org.instancio.internal.selectors.SelectorImpl
- All Implemented Interfaces:
GroupableSelector
,Flattener
,UnusedSelectorDescription
,Selector
,TargetSelector
,ToScopeConvertible
- Direct Known Subclasses:
MetamodelSelector
public class SelectorImpl
extends Object
implements Selector, GroupableSelector, Flattener, UnusedSelectorDescription
-
Constructor Summary
ConstructorDescriptionSelectorImpl
(SelectorTargetKind selectorTargetKind, Class<?> targetClass, String fieldName) SelectorImpl
(SelectorTargetKind selectorTargetKind, Class<?> targetClass, String fieldName, List<Scope> scopes, Selector parent) SelectorImpl
(SelectorTargetKind selectorTargetKind, Class<?> targetClass, String fieldName, List<Scope> scopes, Selector parent, Throwable stackTraceHolder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
flatten()
Flattens selectors into a list.Returns selector description, including line number where it was used.Class<?>
final int
hashCode()
toScope()
Scope representation of a selector.toString()
Specifies the scope for this selector in order to narrow down the selector target.
-
Constructor Details
-
SelectorImpl
public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable Class<?> targetClass, @Nullable String fieldName, @Nullable List<Scope> scopes, @Nullable Selector parent, @Nullable Throwable stackTraceHolder) 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
-
SelectorImpl
public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable Class<?> targetClass, @Nullable String fieldName)
-
-
Method Details
-
getStackTraceHolder
-
getDescription
Description copied from interface:UnusedSelectorDescription
Returns selector description, including line number where it was used.- Specified by:
getDescription
in interfaceUnusedSelectorDescription
- Returns:
- selector description
-
within
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
Description copied from interface:ToScopeConvertible
Scope representation of a selector.- Specified by:
toScope
in interfaceToScopeConvertible
- Returns:
- scope
-
flatten
Description copied from interface:Flattener
Flattens selectors into a list. -
getParent
-
getScopes
-
getSelectorTargetKind
-
getTargetClass
-
getFieldName
-
equals
Performs equality check with all fields except
parent
andstackTraceHolder
. -
hashCode
public final int hashCode()Calculates hashcode using all fields except
parent
andstackTraceHolder
. -
toString
-