Simplify DOMOperationService API
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMActionInstance.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, 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.mdsal.dom.api;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.base.MoreObjects;
14 import com.google.common.collect.ImmutableSet;
15 import java.util.Objects;
16 import java.util.Set;
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.SchemaPath;
22
23 /**
24  * An action which is subject to availability.
25  */
26 public final class DOMActionInstance implements Immutable {
27     private final Set<DOMDataTreeIdentifier> dataTrees;
28     private final SchemaPath type;
29
30     DOMActionInstance(final SchemaPath type, final Set<DOMDataTreeIdentifier> dataTrees) {
31         this.type = requireNonNull(type);
32         this.dataTrees = ImmutableSet.copyOf(dataTrees);
33         checkArgument(!dataTrees.isEmpty());
34     }
35
36     public static DOMActionInstance of(final SchemaPath type, final Set<DOMDataTreeIdentifier> dataTrees) {
37         return new DOMActionInstance(type, dataTrees);
38     }
39
40     public static DOMActionInstance of(final SchemaPath type, final DOMDataTreeIdentifier... dataTrees) {
41         return of(type, ImmutableSet.copyOf(dataTrees));
42     }
43
44     public static DOMActionInstance of(final SchemaPath type, final LogicalDatastoreType datastore,
45             final YangInstanceIdentifier path) {
46         return of(type, ImmutableSet.of(new DOMDataTreeIdentifier(datastore, path)));
47     }
48
49     /**
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.
52      *
53      * @return Set of trees on which this action is available.
54      */
55     public Set<DOMDataTreeIdentifier> getDataTrees() {
56         return dataTrees;
57     }
58
59     /**
60      * Return the operation type.
61      *
62      * @return operation type.
63      */
64     public SchemaPath getType() {
65         return type;
66     }
67
68     @Override
69     public int hashCode() {
70         return Objects.hash(getType(), dataTrees);
71     }
72
73     @Override
74     public boolean equals(final @Nullable Object obj) {
75         if (this == obj) {
76             return true;
77         }
78         if (!(obj instanceof DOMActionInstance)) {
79             return false;
80         }
81         final DOMActionInstance other = (DOMActionInstance) obj;
82         return getType().equals(other.type) && dataTrees.equals(other.dataTrees);
83     }
84
85     @Override
86     public String toString() {
87         return MoreObjects.toStringHelper(this).add("type", type).add("dataTrees", dataTrees).toString();
88     }
89 }