<description>${project.artifactId}</description>
<dependencies>
- <dependency>
- <groupId>com.github.spotbugs</groupId>
- <artifactId>spotbugs-annotations</artifactId>
- <optional>true</optional>
- </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
requires org.slf4j;
// Annotations
- requires static com.github.spotbugs.annotations;
requires static org.eclipse.jdt.annotation;
requires static org.kohsuke.metainf_services;
requires static org.osgi.service.component.annotations;
@Override
final Optional<? extends TreeNode> apply(final ModifiedNode modification,
final Optional<? extends TreeNode> storeMeta, final Version version) {
- Optional<? extends TreeNode> ret = modification.getValidatedNode(this, storeMeta);
- if (ret == null) {
- // This might also mean the delegate is maintaining validation
- if (delegate instanceof AbstractValidation) {
- ret = modification.getValidatedNode(delegate, storeMeta);
- if (ret != null) {
- return ret;
- }
- }
+ var validated = modification.validatedNode(this, storeMeta);
+ if (validated != null) {
+ return validated.toOptional();
+ }
- // Deal with the result moving on us
- ret = delegate.apply(modification, storeMeta, version);
- ret.ifPresent(meta -> enforceOnData(meta.getData()));
+ // This might also mean the delegate is maintaining validation
+ if (delegate instanceof AbstractValidation) {
+ validated = modification.validatedNode(delegate, storeMeta);
+ if (validated != null) {
+ return validated.toOptional();
+ }
}
+
+ // Deal with the result moving on us
+ final var ret = delegate.apply(modification, storeMeta, version);
+ ret.ifPresent(meta -> enforceOnData(meta.getData()));
return ret;
}
}
if (delegate instanceof AbstractValidation) {
- checkApplicable(path, verifyNotNull(modified.getValidatedNode(delegate, current)));
+ checkApplicable(path, verifyNotNull(modified.validatedNode(delegate, current)).toOptional());
return;
}
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
// Internal cache for TreeNodes created as part of validation
private ModificationApplyOperation validatedOp;
private Optional<? extends TreeNode> validatedCurrent;
- private Optional<? extends TreeNode> validatedNode;
+ private ValidatedTreeNode validatedNode;
private ModifiedNode(final PathArgument identifier, final Optional<? extends TreeNode> original,
final ChildTrackingPolicy childPolicy) {
final Optional<? extends TreeNode> node) {
validatedOp = requireNonNull(op);
validatedCurrent = requireNonNull(current);
- validatedNode = requireNonNull(node);
+ validatedNode = new ValidatedTreeNode(node);
}
/**
* @return {@code null} if there is a mismatch with previously-validated node (if present) or the result of previous
* validation.
*/
- @SuppressFBWarnings(value = "NP_OPTIONAL_RETURN_NULL",
- justification = "The contract is package-internal and well documented, we do not need a separate wrapper")
- @Nullable Optional<? extends TreeNode> getValidatedNode(final ModificationApplyOperation op,
+ @Nullable ValidatedTreeNode validatedNode(final ModificationApplyOperation op,
final Optional<? extends TreeNode> current) {
return op.equals(validatedOp) && current.equals(validatedCurrent) ? validatedNode : null;
}
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.tree.impl;
+
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
+
+@SuppressWarnings("null")
+record ValidatedTreeNode(@Nullable TreeNode treeNode) {
+ ValidatedTreeNode(final Optional<? extends TreeNode> optional) {
+ this(optional.orElse(null));
+ }
+
+ @NonNull Optional<TreeNode> toOptional() {
+ return Optional.ofNullable(treeNode);
+ }
+}