*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
qname.getModule());
}
- checkArgument(!qname.getRevision().isPresent(), "Failed to find bound annotation %s", qname);
- checkArgument(value instanceof String, "Invalid non-string value %s for unbound annotation %s", value, qname);
- return (String) value;
+ if (qname.getRevision().isPresent()) {
+ throw new IllegalArgumentException("Failed to find bound annotation " + qname);
+ }
+ if (value instanceof String str) {
+ return str;
+ }
+ throw new IllegalArgumentException("Invalid non-string value " + value + " for unbound annotation " + qname);
}
@Override
protected final void checkTouchApplicable(final ModificationPath path, final NodeModification modification,
final Optional<? extends TreeNode> current, final Version version) throws DataValidationFailedException {
final TreeNode currentNode;
- if (!current.isPresent()) {
+ if (current.isEmpty()) {
currentNode = defaultTreeNode();
if (currentNode == null) {
- if (!modification.getOriginal().isPresent()) {
+ if (modification.getOriginal().isEmpty()) {
final YangInstanceIdentifier id = path.toInstanceIdentifier();
throw new ModifiedNodeDoesNotExistException(id,
- String.format("Node %s does not exist. Cannot apply modification to its children.", id));
+ "Node " + id + " does not exist. Cannot apply modification to its children.");
}
throw new ConflictingModificationAppliedException(path.toInstanceIdentifier(),
}
// Delete with children, implies it really is an empty write
ret = Optional.of(writeDelegate.applyWrite(modification, emptyNode, storeMeta, version));
- } else if (modification.getOperation() == LogicalOperation.TOUCH && !storeMeta.isPresent()) {
+ } else if (modification.getOperation() == LogicalOperation.TOUCH && storeMeta.isEmpty()) {
ret = applyTouch(delegate, emptyNode, modification, storeMeta, version);
} else {
// No special handling required here, run normal apply operation
// We are pulling the 'disappear' trick, but what we report can be three different things
final ModificationType finalType;
- if (!storeMeta.isPresent()) {
+ if (storeMeta.isEmpty()) {
// ... there was nothing in the datastore, no change
finalType = ModificationType.UNMODIFIED;
} else if (modification.getModificationType() == ModificationType.WRITE) {
void enforceOnData(final NormalizedNode data) {
for (var path : mandatoryNodes) {
- if (!NormalizedNodes.findNode(data, path).isPresent()) {
- throw new IllegalArgumentException(String.format("Node %s is missing mandatory descendant %s",
- data.name(), YangInstanceIdentifier.of(path)));
+ if (NormalizedNodes.findNode(data, path).isEmpty()) {
+ throw new IllegalArgumentException("Node " + data.name() + " is missing mandatory descendant "
+ + YangInstanceIdentifier.of(path));
}
}
}
*/
private static void checkWriteApplicable(final ModificationPath path, final NodeModification modification,
final Optional<? extends TreeNode> current, final Version version) throws DataValidationFailedException {
- final Optional<? extends TreeNode> original = modification.getOriginal();
+ final var original = modification.getOriginal();
if (original.isPresent() && current.isPresent()) {
checkNotConflicting(path, original.orElseThrow(), current.orElseThrow());
} else {
- checkConflicting(path, !original.isPresent(), "Node was deleted by other transaction.");
- checkConflicting(path, !current.isPresent(), "Node was created by other transaction.");
+ checkConflicting(path, original.isEmpty(), "Node was deleted by other transaction.");
+ checkConflicting(path, current.isEmpty(), "Node was created by other transaction.");
}
}
private static void checkDeleteApplicable(final NodeModification modification,
final Optional<? extends TreeNode> current) {
// Delete is always applicable, we do not expose it to subclasses
- if (!current.isPresent()) {
+ if (current.isEmpty()) {
LOG.trace("Delete operation turned to no-op on missing node {}", modification);
}
}
case MERGE -> {
final TreeNode result;
- if (!currentMeta.isPresent()) {
+ if (currentMeta.isEmpty()) {
// This is a slight optimization: a merge on a non-existing node equals to a write. Written data
// structure is usually verified when the transaction is sealed. To preserve correctness, we have
// to run that validation here.
DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
- assertTrue(!minMaxListRead.isPresent());
+ assertFalse(minMaxListRead.isPresent());
modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
// FIXME: this really should be handled via separate inference, i.e. we first instantiate the template and when
// it appears, this refine will trigger on it. This reinforces the FIXME below.
final var optRefineTargetCtx = ParserNamespaces.findSchemaTreeStatement(usesParentCtx, refineDescendant);
- InferenceException.throwIf(!optRefineTargetCtx.isPresent(), refineStmtCtx, "Refine target node %s not found.",
+ InferenceException.throwIf(optRefineTargetCtx.isEmpty(), refineStmtCtx, "Refine target node %s not found.",
refineDescendant);
// FIXME: This communicates the looked-up target node to RefineStatementSupport.buildEffective(). We should do
AugmentationSchemaNode augment2 = null;
AugmentationSchemaNode augment3 = null;
for (final AugmentationSchemaNode as : augmentations) {
- if (!as.getWhenCondition().isPresent()) {
+ if (as.getWhenCondition().isEmpty()) {
augment3 = as;
} else if ("br:ifType='ds0'".equals(as.getWhenCondition().orElseThrow().toString())) {
augment1 = as;