Fix occasional NPEs in Connection manager
[controller.git] / opendaylight / sal / yang-prototype / 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.util.ArrayList;
11 import java.util.Collection;
12 import java.util.Collections;
13 import org.opendaylight.yangtools.yang.common.RpcError;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
15
16 public class Rpcs {
17     public static <T> RpcResult<T> getRpcResult(boolean successful, T result,
18             Collection<RpcError> errors) {
19         RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);
20         return ret;
21     }
22
23     private static class RpcResultTO<T> implements RpcResult<T> {
24
25         private final Collection<RpcError> errors;
26         private final T result;
27         private final boolean successful;
28
29         public RpcResultTO(boolean successful, T result,
30                 Collection<RpcError> errors) {
31             this.successful = successful;
32             this.result = result;
33             this.errors = Collections.unmodifiableList(new ArrayList<RpcError>(
34                     errors));
35         }
36
37         @Override
38         public boolean isSuccessful() {
39             return successful;
40         }
41
42         @Override
43         public T getResult() {
44             return result;
45         }
46
47         @Override
48         public Collection<RpcError> getErrors() {
49             return errors;
50         }
51
52     }
53 }