*/
package org.opendaylight.openflowplugin.test;
-import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.opendaylight.mdsal.binding.api.ReadTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
* Created by Martin Bobak mbobak@cisco.com on 8/20/14.
*/
public final class TestProviderTransactionUtil {
-
private static final Logger LOG = LoggerFactory.getLogger(TestProviderTransactionUtil.class);
private TestProviderTransactionUtil() {
- throw new AssertionError("TestProviderTransactionUtil was not meant to be instantiated.");
+ // Hidden on purpose
}
- public static <T extends DataObject> T getDataObject(ReadTransaction readOnlyTransaction,
- InstanceIdentifier<T> identifier) {
- Optional<T> optionalData = null;
+ public static <T extends DataObject> T getDataObject(final ReadTransaction readOnlyTransaction,
+ final InstanceIdentifier<T> identifier) {
try {
- optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get();
- if (optionalData.isPresent()) {
- return optionalData.get();
- }
+ return readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get().orElse(null);
} catch (ExecutionException | InterruptedException e) {
LOG.error("Read transaction for identifier {} failed.", identifier, e);
+ return null;
}
- return null;
}
}