diff options
author | 2018-01-08 12:40:46 +0100 | |
---|---|---|
committer | 2018-01-29 12:58:05 +0100 | |
commit | 8d977df8ba8a63e8c76f58825854fd53f8e638ba (patch) | |
tree | 7a1e606d524ff5ea67715f4b1ef00b94545e9e61 /adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud | |
parent | 1672a4db05c0e313ce258efe26a75f995c162bb5 (diff) |
refactoring - add Optional
change possible null return value to Optional
Change-Id: I70bf78a51b901a74932b00d1d8735bef5eeacef7
Issue-ID: SO-360
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud')
-rw-r--r-- | adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java index ef37f9f719..5d16a95e5f 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java @@ -46,7 +46,6 @@ import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; * * This class also contains methods to query cloud sites and/or identity * services by ID. - * */ @JsonRootName("cloud_config") @@ -89,21 +88,20 @@ public class CloudConfig { * individual entries to try and find one with a CLLI that matches the ID * and an AIC version of 2.5. * - * @param id - * the ID to match - * @return a CloudSite, or null of no match found + * @param id the ID to match + * @return an Optional of CloudSite object. */ - public synchronized CloudSite getCloudSite(String id) { - if (id != null) { - if (cloudSites.containsKey(id)) { - return cloudSites.get(id); - } - // check for id == CLLI now as well - return getCloudSiteWithClli(id); + public synchronized Optional<CloudSite> getCloudSite(String id) { + if (id == null) { + return Optional.empty(); } - return null; + if (cloudSites.containsKey(id)) { + return Optional.ofNullable(cloudSites.get(id)); + } + return Optional.ofNullable(getCloudSiteWithClli(id)); } + private CloudSite getCloudSiteWithClli(String clli) { Optional <CloudSite> cloudSiteOptional = cloudSites.values().stream().filter(cs -> cs.getClli() != null && clli.equals(cs.getClli()) && (CLOUD_SITE_VERSION.equals(cs.getAic_version()))) @@ -111,7 +109,6 @@ public class CloudConfig { return cloudSiteOptional.orElse(getDefaultCloudSite(clli)); } - // TODO in future the result will be optional private CloudSite getDefaultCloudSite(String clli) { Optional<CloudSite> cloudSiteOpt = cloudSites.values().stream() .filter(cs -> cs.getId().equalsIgnoreCase(DEFAULT_CLOUD_SITE_ID)).findAny(); |