* Represents unique path to every schema node inside the schema node identifier namespace. This concept is defined
* in <a href="https://tools.ietf.org/html/rfc7950#section-6.5">RFC7950</a>.
*/
-public abstract class SchemaNodeIdentifier implements Immutable {
+public abstract sealed class SchemaNodeIdentifier implements Immutable {
/**
* An absolute schema node identifier.
*/
- public abstract static class Absolute extends SchemaNodeIdentifier {
- private static final Interner<Absolute> INTERNER = Interners.newWeakInterner();
-
- Absolute() {
- // Hidden on purpose
- }
+ public abstract static sealed class Absolute extends SchemaNodeIdentifier {
+ private static final Interner<@NonNull Absolute> INTERNER = Interners.newWeakInterner();
/**
* Create an absolute schema node identifier composed of a single node identifier.
* @throws IllegalArgumentException if {@code nodeIdentifiers} is empty
*/
public static @NonNull Absolute of(final Collection<QName> nodeIdentifiers) {
- final ImmutableList<QName> qnames = checkQNames(nodeIdentifiers);
+ final var qnames = checkQNames(nodeIdentifiers);
return qnames.size() == 1 ? of(qnames.get(0)) : new AbsoluteMultiple(qnames);
}
/**
* A descendant schema node identifier.
*/
- public abstract static class Descendant extends SchemaNodeIdentifier {
- Descendant() {
- // Hidden on purpose
- }
-
+ public abstract static sealed class Descendant extends SchemaNodeIdentifier {
/**
* Create a descendant schema node identifier composed of a single node identifier.
*
* @throws IllegalArgumentException if {@code nodeIdentifiers} is empty
*/
public static @NonNull Descendant of(final Collection<QName> nodeIdentifiers) {
- final ImmutableList<QName> qnames = checkQNames(nodeIdentifiers);
+ final var qnames = checkQNames(nodeIdentifiers);
return qnames.size() == 1 ? of(qnames.get(0)) : new DescandantMultiple(qnames);
}
// Cached hashCode
private volatile int hash;
- SchemaNodeIdentifier() {
- // Hidden on purpose
- }
-
/**
* Return the non-empty sequence of node identifiers which constitute this schema node identifier.
*
* @return The last node identifier
*/
public @NonNull QName lastNodeIdentifier() {
- final List<QName> local = getNodeIdentifiers();
+ final var local = getNodeIdentifiers();
return local.get(local.size() - 1);
}
abstract @NonNull String className();
private List<?> toStringQNames() {
- final List<QName> ids = getNodeIdentifiers();
+ final var ids = getNodeIdentifiers();
return ids.size() < 2 ? ids : simplifyQNames(ids);
}
private static ImmutableList<QName> checkQNames(final Collection<QName> qnames) {
- final ImmutableList<QName> ret = ImmutableList.copyOf(qnames);
+ final var ret = ImmutableList.copyOf(qnames);
checkArgument(!ret.isEmpty(), "SchemaNodeIdentifier has to have at least one node identifier");
return ret;
}
private static List<?> simplifyQNames(final List<QName> qnames) {
- final List<Object> ret = new ArrayList<>(qnames.size());
+ final var ret = new ArrayList<>(qnames.size());
QNameModule prev = null;
- for (QName qname : qnames) {
- final QNameModule module = qname.getModule();
+ for (var qname : qnames) {
+ final var module = qname.getModule();
ret.add(module.equals(prev) ? qname.getLocalName() : qname);
prev = module;
}