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 org.opendaylight.mdsal.dom.api.DOMRpcResult;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.Preconditions;
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 javax.annotation.Nonnull;
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;
30 private final Collection<RpcError> errors;
31 private final NormalizedNode<?, ?> result;
33 private static Collection<RpcError> asCollection(final RpcError... errors) {
34 if (errors.length == 0) {
35 return Collections.emptyList();
37 return Arrays.asList(errors);
41 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result, final RpcError... errors) {
42 this(result, asCollection(errors));
45 public DefaultDOMRpcResult(final RpcError... errors) {
46 this(null, asCollection(errors));
49 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result) {
50 this(result, Collections.<RpcError>emptyList());
53 public DefaultDOMRpcResult(final NormalizedNode<?, ?> result, final @Nonnull Collection<RpcError> errors) {
55 this.errors = Preconditions.checkNotNull(errors);
58 public DefaultDOMRpcResult(final @Nonnull Collection<RpcError> errors) {
63 public @Nonnull Collection<RpcError> getErrors() {
68 public NormalizedNode<?, ?> getResult() {
73 public int hashCode() {
74 int ret = errors.hashCode();
76 ret = 31 * ret + result.hashCode();
82 public boolean equals(final Object obj) {
86 if (!(obj instanceof DefaultDOMRpcResult)) {
90 final DefaultDOMRpcResult other = (DefaultDOMRpcResult) obj;
91 if (!errors.equals(other.errors)) {
94 return Objects.equals(result, other.result);