2 * Copyright (c) 2018 Pantheon Technologies, 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.mdsal.dom.api;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.collect.ImmutableSet;
15 import java.util.Objects;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.yangtools.concepts.Immutable;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
24 * An action which is subject to availability.
26 public final class DOMActionInstance implements Immutable {
27 private final Set<DOMDataTreeIdentifier> dataTrees;
28 private final Absolute type;
30 private DOMActionInstance(final Absolute type, final ImmutableSet<DOMDataTreeIdentifier> dataTrees) {
31 this.type = requireNonNull(type);
32 this.dataTrees = requireNonNull(dataTrees);
33 checkArgument(!dataTrees.isEmpty());
36 public static DOMActionInstance of(final Absolute type, final Set<DOMDataTreeIdentifier> dataTrees) {
37 return new DOMActionInstance(type, ImmutableSet.copyOf(dataTrees));
40 public static DOMActionInstance of(final Absolute type, final DOMDataTreeIdentifier... dataTrees) {
41 return new DOMActionInstance(type, ImmutableSet.copyOf(dataTrees));
44 public static DOMActionInstance of(final Absolute type, final LogicalDatastoreType datastore,
45 final YangInstanceIdentifier path) {
46 return new DOMActionInstance(type, ImmutableSet.of(new DOMDataTreeIdentifier(datastore, path)));
50 * Return the set of data trees on which this action is available. These identifiers are required to point
51 * to concrete items, i.e. they may not be wildcards. Identifiers which return an empty
52 * {@link DOMDataTreeIdentifier#getRootIdentifier()} are considered to match all items in that particular datastore
53 * and are expected to be treated as lower-priority alternatives to exact matches.
55 * @return Set of trees on which this action is available.
57 public Set<DOMDataTreeIdentifier> getDataTrees() {
62 * Return the action type, i.e. the absolute schema node identifier of the action.
64 * @return action type.
66 public Absolute getType() {
71 public int hashCode() {
72 return Objects.hash(getType(), dataTrees);
76 public boolean equals(final @Nullable Object obj) {
77 return this == obj || obj instanceof DOMActionInstance other && getType().equals(other.type)
78 && dataTrees.equals(other.dataTrees);
82 public String toString() {
83 return MoreObjects.toStringHelper(this).add("type", type).add("dataTrees", dataTrees).toString();