From fa81283ec4192fc1b754a7862243f564365b0fb3 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Thu, 23 Aug 2018 08:24:00 +0200 Subject: Make Validator.validateXXX methods optional Some of the writers do not support update, also write/delete might not require validation. Therefore, in order to reduce amount of boilerplate code, make validateXXX methods default with empty implementation. Change-Id: Id205b478900024c59834a6e6cb18bdbeb9b43792 Signed-off-by: Marek Gradzki --- .../io/fd/honeycomb/translate/write/Validator.java | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Validator.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Validator.java index 2044757ec..470daa23f 100644 --- a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Validator.java +++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Validator.java @@ -41,10 +41,11 @@ public interface Validator { * @param writeContext Write context that provides information about current state of DataTree. * @throws CreateValidationFailedException if write validation failed */ - void validateWrite( - @Nonnull final InstanceIdentifier id, - @Nonnull final D dataAfter, - @Nonnull final WriteContext writeContext) throws CreateValidationFailedException; + default void validateWrite(@Nonnull final InstanceIdentifier id, + @Nonnull final D dataAfter, + @Nonnull final WriteContext writeContext) throws CreateValidationFailedException { + // Validation on write is optional + } /** * Validates update operation. @@ -55,8 +56,12 @@ public interface Validator { * @param writeContext Write context that provides information about current state of DataTree. * @throws UpdateValidationFailedException if update validation failed */ - void validateUpdate(InstanceIdentifier id, D dataBefore, D dataAfter, WriteContext writeContext) - throws UpdateValidationFailedException; + default void validateUpdate(@Nonnull InstanceIdentifier id, + @Nonnull D dataBefore, + @Nonnull D dataAfter, + @Nonnull WriteContext writeContext) throws UpdateValidationFailedException { + // Validation on update is optional + } /** * Validates delete operation. @@ -66,6 +71,9 @@ public interface Validator { * @param writeContext Write context that provides information about current state of DataTree. * @throws DeleteValidationFailedException if delete validation failed */ - void validateDelete(InstanceIdentifier id, D dataBefore, WriteContext writeContext) - throws DeleteValidationFailedException; + default void validateDelete(@Nonnull InstanceIdentifier id, + @Nonnull D dataBefore, + @Nonnull WriteContext writeContext) throws DeleteValidationFailedException { + // Validation on delete is optional + } } -- cgit 1.2.3-korg