public class QueryProfile extends com.yahoo.component.provider.FreezableSimpleComponent implements Cloneable
Modifier and Type | Field and Description |
---|---|
private CopyOnWriteContent |
content
The content of this profile.
|
private List<QueryProfile> |
inherited
The query profiles inherited by this, or null if none
|
private static Pattern |
namePattern |
private Map<String,Boolean> |
overridable
Field override settings: fieldName→OverrideValue.
|
private List<String> |
resolvedDimensions
The resolved variant dimensions of this, or null if none or not resolved yet (is resolved at freeze)
|
private QueryProfileType |
type
Defines the permissible content of this, or null if any content is permissible
|
private Object |
value
The value at this query profile - allows non-fields to have values, e.g a=value1, a.b=value2
|
private QueryProfileVariants |
variants
The variants of this, or null if none
|
Constructor and Description |
---|
QueryProfile(com.yahoo.component.ComponentId id)
Creates a new query profile from an id.
|
QueryProfile(String idString)
Convenience shorthand for new QueryProfile(new ComponentId(idString))
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
accept(boolean allowContent,
QueryProfileVisitor visitor,
DimensionBinding dimensionBinding,
QueryProfile owner)
Visit the profiles and values referenced from this in order of decreasing precedence
|
protected void |
accept(QueryProfileVisitor visitor,
DimensionBinding dimensionBinding,
QueryProfile owner) |
(package private) void |
acceptAndEnter(String key,
QueryProfileVisitor visitor,
DimensionBinding dimensionBinding,
QueryProfile owner) |
void |
addInherited(QueryProfile profile)
Adds a profile to the end of the inherited list of this.
|
void |
addInherited(QueryProfile profile,
DimensionValues dimensionValues)
Adds a profile to the end of the inherited list of this for the given variant.
|
void |
addInherited(QueryProfile profile,
String[] dimensionValues) |
protected Object |
checkAndConvertAssignment(String localName,
Object value,
QueryProfileRegistry registry)
Converts to the type of the receiving field, if possible and necessary.
|
QueryProfile |
clone()
Returns a clone of this.
|
(package private) static Object |
cloneIfNecessary(Object object)
Clones a value of a type which may appear in a query profile if cloning is necessary (i.e if it is
not immutable).
|
private static QueryProfile |
combineProfiles(QueryProfile newProfile,
QueryProfile existingProfile) |
(package private) static Object |
combineValues(Object newValue,
Object existingValue)
Combines an existing and a new value for a query property key.
|
CompiledQueryProfile |
compile(CompiledQueryProfileRegistry registry)
Returns a compiled version of this which produces faster lookup times
|
protected Object |
convertToSubstitutionString(Object value)
Returns this value, or its corresponding substitution string if it contains substitutions
|
protected QueryProfile |
createSubProfile(String name,
DimensionBinding dimensionBinding)
Looks up all inherited profiles and adds any that matches this name.
|
Map<String,Object> |
declaredContent()
Returns the content fields declared in this (i.e not including those inherited) as a read-only map.
|
void |
freeze()
Switches this from write-only to read-only mode.
|
(package private) Object |
get(com.yahoo.processing.request.CompoundName name,
DimensionBinding dimensionBinding) |
(package private) Object |
get(com.yahoo.processing.request.CompoundName name,
DimensionBinding binding,
com.yahoo.processing.request.Properties substitution) |
Object |
get(com.yahoo.processing.request.CompoundName name,
Map<String,String> context,
com.yahoo.processing.request.Properties substitution) |
Object |
get(String name)
Returns a value from this query profile by resolving the given name:
The name up to the first dot is the value looked up in the value of this profile
The rest of the name (if any) is used as the name to look up in the referenced query profile
If this name does not resolve completely into a value in this or any inherited profile, null is returned.
|
(package private) Object |
get(String name,
DimensionBinding binding,
com.yahoo.processing.request.Properties substitution) |
Object |
get(String name,
DimensionValues dimensionValues,
com.yahoo.processing.request.Properties substitution)
Returns a value from this using the given dimensions for resolution
|
Object |
get(String name,
Map<String,String> context)
Returns a value from this using the given property context for resolution and using this for substitution
|
Object |
get(String name,
Map<String,String> context,
com.yahoo.processing.request.Properties substitution) |
Object |
get(String name,
String[] dimensionValues)
Returns a value from this using the given dimensions for resolution
|
Object |
get(String name,
String[] dimensionValues,
com.yahoo.processing.request.Properties substitution) |
protected Map<String,Object> |
getContent()
Returns all the content from this as an unmodifiable map
|
protected Object |
getContent(String key)
Returns a value from the content of this, or null if not present
|
List<String> |
getDimensions()
Returns the variant dimensions to be used in this - an unmodifiable list of dimension names
|
protected FieldDescription |
getFieldDescription(com.yahoo.processing.request.CompoundName name,
DimensionBinding binding)
Returns the field description of this field, or null if it is not typed
|
private QueryProfile |
getQueryProfileExact(String localName,
boolean create,
DimensionBinding dimensionBinding)
Returns a query profile from this by name
|
QueryProfileType |
getType()
Returns the type of this or null if it has no type
|
Object |
getValue()
Returns the value set at this node, to allow non-leafs to have values.
|
QueryProfileVariants |
getVariants()
Returns the virtual variants of this, or null if none
|
List<QueryProfile> |
inherited()
Returns the list of profiles inherited by this.
|
private Boolean |
isDeclaredOverridable(com.yahoo.processing.request.CompoundName name,
DimensionBinding dimensionBinding) |
Boolean |
isDeclaredOverridable(String name,
Map<String,String> context)
Returns if the given field is declared explicitly as overridable or not in this or any nested profiles
(i.e not including overridable settings inherited and from types).
|
boolean |
isExplicit() |
protected Boolean |
isLocalInstanceOverridable(String localName) |
(package private) Boolean |
isLocalOverridable(String localName,
DimensionBinding binding)
Returns true if this value is definitely overridable in this (set and not unoverridable),
false if it is declared unoverridable (in instance or type), and null if this profile has no
opinion on the matter because the value is not set in this.
|
private static boolean |
isModifiable(QueryProfile profile)
Returns whether the given profile may be modified from this profile
|
(package private) Set<com.yahoo.processing.request.CompoundName> |
listReferences(com.yahoo.processing.request.CompoundName prefix,
Map<String,String> context)
Lists references reachable from this.
|
Map<com.yahoo.processing.request.CompoundName,QueryProfileType> |
listTypes(com.yahoo.processing.request.CompoundName prefix,
Map<String,String> context)
Lists types reachable from this, indexed by the prefix having that type.
|
(package private) Set<com.yahoo.processing.request.CompoundName> |
listUnoverridable(com.yahoo.processing.request.CompoundName prefix,
Map<String,String> context)
Lists every entry (value or reference) reachable from this which is not overridable
|
Map<String,Object> |
listValues(com.yahoo.processing.request.CompoundName prefix)
Return all objects that start with the given prefix path using no context.
|
Map<String,Object> |
listValues(com.yahoo.processing.request.CompoundName prefix,
Map<String,String> context)
Return all objects that start with the given prefix path.
|
Map<String,Object> |
listValues(com.yahoo.processing.request.CompoundName prefix,
Map<String,String> context,
com.yahoo.processing.request.Properties substitution)
Adds all objects that start with the given path prefix to the given value map.
|
Map<String,Object> |
listValues(String prefix)
Return all objects that start with the given prefix path using no context.
|
Map<String,Object> |
listValues(String prefix,
Map<String,String> context)
Return all objects that start with the given prefix path.
|
private Object |
localExactLookup(String name,
DimensionBinding dimensionBinding)
Do a variant-aware content lookup in this - without looking in any wrapped content.
|
protected Object |
localLookup(String name,
DimensionBinding dimensionBinding)
Do a variant-aware content lookup in this
|
private void |
localPut(String localName,
Object value,
DimensionBinding dimensionBinding)
Sets a value directly in this query profile (unless frozen)
|
protected Object |
lookup(com.yahoo.processing.request.CompoundName name,
boolean allowQueryProfileResult,
DimensionBinding dimensionBinding) |
Object |
lookup(String name,
Map<String,String> context)
Returns the node at the position prescribed by the given name (without doing substitutions) -
a primitive value, a substitutable string, a query profile, or null if not found.
|
private QueryProfile |
lookupParentExact(com.yahoo.processing.request.CompoundName name,
boolean create,
DimensionBinding dimensionBinding)
Looks up and, if necessary, creates, the query profile which should hold the given local name portion of the
given name.
|
protected void |
set(com.yahoo.processing.request.CompoundName name,
Object value,
DimensionBinding binding,
QueryProfileRegistry registry)
Override this to intercept all writes to this profile (or any nested profiles)
|
void |
set(com.yahoo.processing.request.CompoundName name,
Object value,
Map<String,String> context,
QueryProfileRegistry registry)
Sets a value in this or any nested profile.
|
void |
set(String name,
Object value,
DimensionValues dimensionValues,
QueryProfileRegistry registry)
Sets a value in this or any nested profile.
|
void |
set(String name,
Object value,
Map<String,String> context,
QueryProfileRegistry registry) |
void |
set(String name,
Object value,
QueryProfileRegistry registry)
Sets a value in this or any nested profile using null as context
|
void |
set(String name,
Object value,
String[] dimensionValues,
QueryProfileRegistry registry) |
void |
setDimensions(String[] dimensions)
Sets the dimensions over which this may vary.
|
protected QueryProfile |
setLocalNode(String localName,
Object value,
QueryProfileType parentType,
DimensionBinding dimensionBinding,
QueryProfileRegistry registry)
Sets the value of a node in this profile - the local name given must not be nested (contain dots)
|
private void |
setNode(com.yahoo.processing.request.CompoundName name,
Object value,
QueryProfileType parentType,
DimensionBinding dimensionBinding,
QueryProfileRegistry registry)
Sets a value to a (possibly non-local) node.
|
private void |
setOverridable(com.yahoo.processing.request.CompoundName fieldName,
boolean overridable,
DimensionBinding dimensionBinding)
Sets the overridability of a field in this profile,
this overrides the corresponding setting in the type (if any)
|
void |
setOverridable(String fieldName,
boolean overridable,
Map<String,String> context)
Sets the overridability of a field in this profile,
this overrides the corresponding setting in the type (if any)
|
void |
setType(QueryProfileType type)
Sets the type of this, or set to null to not use any type checking in this profile
|
void |
setValue(Object value) |
String |
toString() |
static void |
validateName(String name)
Throws IllegalArgumentException if the given string is not a valid query profile name
|
private void |
visitContent(QueryProfileVisitor visitor,
DimensionBinding dimensionBinding) |
protected void |
visitInherited(boolean allowContent,
QueryProfileVisitor visitor,
DimensionBinding dimensionBinding,
QueryProfile owner) |
protected void |
visitVariants(boolean allowContent,
QueryProfileVisitor visitor,
DimensionBinding dimensionBinding) |
ensureNotFrozen, isFrozen
private QueryProfileType type
private Object value
private QueryProfileVariants variants
private List<String> resolvedDimensions
private List<QueryProfile> inherited
private CopyOnWriteContent content
private Map<String,Boolean> overridable
private static final Pattern namePattern
public QueryProfile(com.yahoo.component.ComponentId id)
frozen
.
At that point it becomes readable but unmodifiable, which it stays until it goes out of reference.public QueryProfile(String idString)
public QueryProfileType getType()
public void setType(QueryProfileType type)
public QueryProfileVariants getVariants()
public List<QueryProfile> inherited()
public void addInherited(QueryProfile profile)
public final void addInherited(QueryProfile profile, String[] dimensionValues)
public void addInherited(QueryProfile profile, DimensionValues dimensionValues)
public Map<String,Object> declaredContent()
IllegalStateException
- if this is frozenpublic Boolean isDeclaredOverridable(String name, Map<String,String> context)
name
- the (possibly dotted) field name to returncontext
- the context in which the name is resolved, or null if noneIllegalStateException
- if this is frozenpublic void setDimensions(String[] dimensions)
public Object getValue()
public void setValue(Object value)
public List<String> getDimensions()
public final void setOverridable(String fieldName, boolean overridable, Map<String,String> context)
public final Map<String,Object> listValues(String prefix)
For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") will return {"d" => "a.d-value","e" => "a.e-value"}
public final Map<String,Object> listValues(com.yahoo.processing.request.CompoundName prefix)
For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") will return {"d" => "a.d-value","e" => "a.e-value"}
public final Map<String,Object> listValues(String prefix, Map<String,String> context)
For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") will return {"d" => "a.d-value","e" => "a.e-value"}
public final Map<String,Object> listValues(com.yahoo.processing.request.CompoundName prefix, Map<String,String> context)
For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") will return {"d" => "a.d-value","e" => "a.e-value"}
public Map<String,Object> listValues(com.yahoo.processing.request.CompoundName prefix, Map<String,String> context, com.yahoo.processing.request.Properties substitution)
For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") will return {"d" => "a.d-value","e" => "a.e-value"}
public Map<com.yahoo.processing.request.CompoundName,QueryProfileType> listTypes(com.yahoo.processing.request.CompoundName prefix, Map<String,String> context)
Set<com.yahoo.processing.request.CompoundName> listReferences(com.yahoo.processing.request.CompoundName prefix, Map<String,String> context)
Set<com.yahoo.processing.request.CompoundName> listUnoverridable(com.yahoo.processing.request.CompoundName prefix, Map<String,String> context)
public final Object get(String name)
public final Object get(String name, Map<String,String> context)
public final Object get(String name, String[] dimensionValues)
public final Object get(String name, String[] dimensionValues, com.yahoo.processing.request.Properties substitution)
public final Object get(String name, DimensionValues dimensionValues, com.yahoo.processing.request.Properties substitution)
public final Object get(String name, Map<String,String> context, com.yahoo.processing.request.Properties substitution)
public final Object get(com.yahoo.processing.request.CompoundName name, Map<String,String> context, com.yahoo.processing.request.Properties substitution)
final Object get(String name, DimensionBinding binding, com.yahoo.processing.request.Properties substitution)
final Object get(com.yahoo.processing.request.CompoundName name, DimensionBinding binding, com.yahoo.processing.request.Properties substitution)
final Object get(com.yahoo.processing.request.CompoundName name, DimensionBinding dimensionBinding)
public final Object lookup(String name, Map<String,String> context)
public final void set(String name, Object value, QueryProfileRegistry registry)
public final void set(com.yahoo.processing.request.CompoundName name, Object value, Map<String,String> context, QueryProfileRegistry registry)
name
- the name of the field, possibly a dotted name which will cause setting of a variable in a subprofilevalue
- the value to assign to the name, a primitive wrapper, string or a query profilecontext
- the context used to resolve where this value should be set, or null if noneIllegalArgumentException
- if the given name is illegal given the types of this or any nested query profileIllegalStateException
- if this query profile is frozenpublic final void set(String name, Object value, Map<String,String> context, QueryProfileRegistry registry)
public final void set(String name, Object value, String[] dimensionValues, QueryProfileRegistry registry)
public final void set(String name, Object value, DimensionValues dimensionValues, QueryProfileRegistry registry)
name
- the name of the field, possibly a dotted name which will cause setting of a variable in a subprofilevalue
- the value to assign to the name, a primitive wrapper, string or a query profiledimensionValues
- the dimension values - will be matched by order to the dimensions set in this - if this is
shorter or longer than the number of dimensions it will be adjusted as neededregistry
- the registry used to resolve query profile references. If null is passed query profile references
will cause an exceptionIllegalArgumentException
- if the given name is illegal given the types of this or any nested query profileIllegalStateException
- if this query profile is frozenpublic boolean isExplicit()
public void freeze()
Calling this will also freeze any profiles inherited and referenced by this.
freeze
in interface com.yahoo.component.provider.Freezable
freeze
in class com.yahoo.component.provider.FreezableSimpleComponent
public String toString()
toString
in class com.yahoo.component.AbstractComponent
public QueryProfile clone()
clone
in class com.yahoo.component.provider.FreezableSimpleComponent
static Object cloneIfNecessary(Object object)
public static void validateName(String name)
protected void set(com.yahoo.processing.request.CompoundName name, Object value, DimensionBinding binding, QueryProfileRegistry registry)
protected Object convertToSubstitutionString(Object value)
protected FieldDescription getFieldDescription(com.yahoo.processing.request.CompoundName name, DimensionBinding binding)
Boolean isLocalOverridable(String localName, DimensionBinding binding)
protected Object lookup(com.yahoo.processing.request.CompoundName name, boolean allowQueryProfileResult, DimensionBinding dimensionBinding)
protected final void accept(QueryProfileVisitor visitor, DimensionBinding dimensionBinding, QueryProfile owner)
void acceptAndEnter(String key, QueryProfileVisitor visitor, DimensionBinding dimensionBinding, QueryProfile owner)
final void accept(boolean allowContent, QueryProfileVisitor visitor, DimensionBinding dimensionBinding, QueryProfile owner)
allowContent
- whether content in this should be visitedvisitor
- the visitordimensionBinding
- the dimension binding to useprotected void visitVariants(boolean allowContent, QueryProfileVisitor visitor, DimensionBinding dimensionBinding)
protected void visitInherited(boolean allowContent, QueryProfileVisitor visitor, DimensionBinding dimensionBinding, QueryProfile owner)
private void visitContent(QueryProfileVisitor visitor, DimensionBinding dimensionBinding)
protected Object getContent(String key)
protected Map<String,Object> getContent()
protected QueryProfile setLocalNode(String localName, Object value, QueryProfileType parentType, DimensionBinding dimensionBinding, QueryProfileRegistry registry)
static Object combineValues(Object newValue, Object existingValue)
private static QueryProfile combineProfiles(QueryProfile newProfile, QueryProfile existingProfile)
private static boolean isModifiable(QueryProfile profile)
protected Object checkAndConvertAssignment(String localName, Object value, QueryProfileRegistry registry)
IllegalArgumentException
- if the assignment is illegalprotected QueryProfile createSubProfile(String name, DimensionBinding dimensionBinding)
protected Object localLookup(String name, DimensionBinding dimensionBinding)
private Boolean isDeclaredOverridable(com.yahoo.processing.request.CompoundName name, DimensionBinding dimensionBinding)
private void setOverridable(com.yahoo.processing.request.CompoundName fieldName, boolean overridable, DimensionBinding dimensionBinding)
private void setNode(com.yahoo.processing.request.CompoundName name, Object value, QueryProfileType parentType, DimensionBinding dimensionBinding, QueryProfileRegistry registry)
private QueryProfile lookupParentExact(com.yahoo.processing.request.CompoundName name, boolean create, DimensionBinding dimensionBinding)
name
- the name of the variable to lookup the parent ofcreate
- whether or not to create the parent if it is not presentprivate QueryProfile getQueryProfileExact(String localName, boolean create, DimensionBinding dimensionBinding)
localName
- the local name of the profile in this, this is never a compoundcreate
- whether the profile should be created if missingprivate Object localExactLookup(String name, DimensionBinding dimensionBinding)
private void localPut(String localName, Object value, DimensionBinding dimensionBinding)
public CompiledQueryProfile compile(CompiledQueryProfileRegistry registry)
registry
- the registry this will be added to by the caller, or null if noneCopyright © 2018. All rights reserved.