diff options
author | Liam Fallon <liam.fallon@est.tech> | 2020-12-02 12:54:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-12-02 12:54:51 +0000 |
commit | 7eeb2e07be6b2d0c47d415c4a1398a2c4e699156 (patch) | |
tree | e788b335382f9b406e9c5c7e3faf3ee0bb865f35 /models-base/src/main/java/org | |
parent | f46e4ec3af461b4036b189fd8d6a18af37acc29d (diff) | |
parent | 950cbb8872fb2227f4a0382a756a7e1dff53b09c (diff) |
Merge "Add extra authorative TOSCA concepts"
Diffstat (limited to 'models-base/src/main/java/org')
4 files changed, 44 insertions, 8 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java new file mode 100644 index 000000000..36bff5fbc --- /dev/null +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.base; + +import java.util.Comparator; + +/** + * Compare two PfNameVersion objects. + */ +public class PfConceptComparator implements Comparator<PfConcept> { + + @Override + public int compare(PfConcept left, PfConcept right) { + return left.getKey().compareTo(right.getKey()); + } +} diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java index 8cebcdb40..df6141b9b 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -58,7 +58,7 @@ public class PfConceptFilter implements PfObjectFilter<PfConcept> { // @formatter:off if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList); + return this.latestVersionFilter(returnList, new PfConceptComparator()); } else { return returnList; } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java b/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java index 7bdced77b..f9fde53e5 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public interface PfNameVersion { public void setVersion(final String version); /** - * COmpare two name version implementation objects. + * Compare two name version implementation objects. * * @param left the left name/version implementation * @param right the right name/version implementation diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java index f4e457192..f7e29f1b4 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,6 +23,7 @@ package org.onap.policy.models.base; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.function.Function; import java.util.function.Predicate; @@ -34,7 +35,7 @@ import java.util.regex.Pattern; * @author Liam Fallon (liam.fallon@est.tech) */ @FunctionalInterface -public interface PfObjectFilter<T extends Comparable<T>> { +public interface PfObjectFilter<T> { /** * Filter an incoming list, removing items that do not match the filter. * @@ -118,15 +119,16 @@ public interface PfObjectFilter<T extends Comparable<T>> { * Sort an incoming list and remove all but the latest version of each concept. * * @param originalList the incoming list + * @param versionComparator the comparator to use to order versions of the incoming object * @return the filtered list */ - public default List<T> latestVersionFilter(final List<T> originalList) { + public default List<T> latestVersionFilter(final List<T> originalList, final Comparator<T> versionComparator) { if (originalList.size() <= 1) { return originalList; } List<T> filteredList = new ArrayList<>(originalList); - Collections.sort(filteredList); + Collections.sort(filteredList, versionComparator); int icur = 0; for (int j = 1; j < filteredList.size(); j++) { |