--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, 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.api.schema;
+
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+
+/**
+ * A {@link DistinctContainer} containing {@link DataContainerChild} children.
+ *
+ * <p>
+ * <b>NOTE:</b>
+ * All implementations of this interface are assumed to be {@link OrderingAware.System}, i.e. order-independent.
+ */
+public sealed interface DataContainer
+ extends DistinctContainer<NodeIdentifier, DataContainerChild>, OrderingAware.System
+ permits DataContainerNode, NormalizedYangData {
+ @Override
+ int hashCode();
+
+ @Override
+ boolean equals(Object obj);
+}
* Abstract node which does not have value but contains valid {@link DataContainerChild} nodes. Schema of this node is
* described by instance of {@link org.opendaylight.yangtools.yang.model.api.DataNodeContainer}.
*
- * <p>
- * <b>NOTE:</b>
- * All implementations of this interface are assumed to be {@link OrderingAware.System}, i.e. order-independent.
- *
* <h2>Implementation notes</h2>
* This interface should not be implemented directly, but rather implementing one of it's subclasses
* <ul>
* <li>{@link UnkeyedListEntryNode}</li>
* </ul>
*/
-public interface DataContainerNode
- extends DistinctNodeContainer<NodeIdentifier, DataContainerChild>, OrderingAware.System {
- @Override
- int hashCode();
-
- @Override
- boolean equals(Object obj);
+public non-sealed interface DataContainerNode
+ extends DataContainer, DistinctNodeContainer<NodeIdentifier, DataContainerChild> {
+ // Just a composition of DataContainer and DistingNodeContainer
}
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, 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.api.schema;
+
+import static com.google.common.base.Verify.verifyNotNull;
+
+import com.google.common.base.VerifyException;
+import java.util.Collection;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+
+/**
+ * A {@link NormalizedContainer} which contains distinctly-addressable children.
+ *
+ * @param <K> Child path argument type
+ * @param <V> Child Node type
+ */
+public sealed interface DistinctContainer<K extends PathArgument, V extends NormalizedNode>
+ extends NormalizedContainer<V> permits DistinctNodeContainer, DataContainer {
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * All nodes returned in this iterable, MUST also be accessible via {@link #childByArg(PathArgument)} using their
+ * associated identifier.
+ *
+ * @return Iteration of all child nodes
+ */
+ @Override
+ Collection<@NonNull V> body();
+
+ /**
+ * Returns a child node identified by provided key.
+ *
+ * @param key Path argument identifying child node
+ * @return Matching child node, or null if no matching child exists
+ * @throws NullPointerException if {@code key} is {@code null}
+ */
+ @Nullable V childByArg(K key);
+
+ /**
+ * Attempts to find a child node identified by provided key.
+ *
+ * @param key Path argument identifying child node
+ * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist
+ * @throws NullPointerException if {@code key} is {@code null}
+ */
+ default Optional<V> findChildByArg(final K key) {
+ return Optional.ofNullable(childByArg(key));
+ }
+
+ /**
+ * Returns a child node identified by provided key, asserting its presence.
+ *
+ * @param key Path argument identifying child node
+ * @return Matching child node
+ * @throws NullPointerException if {@code key} is {@code null}
+ * @throws VerifyException if the child does not exist
+ */
+ default @NonNull V getChildByArg(final K key) {
+ return verifyNotNull(childByArg(key), "No child matching %s", key);
+ }
+}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import static com.google.common.base.Verify.verifyNotNull;
-
-import com.google.common.base.VerifyException;
-import java.util.Collection;
-import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
* @param <V> Child Node type
*/
public non-sealed interface DistinctNodeContainer<K extends PathArgument, V extends NormalizedNode>
- extends NormalizedNodeContainer<V> {
- /**
- * {@inheritDoc}
- *
- * <p>
- * All nodes returned in this iterable, MUST also be accessible via {@link #childByArg(PathArgument)} using their
- * associated identifier.
- *
- * @return Iteration of all child nodes
- */
- @Override
- Collection<@NonNull V> body();
-
- /**
- * Returns a child node identified by provided key.
- *
- * @param key Path argument identifying child node
- * @return Matching child node, or null if no matching child exists
- * @throws NullPointerException if {@code key} is {@code null}
- */
- @Nullable V childByArg(K key);
-
- /**
- * Attempts to find a child node identified by provided key.
- *
- * @param key Path argument identifying child node
- * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist
- * @throws NullPointerException if {@code key} is {@code null}
- */
- default Optional<V> findChildByArg(final K key) {
- return Optional.ofNullable(childByArg(key));
- }
-
- /**
- * Returns a child node identified by provided key, asserting its presence.
- *
- * @param key Path argument identifying child node
- * @return Matching child node
- * @throws NullPointerException if {@code key} is {@code null}
- * @throws VerifyException if the child does not exist
- */
- default @NonNull V getChildByArg(final K key) {
- return verifyNotNull(childByArg(key), "No child matching %s", key);
- }
+ extends DistinctContainer<K, V>, NormalizedNodeContainer<V> {
+ // Composition of DistinctContainer and NormalizedNodeContainer
}
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, 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.api.schema;
+
+import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
+
+/**
+ * A piece of {@link NormalizedData} which holds some child {@link NormalizedNode}s. This interface should not be used
+ * directly, but rather through its specializations.
+ *
+ * @param <V> Child Node type
+ */
+public sealed interface NormalizedContainer<V extends NormalizedNode> extends NormalizedData, OrderingAware
+ permits NormalizedNodeContainer, DistinctContainer, OrderedContainer {
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * Returns iteration of all child nodes. Order of returned child nodes may be defined by subinterfaces.
+ */
+ @Override
+ Collection<@NonNull V> body();
+
+ /**
+ * Return the logical size of this container body. The default implementation defers to {@code body().size()}.
+ *
+ * @return Size of this container's body.
+ */
+ default int size() {
+ return body().size();
+ }
+
+ /**
+ * Determine whether this container body is empty. The default implementation defers to {@code body().isEmpty()}.
+ *
+ * @return True if this container has an empty body.
+ */
+ default boolean isEmpty() {
+ return body().isEmpty();
+ }
+}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
-import org.eclipse.jdt.annotation.NonNull;
-
/**
* Node which is not leaf, but has child {@link NormalizedNode}s as its value. It provides iteration over its child
* nodes via {@link #body()}. More convenient access to child nodes are provided by {@link DistinctNodeContainer} and
*
* @param <V> Child Node type
*/
-public sealed interface NormalizedNodeContainer<V extends NormalizedNode> extends NormalizedNode, OrderingAware
+public sealed interface NormalizedNodeContainer<V extends NormalizedNode> extends NormalizedContainer<V>, NormalizedNode
permits DistinctNodeContainer, OrderedNodeContainer {
- /**
- * {@inheritDoc}
- *
- * <p>
- * Returns iteration of all child nodes. Order of returned child nodes may be defined by subinterfaces.
- */
- @Override
- Collection<@NonNull V> body();
-
- /**
- * Return the logical size of this container body. The default implementation defers to {@code body().size()}.
- *
- * @return Size of this container's body.
- */
- default int size() {
- return body().size();
- }
-
- /**
- * Determine whether this container body is empty. The default implementation defers to {@code body().isEmpty()}.
- *
- * @return True if this container has an empty body.
- */
- default boolean isEmpty() {
- return body().isEmpty();
- }
+ // Just a composite of NormalizedContainer and NormalizedNode
}
* The contents of a {@code yang-data} template instance, as defined in
* <a href="https://www.rfc-editor.org/rfc/rfc8040#page-80">RFC8040</a>'s {@code ietf-restconf} module.
*/
-public interface NormalizedYangData extends NormalizedData {
+public non-sealed interface NormalizedYangData extends DataContainer {
@Override
default Class<NormalizedYangData> contract() {
return NormalizedYangData.class;
@Override
YangDataName name();
-
- @Override
- DataContainerChild body();
}
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, 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.api.schema;
+
+import org.eclipse.jdt.annotation.NonNull;
+
+/**
+ * A {@link NormalizedContainer} which preserves user supplied ordering and allows addressing of child elements by
+ * position. All implementations of this interface must also implement {@link OrderingAware.User}.
+ *
+ * @param <V> child type
+ */
+public sealed interface OrderedContainer<V extends NormalizedNode> extends NormalizedContainer<V>, OrderingAware.User
+ permits OrderedNodeContainer {
+ /**
+ * Returns child node by position.
+ *
+ * @param position Position of child node
+ * @return Child Node
+ * @throws IndexOutOfBoundsException Out of bound Exception
+ */
+ @NonNull V childAt(int position);
+
+ @Override
+ int hashCode();
+
+ @Override
+ boolean equals(Object obj);
+}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import org.eclipse.jdt.annotation.NonNull;
-
/**
* A {@link NormalizedNodeContainer} which preserves user supplied ordering and allows addressing of child elements by
- * position. All implementations of this interface must also implement {@link OrderingAware.User}. This interface should
- * not be implemented directly, but rather implementing one of it's subclasses
+ * position. This interface should not be implemented directly, but rather implementing one of it's subclasses
* <ul>
* <li>{@link UnkeyedListNode}</li>
* <li>{@link UserLeafSetNode}</li>
// FIXME: 9.0.0: we really want to do a List<@NonNull V> body(), but need to reconcile that with key-based lookup in
// implementations -- and those are using only a Map internally.
public sealed interface OrderedNodeContainer<V extends NormalizedNode>
- extends NormalizedNodeContainer<V>, OrderingAware.User
+ extends OrderedContainer<V>, NormalizedNodeContainer<V>
permits UnkeyedListNode, UserLeafSetNode, UserMapNode {
- /**
- * Returns child node by position.
- *
- * @param position Position of child node
- * @return Child Node
- * @throws IndexOutOfBoundsException Out of bound Exception
- */
- @NonNull V childAt(int position);
-
- @Override
- int hashCode();
-
- @Override
- boolean equals(Object obj);
+ // Composition of OrderedContainer and NormalizedNodeContainer
}
*/
@Beta
@NonNullByDefault
-public sealed interface OrderingAware permits NormalizedNodeContainer, OrderingAware.System, OrderingAware.User {
+public sealed interface OrderingAware permits NormalizedContainer, OrderingAware.System, OrderingAware.User {
/**
* Marker interface for NormalizedNodeContainer implementations which correspond to {@code ordered-by system}. These
* follow the {@link Unordered} contract.