diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2018-08-23 08:24:00 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-08-23 08:36:14 +0200 |
commit | fa81283ec4192fc1b754a7862243f564365b0fb3 (patch) | |
tree | 90d8140ff66f659e65ad901b36b68a6b4d59cece | |
parent | cf7927bd7d122b187313952dd159d55241538942 (diff) |
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 <mgradzki@cisco.com>
-rw-r--r-- | infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Validator.java | 24 |
1 files 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<D extends DataObject> { * @param writeContext Write context that provides information about current state of DataTree. * @throws CreateValidationFailedException if write validation failed */ - void validateWrite( - @Nonnull final InstanceIdentifier<D> id, - @Nonnull final D dataAfter, - @Nonnull final WriteContext writeContext) throws CreateValidationFailedException; + default void validateWrite(@Nonnull final InstanceIdentifier<D> 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<D extends DataObject> { * @param writeContext Write context that provides information about current state of DataTree. * @throws UpdateValidationFailedException if update validation failed */ - void validateUpdate(InstanceIdentifier<D> id, D dataBefore, D dataAfter, WriteContext writeContext) - throws UpdateValidationFailedException; + default void validateUpdate(@Nonnull InstanceIdentifier<D> 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<D extends DataObject> { * @param writeContext Write context that provides information about current state of DataTree. * @throws DeleteValidationFailedException if delete validation failed */ - void validateDelete(InstanceIdentifier<D> id, D dataBefore, WriteContext writeContext) - throws DeleteValidationFailedException; + default void validateDelete(@Nonnull InstanceIdentifier<D> id, + @Nonnull D dataBefore, + @Nonnull WriteContext writeContext) throws DeleteValidationFailedException { + // Validation on delete is optional + } } |