summaryrefslogtreecommitdiffstats
path: root/infra/translate-spi
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-11-08 10:13:36 +0100
committerMaros Marsalek <mmarsale@cisco.com>2016-11-08 13:17:57 +0100
commit757222979bc02d0aaba1870eea36413383d15bde (patch)
tree3fe2a502026fbfa9a4ae5627e1a453a057f6c1fa /infra/translate-spi
parent03a638b95da83e150d4f69451c8733b5f09c37aa (diff)
HONEYCOMB-270 Add isPresent() to Readers/Customizers
So that they can influence whether empty data is to be considered as present + Move registries implementations from util to impl + Introduce DelegatingReader trait + Extend GenericReader where possible to reduce duplication Change-Id: I5a416acd0c4eab1fbc30fcbe585719991dbe9215 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/translate-spi')
-rw-r--r--infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java
index acfabf5bc..738431eea 100644
--- a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java
+++ b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java
@@ -57,4 +57,19 @@ public interface ReaderCustomizer<O extends DataObject, B extends Builder<O>> {
void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final O readValue);
+ /**
+ * Check whether the resulting value should be added to the results or ignored.
+ * Invoked after {@link #readCurrentAttributes(InstanceIdentifier, Builder, ReadContext)}
+ *
+ * @param id Keyed instance identifier of read data
+ * @param built Read data as returned from builder
+ * after {@link #readCurrentAttributes(InstanceIdentifier, Builder, ReadContext)} invocation
+ * @param ctx Read context
+ *
+ * @return true if value is present (even if empty)
+ */
+ default boolean isPresent(final InstanceIdentifier<O> id, final O built, final ReadContext ctx) throws ReadFailedException {
+ // Default impl = check whether read value is empty
+ return !built.equals(getBuilder(id).build());
+ }
}