Merge "Remove remoterpc dead code."
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / DummyFuture.java
1 /*
2  * Copyright (c) 2014 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.restconf.impl.test;
9
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.Future;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
15
16 public class DummyFuture<T> implements Future<RpcResult<T>> {
17
18     private final boolean cancel;
19     private final boolean isCancelled;
20     private final boolean isDone;
21     private final RpcResult<T> result;
22
23     public DummyFuture() {
24         cancel = false;
25         isCancelled = false;
26         isDone = false;
27         result = null;
28     }
29
30     private DummyFuture(final Builder<T> builder) {
31         cancel = builder.cancel;
32         isCancelled = builder.isCancelled;
33         isDone = builder.isDone;
34         result = builder.result;
35     }
36
37
38     @Override
39     public boolean cancel(final boolean mayInterruptIfRunning) {
40         return cancel;
41     }
42
43     @Override
44     public boolean isCancelled() {
45         return isCancelled;
46     }
47
48     @Override
49     public boolean isDone() {
50         return isDone;
51     }
52
53     @Override
54     public RpcResult<T> get() throws InterruptedException, ExecutionException {
55         return result;
56     }
57
58     @Override
59     public RpcResult<T> get(final long timeout, final TimeUnit unit) throws InterruptedException,
60     ExecutionException, TimeoutException {
61         return result;
62     }
63
64     public static class Builder<T> {
65
66         private boolean cancel;
67         private boolean isCancelled;
68         private boolean isDone;
69         private RpcResult<T> result;
70
71         public Builder<T> cancel(final boolean cancel) {
72             this.cancel = cancel;
73             return this;
74         }
75
76         public Builder<T> isCancelled(final boolean isCancelled) {
77             this.isCancelled = isCancelled;
78             return this;
79         }
80
81         public Builder<T> isDone(final boolean isDone) {
82             this.isDone = isDone;
83             return this;
84         }
85
86         public Builder<T> rpcResult(final RpcResult<T> result) {
87             this.result = result;
88             return this;
89         }
90
91         public Future<RpcResult<T>> build() {
92             return new DummyFuture<T>(this);
93         }
94     }
95 }