public class NetricsPredicateMapper
extends java.lang.Object
The ANetricsQueryBuilder class tracks two sets of names:
$"field-name".
Field name expressions cannot appear in string constants or other
field name expressions. They appear only at the top level of
the Predicate String Expression.
${data-item-name}. All text between the curly braces
is the name of the input data field. Input data items can appear
both at the top level and within string constants.
To allow the character sequence ${ to be expressed
in a string constant (or elsewhere) the sequence $\
can be used to represent a single dollar sign that has no special
meaning. This sequence is translated to a single dollar sign
character by this class.
The ANetricsQueryBuilder class allows both the input and output field names to be updated at run time. This class must support these operations. It does so through the setFieldNames and setDataNames methods.
The class must also allow the data values to be inserted into the expression. The getMappedExpr method is used to retrieve the fully mapped Predicate String Expression.
When a data value is inserted into a predicate expression string constant the mapper will encode the value before inserting it. The value should not be encoded before passing it to the predicate expression mapper.
Some Things To Note:
This class does not validate the predicate expression syntax. If given an invalid predicate expression, it will quietly generate an invalid predicate expression.
A data item name may contain any character except a closing curly
brace. This includes double quotes. So expressions of the form
$"first" = "${"data-item-1"}" are valid. Beware of:
$"first" = "${data-item-1"} : this is an unterminated
string constant.
Unterminated field names expressions or data item expressions
are treated as fixed values. For example:
"George" = $"first and "George" = "${first"
are both output exactly as is, as neither has a substitution section.
The unterminated Field Name and Data sections are treated as if
they were fixed text.
| Constructor and Description |
|---|
NetricsPredicateMapper(java.lang.String pred_str)
Create a predicate expression string mapper.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.Set<java.lang.String> |
getCurrentDataNames()
Get the set of the current data item names.
|
java.util.Set<java.lang.String> |
getCurrentFieldNames()
Get the set of the current field names.
|
java.lang.String |
getMappedExpr(java.util.List<java.lang.String> data_names,
java.util.List<java.lang.String> data_values)
Get the fully mapped predicate expression.
|
java.lang.String |
getMappedExpr(java.util.Map<java.lang.String,java.lang.String> data_values)
Get the fully mapped predicate expression.
|
java.util.Set<java.lang.String> |
getOriginalDataNames()
Get the set of the original data item names.
|
java.util.Set<java.lang.String> |
getOriginalFieldNames()
Get the set of the original field names.
|
NetricsPredicateMapper |
setDataNames(java.util.List<java.lang.String> original_names,
java.util.List<java.lang.String> new_names)
Update the data item name mappings.
|
NetricsPredicateMapper |
setDataNames(java.util.Map<java.lang.String,java.lang.String> data_names)
Update the data item name mappings.
|
NetricsPredicateMapper |
setDefaultValue(java.lang.String default_value)
Set the default value for unspecified data items.
|
NetricsPredicateMapper |
setFieldNames(java.util.List<java.lang.String> original_names,
java.util.List<java.lang.String> new_names)
Update the field name mappings.
|
NetricsPredicateMapper |
setFieldNames(java.util.Map<java.lang.String,java.lang.String> field_map)
Update the field name mappings.
|
public NetricsPredicateMapper(java.lang.String pred_str)
${data-item-name} expressions.pred_str - the predicate expression string to be mapped.public NetricsPredicateMapper setDefaultValue(java.lang.String default_value)
default_value - the default value for unspecified
strings. If null a zero length string
is used (the default).public java.util.Set<java.lang.String> getOriginalFieldNames()
public java.util.Set<java.lang.String> getCurrentFieldNames()
public java.util.Set<java.lang.String> getOriginalDataNames()
public java.util.Set<java.lang.String> getCurrentDataNames()
public NetricsPredicateMapper setFieldNames(java.util.Map<java.lang.String,java.lang.String> field_map)
field_map - a mapping where the key is the original field
name and the value is the new name to use.
If this is null it reverts to using the original
field names. Any field name not included in the
map is left as the original name.public NetricsPredicateMapper setFieldNames(java.util.List<java.lang.String> original_names, java.util.List<java.lang.String> new_names) throws java.lang.IllegalArgumentException
original_names - a list of the original field names.new_names - a list of the new names. The names must
be in the same position in the list as the
associated original name in the
original_names list.java.lang.IllegalArgumentException - if either argument is null,
or the two lists are different lengths.public NetricsPredicateMapper setDataNames(java.util.Map<java.lang.String,java.lang.String> data_names)
data_names - a mapping where the key is the original data item
name, and the value is the new data item name to use.
If this is null it reverts to using the original data
item names. Any data item not included in the map
is left as the original name.public NetricsPredicateMapper setDataNames(java.util.List<java.lang.String> original_names, java.util.List<java.lang.String> new_names) throws java.lang.IllegalArgumentException
original_names - a list of the original data item names.new_names - a list of the new names. The names must
be in the same position in the list as the
associated original name in the
original_names list.java.lang.IllegalArgumentException - if either argument is null,
or the two lists have different lengths.public java.lang.String getMappedExpr(java.util.Map<java.lang.String,java.lang.String> data_values)
$\
values. The returned string has all of the currently defined field
name mappings applied. Data items that do not appear in the given
data_values map are assigned the default value.
Data values inserted into predicate string constants have the special characters: &, ", \n and \0 encoded as &, ", and � respectively.
data_values - a mapping where the key is the mapped data
item name, and the value is the value for that
data item.public java.lang.String getMappedExpr(java.util.List<java.lang.String> data_names,
java.util.List<java.lang.String> data_values)
throws java.lang.IllegalArgumentException
$\
values. The returned string has all of the currently defined field
name mappings applied. Data items that do not appear in the given
lists are assigned the default value.
Data values inserted into predicate string constants have the special characters: &, ", \n and \0 encoded as &, ", and � respectively.
data_names - a list of the current data item names.data_values - a list of the data item values. The values must
be in the same position in the list as the
associated name in the data_names list.java.lang.IllegalArgumentException - if either argument is null,
or the two lists have different lengths.