summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2023-02-15 13:52:23 +0100
committerJon Bratseth <bratseth@gmail.com>2023-02-15 13:52:23 +0100
commit4c9206d8119d1131e248419c7e1ba669c396b89b (patch)
tree414dfdc40c088e06c108e28a7f050bf375ce9d3b /vespajlib
parentb9b7e3cf8529e6f7e9904c1013174e37c0460696 (diff)
Exchange BCP info WIP
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/slime/Inspector.java5
-rw-r--r--vespajlib/src/main/java/com/yahoo/slime/Value.java6
2 files changed, 11 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/slime/Inspector.java b/vespajlib/src/main/java/com/yahoo/slime/Inspector.java
index d72a8888b2c..948a810a39e 100644
--- a/vespajlib/src/main/java/com/yahoo/slime/Inspector.java
+++ b/vespajlib/src/main/java/com/yahoo/slime/Inspector.java
@@ -1,6 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.slime;
+import java.util.function.Consumer;
+
/**
* Interface for read-only access to any value or object that is part
* of a Slime. You can access meta-data such as validity and actual
@@ -17,6 +19,9 @@ public interface Inspector {
/** check if this inspector is valid */
boolean valid();
+ /** Invoke the given consumer with this value if it is valid */
+ void ifValid(Consumer<Inspector> consumer);
+
/** return an enum describing value type */
Type type();
diff --git a/vespajlib/src/main/java/com/yahoo/slime/Value.java b/vespajlib/src/main/java/com/yahoo/slime/Value.java
index 6fb267ab9bb..053b06b97c4 100644
--- a/vespajlib/src/main/java/com/yahoo/slime/Value.java
+++ b/vespajlib/src/main/java/com/yahoo/slime/Value.java
@@ -3,6 +3,7 @@ package com.yahoo.slime;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
+import java.util.function.Consumer;
/**
* Common implementation for all value types.
@@ -17,6 +18,11 @@ abstract class Value implements Cursor {
private static final byte[] emptyData = new byte[0];
public final boolean valid() { return this != NixValue.invalid(); }
+
+ public final void ifValid(Consumer<Inspector> consumer) {
+ if (valid()) consumer.accept(this);
+ }
+
public int children() { return 0; }
public int entries() { return 0; }
public int fields() { return 0; }