Switch to JDT annotations for Nullable and NonNull
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / utils / ElanEtreeUtils.java
1 /*
2  * Copyright © 2017 Red Hat, Inc. and others.
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.netvirt.elan.utils;
9
10 import com.google.common.base.Optional;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeLeafTagName;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19
20 @Singleton
21 public class ElanEtreeUtils {
22     private final DataBroker broker;
23
24     @Inject
25     public ElanEtreeUtils(DataBroker broker) {
26         this.broker = broker;
27     }
28
29     @Nullable
30     public EtreeLeafTagName getEtreeLeafTagByElanTag(long elanTag) {
31         InstanceIdentifier<ElanTagName> elanId = ElanUtils.getElanInfoEntriesOperationalDataPath(elanTag);
32         Optional<ElanTagName> existingElanInfo = ElanUtils.read(broker,
33                 LogicalDatastoreType.OPERATIONAL, elanId);
34         if (existingElanInfo.isPresent()) {
35             ElanTagName elanTagName = existingElanInfo.get();
36             return elanTagName.augmentation(EtreeLeafTagName.class);
37         }
38         return null;
39     }
40 }