From e9d3785d0603bf6e024affafc735641ee312b675 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Thu, 9 Aug 2018 10:07:36 +0200 Subject: AbstractGenericWriter: remove xxxCurrent methods Use xxxCurrentAttributes instead to simplify call graph. Change-Id: I8201b115354dddd35ca0b63b2c72dfb4eac93646 Signed-off-by: Marek Gradzki --- .../translate/impl/write/GenericListWriter.java | 31 ++---------- .../util/write/AbstractGenericWriter.java | 55 ++++++++-------------- 2 files changed, 25 insertions(+), 61 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 5121eb793..ff683b810 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 @@ -85,30 +85,14 @@ public final class GenericListWriter, K e } @Override - protected void writeCurrent(final InstanceIdentifier id, final D data, final WriteContext ctx) - throws WriteFailedException { - super.writeCurrent(getManagedId(id, data), data, ctx); - } - - @Override - protected void updateCurrent(final InstanceIdentifier id, final D dataBefore, final D dataAfter, - final WriteContext ctx) throws WriteFailedException { - super.updateCurrent(getManagedId(id, dataBefore), dataBefore, dataAfter, ctx); - } - - @Override - protected void deleteCurrent(final InstanceIdentifier id, final D dataBefore, final WriteContext ctx) - throws WriteFailedException { - super.deleteCurrent(getManagedId(id, dataBefore), dataBefore, ctx); - } - - @Override - protected InstanceIdentifier getManagedId(@Nonnull final InstanceIdentifier currentId, - @Nonnull final D current) { + @SuppressWarnings("unchecked") + protected InstanceIdentifier getSpecificId(@Nonnull final InstanceIdentifier currentId, + @Nonnull final D current) { final InstanceIdentifier id = (InstanceIdentifier) currentId; // Make sure the key is present if (isWildcarded(id)) { - return getSpecificId(id, current); + return RWUtils.replaceLastInId(id, + new InstanceIdentifier.IdentifiableItem<>(id.getTargetType(), current.getKey())); } else { return id; } @@ -117,9 +101,4 @@ public final class GenericListWriter, K e private boolean isWildcarded(final InstanceIdentifier id) { return id.firstIdentifierOf(getManagedDataObjectType().getTargetType()).isWildcarded(); } - - private InstanceIdentifier getSpecificId(final InstanceIdentifier currentId, final D current) { - return RWUtils.replaceLastInId(currentId, - new InstanceIdentifier.IdentifiableItem<>(currentId.getTargetType(), current.getKey())); - } } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java index ba8f1d992..012b5050f 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java @@ -50,33 +50,6 @@ public abstract class AbstractGenericWriter implements Wri this.validator = validator; } - protected void writeCurrent(final InstanceIdentifier id, final D data, final WriteContext ctx) - throws WriteFailedException { - LOG.debug("{}: Writing current: {} data: {}", this, id, data); - writeCurrentAttributes(id, data, ctx); - LOG.debug("{}: Current node written successfully", this); - } - - protected void updateCurrent(final InstanceIdentifier id, final D dataBefore, final D dataAfter, - final WriteContext ctx) throws WriteFailedException { - LOG.debug("{}: Updating current: {} dataBefore: {}, datAfter: {}", this, id, dataBefore, dataAfter); - - if (dataBefore.equals(dataAfter)) { - LOG.debug("{}: Skipping current(no update): {}", this, id); - // No change, ignore - return; - } - updateCurrentAttributes(id, dataBefore, dataAfter, ctx); - LOG.debug("{}: Current node updated successfully", this); - } - - protected void deleteCurrent(final InstanceIdentifier id, final D dataBefore, final WriteContext ctx) - throws WriteFailedException { - LOG.debug("{}: Deleting current: {} dataBefore: {}", this, id, dataBefore); - deleteCurrentAttributes(id, dataBefore, ctx); - } - - @SuppressWarnings("unchecked") @Override public void processModification(@Nonnull final InstanceIdentifier id, @Nullable final DataObject dataBefore, @@ -89,12 +62,23 @@ public abstract class AbstractGenericWriter implements Wri id, getManagedDataObjectType(), this); if (isWrite(dataBefore, dataAfter)) { - writeCurrent((InstanceIdentifier) id, castToManaged(dataAfter), ctx); + LOG.debug("{}: Writing {} data: {}", this, id, dataAfter); + final D after = castToManaged(dataAfter); + writeCurrentAttributes(getSpecificId(id, after), after, ctx); } else if (isDelete(dataBefore, dataAfter)) { - deleteCurrent((InstanceIdentifier) id, castToManaged(dataBefore), ctx); + LOG.debug("{}: Deleting {} data: {}", this, id, dataBefore); + final D before = castToManaged(dataBefore); + deleteCurrentAttributes(getSpecificId(id, before), before, ctx); } else { + LOG.debug("{}: Updating {} dataBefore: {}, datAfter: {}", this, id, dataBefore, dataAfter); checkArgument(dataBefore != null && dataAfter != null, "No data to process"); - updateCurrent((InstanceIdentifier) id, castToManaged(dataBefore), castToManaged(dataAfter), ctx); + if (dataBefore.equals(dataAfter)) { + LOG.debug("{}: Skipping modification (no update): {}", this, id); + // No change, ignore + return; + } + final D before = castToManaged(dataBefore); + updateCurrentAttributes(getSpecificId(id, before), before, castToManaged(dataAfter), ctx); } } @@ -113,10 +97,10 @@ public abstract class AbstractGenericWriter implements Wri if (isWrite(dataBefore, dataAfter)) { final D after = castToManaged(dataAfter); - validator.validateWrite(getManagedId(id, after), after, ctx); + validator.validateWrite(getSpecificId(id, after), after, ctx); } else if (isDelete(dataBefore, dataAfter)) { final D before = castToManaged(dataBefore); - validator.validateDelete(getManagedId(id, before), before, ctx); + validator.validateDelete(getSpecificId(id, before), before, ctx); } else { checkArgument(dataBefore != null && dataAfter != null, "No data to process"); if (dataBefore.equals(dataAfter)) { @@ -125,12 +109,13 @@ public abstract class AbstractGenericWriter implements Wri return; } final D before = castToManaged(dataBefore); - validator.validateUpdate(getManagedId(id, before), before, castToManaged(dataAfter), ctx); + validator.validateUpdate(getSpecificId(id, before), before, castToManaged(dataAfter), ctx); } } - protected InstanceIdentifier getManagedId(@Nonnull final InstanceIdentifier currentId, - @Nonnull final D current) { + @SuppressWarnings("unchecked") + protected InstanceIdentifier getSpecificId(@Nonnull final InstanceIdentifier currentId, + @Nonnull final D current) { return (InstanceIdentifier) currentId; } -- cgit 1.2.3-korg