Make filters on TOSCA entities generic
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / concepts / ToscaEntityFilter.java
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,13 +28,13 @@ import lombok.NonNull;
 import org.onap.policy.models.base.PfObjectFilter;
 
 /**
- * Filter class for searches for {@link ToscaPolicyType} instances. If any fields are null, they are ignored.
+ * Filter class for searches for {@link ToscaEntity} instances. If any fields are null, they are ignored.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 @Builder
 @Data
-public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> {
+public class ToscaEntityFilter<T extends ToscaEntity> implements PfObjectFilter<T> {
     public static final String LATEST_VERSION = "LATEST";
 
     // Regular expression
@@ -44,10 +44,10 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> {
     private String version;
 
     @Override
-    public List<ToscaPolicyType> filter(@NonNull final List<ToscaPolicyType> originalList) {
+    public List<T> filter(@NonNull final List<T> originalList) {
 
         // @formatter:off
-        List<ToscaPolicyType> returnList = originalList.stream()
+        List<T> returnList = originalList.stream()
                 .filter(p -> filterString(p.getName(), name))
                 .filter(p -> LATEST_VERSION.equals(version)
                         || filterString(p.getVersion(), version))
@@ -55,7 +55,7 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> {
         // @formatter:off
 
         if (LATEST_VERSION.equals(version)) {
-            return this.latestVersionFilter(returnList, new ToscaPolicyTypeComparator());
+            return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>());
         } else  {
             return returnList;
         }