import com.google.common.cache.LoadingCache;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
-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.model.api.SchemaContext;
return getRoot().findChild(path);
}
- /**
- * Get a child node as identified by an absolute {@link YangInstanceIdentifier}.
- *
- * @param path Path towards the child node
- * @return Child node if present, or null when corresponding child is not found.
- * @throws NullPointerException if {@code path} is null
- *
- * @deprecated Use {@link #findChild(YangInstanceIdentifier)} instead.
- */
- @Deprecated(forRemoval = true)
- public @Nullable DataSchemaContextNode<?> getChild(final YangInstanceIdentifier path) {
- DataSchemaContextNode<?> currentOp = root;
- for (PathArgument arg : path.getPathArguments()) {
- currentOp = currentOp.getChild(arg);
- if (currentOp == null) {
- return null;
- }
- }
- return currentOp;
- }
-
public DataSchemaContextNode<?> getRoot() {
return root;
}
package org.opendaylight.yangtools.yang.data.util.codec;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.net.URI;
assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO)).isPresent());
assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR)).isPresent());
assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO).node(BAR).node(BAZ)).isPresent());
-
- assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO)));
- assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO).node(BAR)));
- assertNotNull(CONTEXT.getChild(YangInstanceIdentifier.of(FOO).node(BAR).node(BAZ)));
}
@Test
public void testSimpleBad() {
assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR)));
- assertNull(CONTEXT.getChild(YangInstanceIdentifier.of(BAR)));
}
@Test
public void testNestedBad() {
assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR).node(BAZ)));
- assertNull(CONTEXT.getChild(YangInstanceIdentifier.of(BAR).node(BAZ)));
}
}