From 950cbb8872fb2227f4a0382a756a7e1dff53b09c Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 20 Nov 2020 10:24:44 +0000 Subject: Add extra authorative TOSCA concepts This review brings in extra TOSCA concepts for Node types, nodes, and capabilities. The TOSCA handling is also amended to make the handling of equality consistent. Now, if filtering or ordering is required using an order rather than natural ordering, a comparator must be supplied by the user. Issue-ID: POLICY-2900 Change-Id: Ie40e86870b97eb993b1338bdc0666ac116f72f67 Signed-off-by: liamfallon --- .../policy/models/base/PfConceptComparator.java | 34 ++++++++++++++++++++++ .../onap/policy/models/base/PfConceptFilter.java | 4 +-- .../org/onap/policy/models/base/PfNameVersion.java | 4 +-- .../onap/policy/models/base/PfObjectFilter.java | 10 ++++--- 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java (limited to 'models-base/src/main/java/org') 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 { + + @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 { // @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> { +public interface PfObjectFilter { /** * Filter an incoming list, removing items that do not match the filter. * @@ -118,15 +119,16 @@ public interface PfObjectFilter> { * 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 latestVersionFilter(final List originalList) { + public default List latestVersionFilter(final List originalList, final Comparator versionComparator) { if (originalList.size() <= 1) { return originalList; } List filteredList = new ArrayList<>(originalList); - Collections.sort(filteredList); + Collections.sort(filteredList, versionComparator); int icur = 0; for (int j = 1; j < filteredList.size(); j++) { -- cgit 1.2.3-korg