Simplify ListenableFuture translation
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / DOMStoreReadTransactionAdapter.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.core.compat;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.Optional;
13 import com.google.common.collect.ForwardingObject;
14 import com.google.common.util.concurrent.CheckedFuture;
15 import com.google.common.util.concurrent.MoreExecutors;
16 import org.opendaylight.controller.md.sal.common.api.MappingCheckedFuture;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21
22 public class DOMStoreReadTransactionAdapter<T extends org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction>
23         extends ForwardingObject implements DOMStoreReadTransaction {
24     private final T delegate;
25
26     public DOMStoreReadTransactionAdapter(final T delegate) {
27         this.delegate = requireNonNull(delegate);
28     }
29
30     @Override
31     protected T delegate() {
32         return delegate;
33     }
34
35     @Override
36     public Object getIdentifier() {
37         return delegate.getIdentifier();
38     }
39
40     @Override
41     public void close() {
42         delegate.close();
43     }
44
45     @Override
46     public CheckedFuture<com.google.common.base.Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
47             final YangInstanceIdentifier path) {
48         return MappingCheckedFuture.create(delegate.read(path).transform(
49             Optional::fromJavaUtil, MoreExecutors.directExecutor()), ReadFailedExceptionAdapter.INSTANCE);
50     }
51
52     @Override
53     public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
54         return MappingCheckedFuture.create(delegate.exists(path), ReadFailedExceptionAdapter.INSTANCE);
55     }
56 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.