2 * Copyright © 2018 Red Hat, Inc. and others.
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.mdsal.binding.util;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 * Strongly-typed representation of a datastore (configuration or operational).
19 // FIXME Base this on ietf-datastores.yang (RFC 8342)
20 public abstract sealed class Datastore {
22 * Class representing the configuration datastore.
24 public static final class Configuration extends Datastore {
25 private Configuration() {
26 super(LogicalDatastoreType.CONFIGURATION);
31 * Class representing the operational datastore.
33 public static final class Operational extends Datastore {
34 private Operational() {
35 super(LogicalDatastoreType.OPERATIONAL);
39 public static final Operational OPERATIONAL = new Operational();
40 public static final Configuration CONFIGURATION = new Configuration();
42 private final LogicalDatastoreType type;
44 private Datastore(final LogicalDatastoreType type) {
45 this.type = requireNonNull(type);
49 * Returns the logical datastore type corresponding to thisclass.
51 * @return The corresponding logical datastore type.
53 public LogicalDatastoreType type() {
58 * Returns the Datastore corresponding to the given logical datastore type.
60 * @param type The logical datastore type to convert.
61 * @return The corresponding Datastore
62 * @throws NullPointerException if {@code type} is {@code null}
64 public static Datastore ofType(final LogicalDatastoreType type) {
65 return switch (type) {
66 case CONFIGURATION -> CONFIGURATION;
67 case OPERATIONAL -> OPERATIONAL;