From 299ea091899183df220c3ae7943cd4ea53cf6ac3 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 31 Jul 2018 18:12:21 +0200 Subject: Remove code repetitions from GenericListWriter Change-Id: I4efbdcc4bc12e29bd767c7b8fa6696de62ac1d37 Signed-off-by: Marek Gradzki --- .../translate/impl/write/GenericListWriter.java | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java index 6fbef8e84..92467a8e8 100644 --- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java +++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java @@ -79,33 +79,27 @@ public final class GenericListWriter, K e @Override protected void writeCurrent(final InstanceIdentifier id, final D data, final WriteContext ctx) throws WriteFailedException { - // Make sure the key is present - if (isWildcarded(id)) { - super.writeCurrent(getSpecificId(id, data), data, ctx); - } else { - super.writeCurrent(id, data, ctx); - } + super.writeCurrent(getId(id, data), data, ctx); } @Override protected void updateCurrent(final InstanceIdentifier id, final D dataBefore, final D dataAfter, final WriteContext ctx) throws WriteFailedException { - // Make sure the key is present - if (isWildcarded(id)) { - super.updateCurrent(getSpecificId(id, dataBefore), dataBefore, dataAfter, ctx); - } else { - super.updateCurrent(id, dataBefore, dataAfter, ctx); - } + super.updateCurrent(getId(id, dataBefore), dataBefore, dataAfter, ctx); } @Override protected void deleteCurrent(final InstanceIdentifier id, final D dataBefore, final WriteContext ctx) throws WriteFailedException { + super.deleteCurrent(getId(id, dataBefore), dataBefore, ctx); + } + + private InstanceIdentifier getId(final InstanceIdentifier id, final D current) { // Make sure the key is present if (isWildcarded(id)) { - super.deleteCurrent(getSpecificId(id, dataBefore), dataBefore, ctx); + return getSpecificId(id, current); } else { - super.deleteCurrent(id, dataBefore, ctx); + return id; } } -- cgit 1.2.3-korg