aboutsummaryrefslogtreecommitdiffstats
path: root/models-base/src/main/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-11-20 10:24:44 +0000
committerliamfallon <liam.fallon@est.tech>2020-12-01 12:27:54 +0000
commit950cbb8872fb2227f4a0382a756a7e1dff53b09c (patch)
treece493c7161872360f4d88c5065c0730d53987c82 /models-base/src/main/java/org
parent1dd41890f83702d47c5a957493046433989ef36c (diff)
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 <liam.fallon@est.tech>
Diffstat (limited to 'models-base/src/main/java/org')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java34
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java4
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java4
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java10
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++) {