Package org.instancio.internal.selectors
Class SelectorImpl
- java.lang.Object
-
- org.instancio.internal.selectors.SelectorImpl
-
- All Implemented Interfaces:
GroupableSelector
,Flattener
,Selector
,TargetSelector
,ToScopeConvertible
- Direct Known Subclasses:
MetamodelSelector
public 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)
SelectorImpl(SelectorTargetKind selectorTargetKind, Class<?> targetClass, String fieldName, List<Scope> scopes, Selector parent, Throwable stackTraceHolder)
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()
SelectorTargetKind
getSelectorTargetKind()
Throwable
getStackTraceHolder()
String
getStackTraceLine()
Returns the line where this selector was declared in client code.Class<?>
getTargetClass()
int
hashCode()
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, @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
public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable Class<?> targetClass, @Nullable String fieldName, @Nullable List<Scope> scopes, @Nullable Selector parent)
-
SelectorImpl
public SelectorImpl(SelectorTargetKind selectorTargetKind, @Nullable Class<?> targetClass, @Nullable String fieldName)
-
-
Method Detail
-
getStackTraceHolder
public Throwable getStackTraceHolder()
-
getStackTraceLine
public String getStackTraceLine()
Returns the line where this selector was declared in client code. Used for reporting unused selectors.- Returns:
- the first non-Instancio stacktrace element as a string.
-
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()
-
getSelectorTargetKind
public SelectorTargetKind getSelectorTargetKind()
-
getTargetClass
public Class<?> getTargetClass()
-
getFieldName
public String getFieldName()
-
equals
public final boolean equals(Object o)
Performs equality check with all fields except
parent
andstackTraceHolder
.
-
hashCode
public final int hashCode()
Calculates hashcode using all fields except
parent
andstackTraceHolder
.
-
-