2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
10 import com.google.common.annotations.Beta;
11 import java.util.Objects;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 // FIXME: remove this class once we ditch SchemaPath.getPath()
19 public abstract class SchemaPathSupport implements Immutable {
20 private static final class Enabled extends SchemaPathSupport {
22 SchemaPath effectivePath(final SchemaPath path) {
27 SchemaPath optionalPath(final SchemaPath path) {
32 boolean equalPaths(final SchemaPath first, final SchemaPath second) {
33 return Objects.equals(first, second);
37 private static final SchemaPathSupport DEFAULT = new Enabled();
39 private SchemaPathSupport() {
43 public static @NonNull Immutable toEffectivePath(final @NonNull SchemaPath path) {
44 return DEFAULT.effectivePath(path);
47 public static @Nullable SchemaPath toOptionalPath(final @Nullable SchemaPath path) {
48 return DEFAULT.optionalPath(path);
51 public static boolean effectivelyEqual(@Nullable final SchemaPath first, @Nullable final SchemaPath second) {
52 return DEFAULT.equalPaths(first, second);
55 abstract boolean equalPaths(@Nullable SchemaPath first, @Nullable SchemaPath second);
57 abstract @NonNull Immutable effectivePath(@NonNull SchemaPath path);
59 abstract @Nullable SchemaPath optionalPath(@Nullable SchemaPath path);