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 com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.io.Serializable;
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Objects;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
20 import org.opendaylight.yangtools.concepts.Immutable;
21 import org.opendaylight.yangtools.yang.common.RpcError;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 * Utility class implementing {@link DefaultDOMRpcResult}.
28 public final class DefaultDOMRpcResult implements DOMRpcResult, Immutable, Serializable {
29 private static final long serialVersionUID = 1L;
31 // Flagged as "Non-transient non-serializable instance field" - the Collection is Serializable but the RpcError
32 // interface isn't. In lieu of changing the interface, we assume the implementation is Serializable which is
33 // reasonable since the only implementation that is actually used is from the RpcResultBuilder.
34 @SuppressFBWarnings("SE_BAD_FIELD")
35 private final Collection<? extends RpcError> errors;
37 // Unfortunately the NormalizedNode interface isn't Serializable but we assume the implementations are.
38 @SuppressFBWarnings("SE_BAD_FIELD")
39 private final NormalizedNode<?, ?> result;
41 private static Collection<RpcError> asCollection(final RpcError... errors) {
42 if (errors.length == 0) {
43 return Collections.emptyList();
45 return Arrays.asList(errors);
49 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result, final RpcError... errors) {
50 this(result, asCollection(errors));
53 public DefaultDOMRpcResult(final RpcError... errors) {
54 this(null, asCollection(errors));
57 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result) {
58 this(result, Collections.<RpcError>emptyList());
61 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result,
62 final @Nonnull Collection<? extends RpcError> errors) {
64 this.errors = Preconditions.checkNotNull(errors);
67 public DefaultDOMRpcResult(final @Nonnull Collection<RpcError> errors) {
72 public @Nonnull Collection<? extends RpcError> getErrors() {
77 public NormalizedNode<?, ?> getResult() {
82 public int hashCode() {
83 int ret = errors.hashCode();
85 ret = 31 * ret + result.hashCode();
91 public boolean equals(final Object obj) {
95 if (!(obj instanceof DefaultDOMRpcResult)) {
99 final DefaultDOMRpcResult other = (DefaultDOMRpcResult) obj;
100 if (!errors.equals(other.errors)) {
103 return Objects.equals(result, other.result);