Suppress modernization
[controller.git] / opendaylight / md-sal / sal-dom-spi / src / main / java / org / opendaylight / controller / md / sal / dom / spi / DefaultDOMRpcResult.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.md.sal.dom.spi;
9
10 import static java.util.Objects.requireNonNull;
11
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;
24
25 /**
26  * Utility class implementing {@link DefaultDOMRpcResult}.
27  * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult} instead.
28  */
29 @Deprecated
30 @Beta
31 public final class DefaultDOMRpcResult implements DOMRpcResult, Immutable, Serializable {
32     private static final long serialVersionUID = 1L;
33
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;
39
40     // Unfortunately the NormalizedNode interface isn't Serializable but we assume the implementations are.
41     @SuppressFBWarnings("SE_BAD_FIELD")
42     private final NormalizedNode<?, ?> result;
43
44     private static Collection<RpcError> asCollection(final RpcError... errors) {
45         if (errors.length == 0) {
46             return Collections.emptyList();
47         } else {
48             return Arrays.asList(errors);
49         }
50     }
51
52     public DefaultDOMRpcResult(final NormalizedNode<?, ?> result, final RpcError... errors) {
53         this(result, asCollection(errors));
54     }
55
56     public DefaultDOMRpcResult(final RpcError... errors) {
57         this(null, asCollection(errors));
58     }
59
60     public DefaultDOMRpcResult(final NormalizedNode<?, ?> result) {
61         this(result, Collections.emptyList());
62     }
63
64     public DefaultDOMRpcResult(final NormalizedNode<?, ?> result,
65             final @NonNull Collection<? extends RpcError> errors) {
66         this.result = result;
67         this.errors = requireNonNull(errors);
68     }
69
70     public DefaultDOMRpcResult(final @NonNull Collection<RpcError> errors) {
71         this(null, errors);
72     }
73
74     @Override
75     public Collection<? extends RpcError> getErrors() {
76         return errors;
77     }
78
79     @Override
80     public NormalizedNode<?, ?> getResult() {
81         return result;
82     }
83
84     @Override
85     public int hashCode() {
86         int ret = errors.hashCode();
87         if (result != null) {
88             ret = 31 * ret + result.hashCode();
89         }
90         return ret;
91     }
92
93     @Override
94     public boolean equals(final Object obj) {
95         if (this == obj) {
96             return true;
97         }
98         if (!(obj instanceof DefaultDOMRpcResult)) {
99             return false;
100         }
101
102         final DefaultDOMRpcResult other = (DefaultDOMRpcResult) obj;
103         if (!errors.equals(other.errors)) {
104             return false;
105         }
106         return Objects.equals(result, other.result);
107     }
108 }