2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.basicmodel.concepts;
23 import java.util.NavigableMap;
25 import java.util.TreeSet;
27 import org.onap.policy.apex.model.utilities.Assertions;
30 * Implements concept getting from navigable maps.
32 * @author Liam Fallon (liam.fallon@ericsson.com)
33 * @param <C> the type of concept on which the interface implementation is applied.
35 public class AxConceptGetterImpl<C> implements AxConceptGetter<C> {
37 // The map from which to get concepts
38 private final NavigableMap<AxArtifactKey, C> conceptMap;
41 * Constructor that sets the concept map on which the getter methods in the interface will operate..
43 * @param conceptMap the concept map on which the method will operate
45 public AxConceptGetterImpl(final NavigableMap<AxArtifactKey, C> conceptMap) {
46 this.conceptMap = conceptMap;
52 * @see org.onap.policy.apex.core.basicmodel.concepts.AxConceptGetter#get(org.onap.policy.apex.apex.core.basicmodel.
53 * concepts.AxArtifactKey)
56 public C get(final AxArtifactKey conceptKey) {
57 return conceptMap.get(conceptKey);
63 * @see org.onap.policy.apex.core.basicmodel.concepts.AxConceptGetter#get(java.lang. String)
66 public C get(final String conceptKeyName) {
67 Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null");
69 // The very fist key that could have this name
70 final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
72 // Check if we found a key for our name
73 AxArtifactKey foundKey = conceptMap.ceilingKey(lowestArtifactKey);
74 if (foundKey == null || !foundKey.getName().equals(conceptKeyName)) {
78 // Look for higher versions of the key
80 final AxArtifactKey nextkey = conceptMap.higherKey(foundKey);
81 if (nextkey == null || !nextkey.getName().equals(conceptKeyName)) {
87 return conceptMap.get(foundKey);
93 * @see org.onap.policy.apex.core.basicmodel.concepts.AxConceptGetter#get(java.lang. String, java.lang.String)
96 public C get(final String conceptKeyName, final String conceptKeyVersion) {
97 Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null");
99 if (conceptKeyVersion != null) {
100 return conceptMap.get(new AxArtifactKey(conceptKeyName, conceptKeyVersion));
102 return this.get(conceptKeyName);
109 * @see org.onap.policy.apex.core.basicmodel.concepts.AxConceptGetter#getAll(java. lang.String)
112 public Set<C> getAll(final String conceptKeyName) {
113 return getAll(conceptKeyName, null);
119 * @see org.onap.policy.apex.core.basicmodel.concepts.AxConceptGetter#getAll(java. lang.String, java.lang.String)
122 public Set<C> getAll(final String conceptKeyName, final String conceptKeyVersion) {
123 final Set<C> returnSet = new TreeSet<>();
125 if (conceptKeyName == null) {
126 returnSet.addAll(conceptMap.values());
130 // The very fist key that could have this name
131 final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
132 if (conceptKeyVersion != null) {
133 lowestArtifactKey.setVersion(conceptKeyVersion);
136 // Check if we found a key for our name
137 AxArtifactKey foundKey = conceptMap.ceilingKey(lowestArtifactKey);
138 if (foundKey == null || !foundKey.getName().equals(conceptKeyName)) {
141 returnSet.add(conceptMap.get(foundKey));
143 // Look for higher versions of the key
145 foundKey = conceptMap.higherKey(foundKey);
146 if (foundKey == null || !foundKey.getName().equals(conceptKeyName)) {
149 returnSet.add(conceptMap.get(foundKey));