Add YangDataName 94/104094/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Jan 2023 08:46:00 +0000 (09:46 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 23 Jan 2023 09:44:15 +0000 (09:44 +0000)
This adds yang.common.YangDataName, as the common identifier for
ietf-restconf:yang-data templates.

JIRA: YANGTOOLS-1477
Change-Id: Ie384e341ea84a6e1ca45b3f416d66aa1cd5ac79f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangDataName.java [new file with mode: 0644]

diff --git a/common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangDataName.java b/common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangDataName.java
new file mode 100644 (file)
index 0000000..996f1b5
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.common;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.Identifier;
+
+/**
+ * Identifier of a RESTCONF {@code yang-data} extension template instantiation. The {@link #module()} method returns
+ * the namespace and revision of use and {@link #name()} returns the name of the template.
+ */
+public record YangDataName(@NonNull QNameModule module, @NonNull String name) implements Identifier {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
+    private static final Interner<@NonNull YangDataName> INTERNER = Interners.newWeakInterner();
+
+    public YangDataName {
+        requireNonNull(module);
+        checkArgument(!name.isEmpty(), "name must not be empty");
+    }
+
+    /**
+     * Intern this instance.
+     *
+     * @return An interned instance.
+     */
+    public @NonNull YangDataName intern() {
+        return INTERNER.intern(this);
+    }
+}