import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.Optional;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class InMemoryDataTreeModification extends AbstractCursorAware implements CursorAwareDataTreeModification,
- EffectiveModelContextProvider {
+final class InMemoryDataTreeModification extends AbstractCursorAware implements CursorAwareDataTreeModification {
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDataTreeModification.class);
private static final byte STATE_OPEN = 0;
// All access needs to go through STATE
@SuppressWarnings("unused")
+ @SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "https://github.com/spotbugs/spotbugs/issues/2749")
private volatile byte state;
InMemoryDataTreeModification(final InMemoryDataTreeSnapshot snapshot,
* node in modification and in data tree (if successfully
* committed) will be same and will not change.
*/
- version = snapshot.getRootNode().getSubtreeVersion().next();
+ version = snapshot.getRootNode().subtreeVersion().next();
}
ModifiedNode getRootModification() {
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
- return snapshot.getEffectiveModelContext();
+ public EffectiveModelContext modelContext() {
+ return snapshot.modelContext();
}
@Override
final var terminalPath = terminal.getKey();
final var result = resolveSnapshot(terminalPath, terminal.getValue());
- if (result.isPresent()) {
- final var data = result.orElseThrow().getData();
- return NormalizedNodes.findNode(terminalPath, data, path);
- }
-
- return Optional.empty();
+ return result == null ? Optional.empty() : NormalizedNodes.findNode(terminalPath, result.data(), path);
}
@SuppressWarnings("checkstyle:illegalCatch")
- private Optional<? extends TreeNode> resolveSnapshot(final YangInstanceIdentifier path,
- final ModifiedNode modification) {
+ private @Nullable TreeNode resolveSnapshot(final YangInstanceIdentifier path, final ModifiedNode modification) {
final var potentialSnapshot = modification.getSnapshot();
if (potentialSnapshot != null) {
- return potentialSnapshot;
+ return potentialSnapshot.orElse(null);
}
try {
* have same version each time this method is called.
*/
final var originalSnapshotRoot = snapshot.getRootNode();
- return new InMemoryDataTreeSnapshot(snapshot.getEffectiveModelContext(),
- getStrategy().apply(rootNode, originalSnapshotRoot, version)
- .orElseThrow(() -> new IllegalStateException(
- "Data tree root is not present, possibly removed by previous modification")), strategyTree)
- .newModification();
+ final var newRoot = getStrategy().apply(rootNode, originalSnapshotRoot, version);
+ if (newRoot == null) {
+ throw new IllegalStateException("Data tree root is not present, possibly removed by previous modification");
+ }
+ return new InMemoryDataTreeSnapshot(snapshot.modelContext(), newRoot, strategyTree).newModification();
}
Version getVersion() {