From 4c9206d8119d1131e248419c7e1ba669c396b89b Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 15 Feb 2023 13:52:23 +0100 Subject: Exchange BCP info WIP --- vespajlib/src/main/java/com/yahoo/slime/Inspector.java | 5 +++++ vespajlib/src/main/java/com/yahoo/slime/Value.java | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'vespajlib') 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 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 consumer) { + if (valid()) consumer.accept(this); + } + public int children() { return 0; } public int entries() { return 0; } public int fields() { return 0; } -- cgit v1.2.3