diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2020-02-13 13:37:14 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2020-02-13 13:37:14 +0100 |
commit | 2f1e103ba33d32f60f0c2460ffe0de91247aaa5d (patch) | |
tree | 78edd88785ac1207e96b4220561393e30e2c7bfa /processing | |
parent | 74c0354105f3a00ceb4465eb7cb2aa9c1780e7ef (diff) |
Support clearing values in query profiles
Diffstat (limited to 'processing')
-rw-r--r-- | processing/abi-spec.json | 4 | ||||
-rw-r--r-- | processing/src/main/java/com/yahoo/processing/request/Properties.java | 72 |
2 files changed, 65 insertions, 11 deletions
diff --git a/processing/abi-spec.json b/processing/abi-spec.json index 78058f1a8b7..8f77672faec 100644 --- a/processing/abi-spec.json +++ b/processing/abi-spec.json @@ -329,6 +329,10 @@ "public final void set(java.lang.String, java.lang.Object, java.util.Map)", "public final void set(com.yahoo.processing.request.CompoundName, java.lang.Object)", "public final void set(java.lang.String, java.lang.Object)", + "public void clearAll(com.yahoo.processing.request.CompoundName, java.util.Map)", + "public final void clearAll(java.lang.String, java.lang.Object, java.util.Map)", + "public final void clearAll(com.yahoo.processing.request.CompoundName)", + "public final void clearAll(java.lang.String)", "public final boolean getBoolean(com.yahoo.processing.request.CompoundName)", "public final boolean getBoolean(java.lang.String)", "public final boolean getBoolean(com.yahoo.processing.request.CompoundName, boolean)", diff --git a/processing/src/main/java/com/yahoo/processing/request/Properties.java b/processing/src/main/java/com/yahoo/processing/request/Properties.java index 095a0e51ce0..cadc658417b 100644 --- a/processing/src/main/java/com/yahoo/processing/request/Properties.java +++ b/processing/src/main/java/com/yahoo/processing/request/Properties.java @@ -206,8 +206,8 @@ public class Properties implements Cloneable { * This default implementation forwards to the chained instance or throws * a RuntimeException if there is not chained instance. * - * @param name the name of the value - * @param value the value to set. Setting a name to null explicitly is legal. + * @param name the name of the property + * @param value the value to set. Setting a property to null clears it. * @param context the context used to resolve where the values should be set, or null if none * @throws RuntimeException if no instance in the chain accepted this name-value pair */ @@ -223,8 +223,8 @@ public class Properties implements Cloneable { * This default implementation forwards to the chained instance or throws * a RuntimeException if there is not chained instance. * - * @param name the name of the value - * @param value the value to set. Setting a name to null explicitly is legal. + * @param name the name of the property + * @param value the value to set. Setting a property to null clears it. * @param context the context used to resolve where the values should be set, or null if none * @throws RuntimeException if no instance in the chain accepted this name-value pair */ @@ -235,8 +235,8 @@ public class Properties implements Cloneable { /** * Sets a value to the first chained instance which accepts it by calling set(name,value,null). * - * @param name the name of the value - * @param value the value to set. Setting a name to null explicitly is legal. + * @param name the name of the property + * @param value the value to set. Setting a property to null clears it. * @throws RuntimeException if no instance in the chain accepted this name-value pair */ public final void set(CompoundName name, Object value) { @@ -246,8 +246,8 @@ public class Properties implements Cloneable { /** * Sets a value to the first chained instance which accepts it by calling set(name,value,null). * - * @param name the name of the value - * @param value the value to set. Setting a name to null explicitly is legal. + * @param name the name of the property + * @param value the value to set. Setting a property to null clears it. * @throws RuntimeException if no instance in the chain accepted this name-value pair */ public final void set(String name, Object value) { @@ -255,6 +255,56 @@ public class Properties implements Cloneable { } /** + * Sets all properties having this name as a compound prefix to null. + * I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab". + * This default implementation forwards to the chained instance or throws + * a RuntimeException if there is not chained instance. + * + * @param name the compound prefix of the properties to clear + * @param context the context used to resolve where the values should be cleared, or null if none + * @throws RuntimeException if no instance in the chain accepted this name-value pair + */ + public void clearAll(CompoundName name, Map<String, String> context) { + if (chained == null) throw new RuntimeException("Property '" + name + + "' was not accepted in this property chain"); + chained.clearAll(name, context); + } + + /** + * Sets all properties having this name as a compound prefix to null. + * I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab". + * + * @param name the compound prefix of the properties to clear + * @param context the context used to resolve where the values should be cleared, or null if none + * @throws RuntimeException if no instance in the chain accepted this name-value pair + */ + public final void clearAll(String name, Object value, Map<String, String> context) { + set(new CompoundName(name), value, context); + } + + /** + * Sets all properties having this name as a compound prefix to null. + * I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab". + * + * @param name the compound prefix of the properties to clear + * @throws RuntimeException if no instance in the chain accepted this name-value pair + */ + public final void clearAll(CompoundName name) { + clearAll(name, null); + } + + /** + * Sets all properties having this name as a compound prefix to null. + * I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab". + * + * @param name the compound prefix of the properties to clear + * @throws RuntimeException if no instance in the chain accepted this name-value pair + */ + public final void clearAll(String name) { + clearAll(new CompoundName(name), Collections.<String,String>emptyMap()); + } + + /** * Gets a property as a boolean - if this value can reasonably be interpreted as a boolean, this will return * the value. Returns false if this property is null. */ @@ -571,14 +621,14 @@ public class Properties implements Cloneable { } } - /** - * Clones a map by deep cloning each value which is cloneable and shallow copying all other values. - */ + /** Clones a map by deep cloning each value which is cloneable and shallow copying all other values. */ public static Map<CompoundName, Object> cloneMap(Map<CompoundName, Object> map) { return cloneHelper.cloneMap(map); } + /** Clones this object if it is clonable, and the clone is public. Returns null if not */ public static Object clone(Object object) { return cloneHelper.clone(object); } + } |