Clean up a couple of array lists 38/84438/3
authorJim Hahn <jrh3@att.com>
Sun, 7 Apr 2019 14:50:27 +0000 (10:50 -0400)
committerJim Hahn <jrh3@att.com>
Sun, 7 Apr 2019 15:00:07 +0000 (11:00 -0400)
Initialized initial array size for empty list.
Add some junit tests to ensure that the returned lists are mutable.
Updated license in filter class.

Change-Id: I9c151eb50355a71f4d34ac46b41f8278cf913664
Issue-ID: POLICY-1542
Signed-off-by: Jim Hahn <jrh3@att.com>
models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java
models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java

index a7d8401..6ede4d9 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
index 7bdd9a5..c33271d 100644 (file)
@@ -73,7 +73,7 @@ public final class PfUtils {
      */
     public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc) {
         if (source == null) {
-            return new ArrayList<>();
+            return new ArrayList<>(0);
         }
 
         return source.stream().map(mapFunc).collect(Collectors.toList());
index 11ddf31..339ee9d 100644 (file)
@@ -52,9 +52,19 @@ public class PfUtilsTest {
         });
         assertTrue(resultList.isEmpty());
 
+        // verify that we can modify the empty list without throwing an exception
+        resultList.add("xyz");
+        resultList.add("pdq");
+        resultList.remove("xyz");
+
+
         List<String> origList = Arrays.asList("abc", "def");
         List<String> newList = PfUtils.mapList(origList, text -> text + "X");
 
         assertEquals(Arrays.asList("abcX", "defX"), newList);
+
+        // verify that we can modify the list without throwing an exception
+        newList.remove("abcX");
+        newList.add("something else");
     }
 }