9ffe8ab0644036ed210e0151514312374c2d08a1
[controller.git] / opendaylight / md-sal / sal-common-util / src / main / java / org / opendaylight / controller / sal / common / util / Rpcs.java
1 /*
2  * Copyright (c) 2013 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.sal.common.util;
9
10 import java.io.Serializable;
11 import java.util.Collection;
12
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.common.RpcError;
15 import org.opendaylight.yangtools.yang.common.RpcResult;
16
17 import com.google.common.collect.ImmutableList;
18
19 /**
20  * @deprecated Use {@link org.opendaylight.yangtools.yang.common.RpcResultBuilder}
21  */
22 @Deprecated
23 public class Rpcs {
24
25     public static <T> RpcResult<T> getRpcResult(boolean successful) {
26         return new RpcResultTO<>(successful, null, ImmutableList.of());
27     }
28
29     public static <T> RpcResult<T> getRpcResult(boolean successful, T result,
30             Collection<RpcError> errors) {
31         return new RpcResultTO<>(successful, result, errors);
32     }
33
34     public static <T> RpcResult<T> getRpcResult(boolean successful, Collection<RpcError> errors) {
35         return new RpcResultTO<>(successful, null, errors);
36     }
37
38     private static class RpcResultTO<T> implements RpcResult<T>, Serializable, Immutable {
39         private static final long serialVersionUID = 1L;
40         private final Collection<RpcError> errors;
41         private final T result;
42         private final boolean successful;
43
44         public RpcResultTO(boolean successful, T result,
45                 Collection<RpcError> errors) {
46             this.successful = successful;
47             this.result = result;
48             this.errors = ImmutableList.copyOf(errors);
49         }
50
51         @Override
52         public boolean isSuccessful() {
53             return successful;
54         }
55
56         @Override
57         public T getResult() {
58             return result;
59         }
60
61         @Override
62         public Collection<RpcError> getErrors() {
63             return errors;
64         }
65
66     }
67 }