Merge "Fix warnings reported in toaster"
[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 public class Rpcs {
20
21     public static <T> RpcResult<T> getRpcResult(boolean successful) {
22         RpcResult<T> ret = new RpcResultTO<T>(successful, null, ImmutableList.<RpcError>of());
23         return ret;
24     }
25
26     public static <T> RpcResult<T> getRpcResult(boolean successful, T result,
27             Collection<RpcError> errors) {
28         RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);
29         return ret;
30     }
31
32     public static <T> RpcResult<T> getRpcResult(boolean successful, Collection<RpcError> errors) {
33         return new RpcResultTO<T>(successful, null, errors);
34     }
35
36     private static class RpcResultTO<T> implements RpcResult<T>, Serializable, Immutable {
37         private static final long serialVersionUID = 1L;
38         private final Collection<RpcError> errors;
39         private final T result;
40         private final boolean successful;
41
42         public RpcResultTO(boolean successful, T result,
43                 Collection<RpcError> errors) {
44             this.successful = successful;
45             this.result = result;
46             this.errors = ImmutableList.copyOf(errors);
47         }
48
49         @Override
50         public boolean isSuccessful() {
51             return successful;
52         }
53
54         @Override
55         public T getResult() {
56             return result;
57         }
58
59         @Override
60         public Collection<RpcError> getErrors() {
61             return errors;
62         }
63
64     }
65 }