Improve iteration over subnets map by using entrySet instead of keyset.
[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.ArrayList;
12 import java.util.Collection;
13 import java.util.Collections;
14 import org.opendaylight.yangtools.yang.common.RpcError;
15 import org.opendaylight.yangtools.yang.common.RpcResult;
16
17 public class Rpcs {
18     public static <T> RpcResult<T> getRpcResult(boolean successful, T result,
19             Collection<RpcError> errors) {
20         RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);
21         return ret;
22     }
23
24     private static class RpcResultTO<T> implements RpcResult<T>, Serializable {
25
26         private final Collection<RpcError> errors;
27         private final T result;
28         private final boolean successful;
29
30         public RpcResultTO(boolean successful, T result,
31                 Collection<RpcError> errors) {
32             this.successful = successful;
33             this.result = result;
34             this.errors = Collections.unmodifiableList(new ArrayList<RpcError>(
35                     errors));
36         }
37
38         @Override
39         public boolean isSuccessful() {
40             return successful;
41         }
42
43         @Override
44         public T getResult() {
45             return result;
46         }
47
48         @Override
49         public Collection<RpcError> getErrors() {
50             return errors;
51         }
52
53     }
54 }