import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.CheckedFuture;
-import java.util.Collections;
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
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;
/**
private void ensureListParentIfNeeded(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalized) {
if (Identifiable.class.isAssignableFrom(path.getTargetType())) {
- YangInstanceIdentifier parentMapPath = getParent(normalized.getKey()).get();
+ YangInstanceIdentifier parentMapPath = normalized.getKey().getParent();
+ Preconditions.checkArgument(parentMapPath != null, "Map path %s does not have a parent", path);
+
NormalizedNode<?, ?> emptyParent = getCodec().getDefaultNodeFor(parentMapPath);
getDelegate().merge(store, parentMapPath, emptyParent);
}
}
- // FIXME (should be probaly part of InstanceIdentifier)
- protected static Optional<YangInstanceIdentifier> getParent(
- final YangInstanceIdentifier child) {
-
- Iterable<PathArgument> mapEntryItemPath = child.getPathArguments();
- int parentPathSize = Iterables.size(mapEntryItemPath) - 1;
- if (parentPathSize > 1) {
- return Optional.of(YangInstanceIdentifier.create(Iterables.limit(mapEntryItemPath, parentPathSize)));
- } else if(parentPathSize == 0) {
- return Optional.of(YangInstanceIdentifier.create(Collections.<PathArgument>emptyList()));
- } else {
- return Optional.absent();
- }
+ /**
+ * @deprecated Use {@link YangInstanceIdentifier#getParent()} instead.
+ */
+ @Deprecated
+ protected static Optional<YangInstanceIdentifier> getParent(final YangInstanceIdentifier child) {
+ return Optional.fromNullable(child.getParent());
}
/**
package org.opendaylight.controller.cluster.datastore.node.utils.stream;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
}
private void writeYangInstanceIdentifierInternal(YangInstanceIdentifier identifier) throws IOException {
- Iterable<YangInstanceIdentifier.PathArgument> pathArguments = identifier.getPathArguments();
- int size = Iterables.size(pathArguments);
- output.writeInt(size);
+ Collection<YangInstanceIdentifier.PathArgument> pathArguments = identifier.getPathArguments();
+ output.writeInt(pathArguments.size());
for(YangInstanceIdentifier.PathArgument pathArgument : pathArguments) {
writePathArgument(pathArgument);
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.net.URI;
final Optional<ModifyAction> operation, final Optional<NormalizedNode<?, ?>> lastChildOverride) {
final NormalizedNode<?, ?> configContent;
- if(Iterables.isEmpty(dataPath.getPathArguments())) {
+ if (dataPath.isEmpty()) {
Preconditions.checkArgument(lastChildOverride.isPresent(), "Data has to be present when creating structure for top level element");
Preconditions.checkArgument(lastChildOverride.get() instanceof DataContainerChild<?, ?>,
"Data has to be either container or a list node when creating structure for top level element, but was: %s", lastChildOverride.get());
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
final YangInstanceIdentifier pathIdentifier = ((YangInstanceIdentifier) pathValue);
String streamName = null;
- if (!Iterables.isEmpty(pathIdentifier.getPathArguments())) {
+ if (!pathIdentifier.isEmpty()) {
final String fullRestconfIdentifier = controllerContext.toFullRestconfIdentifier(pathIdentifier, null);
LogicalDatastoreType datastore = parseEnumTypeParameter(value, LogicalDatastoreType.class,
final YangInstanceIdentifier identifier) {
final String payloadName = node.getData().getNodeType().getLocalName();
- final Iterator<PathArgument> pathArguments = identifier.getReversePathArguments().iterator();
//no arguments
- if ( ! pathArguments.hasNext()) {
+ if (identifier.isEmpty()) {
//no "data" payload
- if ( ! node.getData().getNodeType().equals(NETCONF_BASE_QNAME)) {
+ if (!node.getData().getNodeType().equals(NETCONF_BASE_QNAME)) {
throw new RestconfDocumentedException("Instance identifier has to contain at least one path argument",
ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
//any arguments
} else {
- final String identifierName = pathArguments.next().getNodeType().getLocalName();
- if ( ! payloadName.equals(identifierName)) {
+ final String identifierName = identifier.getLastPathArgument().getNodeType().getLocalName();
+ if (!payloadName.equals(identifierName)) {
throw new RestconfDocumentedException("Payload name (" + payloadName
+ ") is different from identifier name (" + identifierName + ")", ErrorType.PROTOCOL,
ErrorTag.MALFORMED_MESSAGE);