Remove NamespaceStmtCtx.get(All)FromNamespace()
[yangtools.git] / parser / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / ParserNamespace.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import java.io.Serial;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.opendaylight.yangtools.concepts.Identifier;
16
17 /**
18  * {@link ParserNamespace} serves as common superclass for namespaces used during parser operation. Each such namespace,
19  * is a type-captured subclass. This type capture of namespace allows for handy type-safe reading methods such as
20  * {@link NamespaceStmtCtx#namespaceItem(ParserNamespace, Object)} and still allows introduction of new namespaces
21  * without need to change APIs.
22  *
23  * @param <K> Identifier type
24  * @param <V> Value type
25  */
26 @NonNullByDefault
27 public final class ParserNamespace<K, V> implements Identifier {
28     @Serial
29     private static final long serialVersionUID = 1L;
30
31     private final String name;
32
33     // FIXME: hide this constructor once we collapse the type hierarchy
34     public ParserNamespace(final String name) {
35         this.name = requireNonNull(name);
36     }
37
38     @Override
39     public String toString() {
40         return MoreObjects.toStringHelper(this).add("name", name).toString();
41     }
42 }