summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils/src/main
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-08-09 10:07:36 +0200
committerMarek Gradzki <mgradzki@cisco.com>2018-08-17 10:18:19 +0000
commite9d3785d0603bf6e024affafc735641ee312b675 (patch)
tree6e3346b7628497743ebfc986952b15edb7cc8b04 /infra/translate-utils/src/main
parentd1b102f6fafced3c7badb09ecc78fec590704c8a (diff)
AbstractGenericWriter: remove xxxCurrent methods
Use xxxCurrentAttributes instead to simplify call graph. Change-Id: I8201b115354dddd35ca0b63b2c72dfb4eac93646 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main')
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java55
1 files changed, 20 insertions, 35 deletions
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<D extends DataObject> implements Wri
this.validator = validator;
}
- protected void writeCurrent(final InstanceIdentifier<D> 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<D> 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<D> 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<? extends DataObject> id,
@Nullable final DataObject dataBefore,
@@ -89,12 +62,23 @@ public abstract class AbstractGenericWriter<D extends DataObject> implements Wri
id, getManagedDataObjectType(), this);
if (isWrite(dataBefore, dataAfter)) {
- writeCurrent((InstanceIdentifier<D>) 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<D>) 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<D>) 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<D extends DataObject> 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<D extends DataObject> 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<D> getManagedId(@Nonnull final InstanceIdentifier<? extends DataObject> currentId,
- @Nonnull final D current) {
+ @SuppressWarnings("unchecked")
+ protected InstanceIdentifier<D> getSpecificId(@Nonnull final InstanceIdentifier<? extends DataObject> currentId,
+ @Nonnull final D current) {
return (InstanceIdentifier<D>) currentId;
}