+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. 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.impl.schema.tree;
-
-import java.util.Optional;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
-
-/**
- * An implementation of apply operation which fails to do anything, consistently. An instance of this class is used by
- * the data tree if it does not have a SchemaContext attached and hence cannot perform anything meaningful.
- */
-final class AlwaysFailOperation extends NonApplyDelegatedModificationApplyOperation {
- static final ModificationApplyOperation INSTANCE = new AlwaysFailOperation();
-
- private AlwaysFailOperation() {
-
- }
-
- @Override
- ModificationApplyOperation delegate() {
- throw ise();
- }
-
- @Override
- Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
- final Version version) {
- throw ise();
- }
-
- @Override
- void checkApplicable(final ModificationPath path, final NodeModification modification,
- final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
- throw ise();
- }
-
- private static IllegalStateException ise() {
- return new IllegalStateException("Schema Context is not available.");
- }
-}
}
ModificationApplyOperation getStrategy() {
- return strategyTree.delegate();
+ final ModificationApplyOperation ret = strategyTree.delegate();
+ if (ret == null) {
+ throw new IllegalStateException("Schema Context is not available.");
+ }
+ return ret;
}
@Override
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+import static java.util.Objects.requireNonNull;
+
/**
* Holder and factory for upgradable root modifications.
*
*/
final class LatestOperationHolder {
- private ModificationApplyOperation current = AlwaysFailOperation.INSTANCE;
+ private ModificationApplyOperation current;
/**
* Return latest backing implementation.
* @param newApplyOper New backing implementation
*/
void setCurrent(final ModificationApplyOperation newApplyOper) {
- current = newApplyOper;
+ current = requireNonNull(newApplyOper);
}
/**
+++ /dev/null
-/*
- * Copyright (c) 2019 Pantheon Technologies, 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.impl.schema.tree;
-
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * A {@link ModificationApplyOperation} which delegates all invocations except checkApplicable()/apply() to a delegate
- * instance.
- */
-abstract class NonApplyDelegatedModificationApplyOperation extends DelegatingModificationApplyOperation {
- @Override
- final void fullVerifyStructure(final NormalizedNode<?, ?> modification) {
- delegate().fullVerifyStructure(modification);
- }
-}
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import com.google.common.collect.ForwardingObject;
+import java.util.Objects;
/**
* Represents a {@link ModificationApplyOperation} which is rooted at conceptual
@Override
public final boolean equals(final Object obj) {
- return delegate().equals(obj);
+ return Objects.equals(delegate(), obj);
}
@Override
public final int hashCode() {
- return delegate().hashCode();
+ return Objects.hashCode(delegate());
}
@Override
public final String toString() {
- return delegate().toString();
+ return Objects.toString(delegate());
}
/**
@Override
void upgradeIfPossible() {
ModificationApplyOperation holderCurrent = holder.getCurrent();
- if (holderCurrent != delegate) {
+ if (holderCurrent != null && holderCurrent != delegate) {
// FIXME: Allow update only if there is addition of models, not
// removals.
delegate = holderCurrent;