2 * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.md.sal.dom.spi;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14 import java.io.Serializable;
15 import java.util.Arrays;
16 import java.util.Collection;
17 import java.util.Collections;
18 import java.util.Objects;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
21 import org.opendaylight.yangtools.concepts.Immutable;
22 import org.opendaylight.yangtools.yang.common.RpcError;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 * Utility class implementing {@link DefaultDOMRpcResult}.
27 * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult} instead.
31 public final class DefaultDOMRpcResult implements DOMRpcResult, Immutable, Serializable {
32 private static final long serialVersionUID = 1L;
34 // Flagged as "Non-transient non-serializable instance field" - the Collection is Serializable but the RpcError
35 // interface isn't. In lieu of changing the interface, we assume the implementation is Serializable which is
36 // reasonable since the only implementation that is actually used is from the RpcResultBuilder.
37 @SuppressFBWarnings("SE_BAD_FIELD")
38 private final Collection<? extends RpcError> errors;
40 // Unfortunately the NormalizedNode interface isn't Serializable but we assume the implementations are.
41 @SuppressFBWarnings("SE_BAD_FIELD")
42 private final NormalizedNode<?, ?> result;
44 private static Collection<RpcError> asCollection(final RpcError... errors) {
45 if (errors.length == 0) {
46 return Collections.emptyList();
48 return Arrays.asList(errors);
52 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result, final RpcError... errors) {
53 this(result, asCollection(errors));
56 public DefaultDOMRpcResult(final RpcError... errors) {
57 this(null, asCollection(errors));
60 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result) {
61 this(result, Collections.emptyList());
64 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result,
65 final @NonNull Collection<? extends RpcError> errors) {
67 this.errors = requireNonNull(errors);
70 public DefaultDOMRpcResult(final @NonNull Collection<RpcError> errors) {
75 public Collection<? extends RpcError> getErrors() {
80 public NormalizedNode<?, ?> getResult() {
85 public int hashCode() {
86 int ret = errors.hashCode();
88 ret = 31 * ret + result.hashCode();
94 public boolean equals(final Object obj) {
98 if (!(obj instanceof DefaultDOMRpcResult)) {
102 final DefaultDOMRpcResult other = (DefaultDOMRpcResult) obj;
103 if (!errors.equals(other.errors)) {
106 return Objects.equals(result, other.result);