From 038c19d4042de980d4adccbfa82c1534b53abe5f Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 30 Jul 2021 16:06:49 -0400 Subject: Use lombok annotations in apex-pdp Updated projects: services-engine through utilities Issue-ID: POLICY-3391 Change-Id: I35ebb40d86e9bda360f7819516290b3fea88335c Signed-off-by: Jim Hahn --- .../apex/model/utilities/CollectionUtils.java | 10 ++--- .../apex/model/utilities/DirectoryUtils.java | 12 +++-- .../policy/apex/model/utilities/TreeMapUtils.java | 12 ++--- .../model/utilities/comparison/KeyDifference.java | 28 +++--------- .../utilities/comparison/KeyedMapDifference.java | 52 ++++------------------ .../apex/model/utilities/json/JsonHandler.java | 14 +++--- 6 files changed, 35 insertions(+), 93 deletions(-) (limited to 'model') diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/CollectionUtils.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/CollectionUtils.java index 190b270ea..8ca6d153e 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/CollectionUtils.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/CollectionUtils.java @@ -23,18 +23,16 @@ package org.onap.policy.apex.model.utilities; import java.util.List; import java.util.ListIterator; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * This is common utility class with static methods for handling collections. * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class CollectionUtils { - /** - * Private constructor used to prevent sub class instantiation. - */ - private CollectionUtils() { - } +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class CollectionUtils { /** * Compare two lists, checks for equality, then for equality on members. diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/DirectoryUtils.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/DirectoryUtils.java index 011dbb1b2..cc92d2a7f 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/DirectoryUtils.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/DirectoryUtils.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -22,6 +23,8 @@ package org.onap.policy.apex.model.utilities; import java.io.File; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -31,16 +34,11 @@ import org.slf4j.ext.XLoggerFactory; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public abstract class DirectoryUtils { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DirectoryUtils { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(DirectoryUtils.class); - /** - * Private constructor used to prevent sub class instantiation. - */ - private DirectoryUtils() { - } - /** * Method to get an empty temporary directory in the system temporary directory on the local machine that will be * deleted on (normal) shutdown. diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java index d48f7f951..6daa6864a 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java @@ -26,6 +26,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; import java.util.NavigableMap; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * This class provides utility functions for tree maps. A function to find the nearest match in the tree map to an input @@ -33,14 +35,8 @@ import java.util.NavigableMap; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class TreeMapUtils { - - /** - * This class is a utility class that can't be instantiated. - */ - private TreeMapUtils() { - // Private constructor to block subclassing - } +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class TreeMapUtils { /** * Find the list of entries that matches a given word, for example "p" will match "put", "policy", and "push". diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyDifference.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyDifference.java index 2eb6af894..b01c83d59 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyDifference.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyDifference.java @@ -1,25 +1,28 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 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. * 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.apex.model.utilities.comparison; +import lombok.Getter; + /** * This class is used to template key differences for bulk key comparisons in models. It performs a difference check * between two keys. @@ -27,6 +30,7 @@ package org.onap.policy.apex.model.utilities.comparison; * @author Liam Fallon (liam.fallon@ericsson.com) * @param the generic type */ +@Getter public class KeyDifference { // The keys being compared private K leftKey; @@ -43,24 +47,6 @@ public class KeyDifference { this.rightKey = rightKey; } - /** - * Gets the left key. - * - * @return the left key - */ - public K getLeftKey() { - return leftKey; - } - - /** - * Gets the right key. - * - * @return the right key - */ - public K getRightKey() { - return rightKey; - } - /** * Checks if the left and right keys are equal. * diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyedMapDifference.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyedMapDifference.java index 91c523ed1..a070ec9ce 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyedMapDifference.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/comparison/KeyedMapDifference.java @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 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. * 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========================================================= */ @@ -24,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; +import lombok.Getter; /** * This class holds the result of a difference check between two keyed maps. Four results are returned in the class. The @@ -36,6 +38,7 @@ import java.util.TreeMap; * @param the generic type * @param the generic type */ +@Getter public class KeyedMapDifference { private static final String KEY = "key="; private static final String VALUE = ",value="; @@ -46,43 +49,6 @@ public class KeyedMapDifference { private Map identicalValues = new TreeMap<>(); private Map> differentValues = new TreeMap<>(); - /** - * Gets the entries that were found only in the left map. - * - * @return the entries only in the left map - */ - public Map getLeftOnly() { - return leftOnly; - } - - /** - * Gets the entries that were found only in the right map. - * - * @return the entries only in the right map - */ - public Map getRightOnly() { - return rightOnly; - } - - /** - * Gets the entries that were identical (keys and values the same) in both maps. - * - * @return the identical entries - */ - public Map getIdenticalValues() { - return identicalValues; - } - - /** - * Gets the entries that had the same key but different values in both maps. - * - * @return the entries that were different. There are two values in the list of values for each entry. The first - * value is the value that was in the left map and the second value is the value that was in the right map. - */ - public Map> getDifferentValues() { - return differentValues; - } - /** * Return a string representation of the differences. * @@ -127,7 +93,7 @@ public class KeyedMapDifference { /** * Output the entries in a map with entries that are in one side only as a string. - * + * * @param sideMap the map for the side being checked * @param sideMapString the string that represents the map in output strings * @param keysOnly if true, just add key information and not entries @@ -153,7 +119,7 @@ public class KeyedMapDifference { /** * Output the differences between two the maps as a string. - * + * * @param keysOnly if true, just add key information and not entries * @return the differences as a string */ @@ -185,7 +151,7 @@ public class KeyedMapDifference { /** * Output the identical entries in the maps as a string. - * + * * @param keysOnly if true, just add key information and not entries * @return the identical entries as a string */ diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/json/JsonHandler.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/json/JsonHandler.java index bc0551c57..66e389fa2 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/json/JsonHandler.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/json/JsonHandler.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 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. * 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========================================================= */ @@ -33,6 +34,7 @@ import java.io.Reader; * @param

the generic type */ public class JsonHandler

{ + private static final Gson GSON = new GsonBuilder().serializeNulls().create(); /** * This method reads objects of a given class from an input stream. @@ -42,11 +44,7 @@ public class JsonHandler

{ * @return the object read */ public P read(final Class

inputClass, final InputStream inputStream) { - // Register the adapters for our carrier technologies and event protocols with GSON - final GsonBuilder gsonBuilder = new GsonBuilder(); - - final Gson gson = gsonBuilder.serializeNulls().create(); final Reader jsonResourceReader = new InputStreamReader(inputStream); - return gson.fromJson(jsonResourceReader, inputClass); + return GSON.fromJson(jsonResourceReader, inputClass); } } -- cgit 1.2.3-korg