2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.base;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.function.Function;
27 import java.util.stream.Collectors;
30 * Utility class for Policy Framework concept utilities.
32 * @author Liam Fallon (liam.fallon@est.tech)
34 public final class PfUtils {
36 // Cannot be subclassed
40 * Compare two objects using their equals methods, nulls are allowed.
42 * @param leftObject the first object
43 * @param rightObject the second object
44 * @return a measure of the comparison
46 public static int compareObjects(final Object leftObject, final Object rightObject) {
47 if (leftObject == null && rightObject == null) {
51 if (leftObject == null) {
55 if (rightObject == null) {
59 if (!leftObject.equals(rightObject)) {
60 return leftObject.hashCode() - rightObject.hashCode();
67 * Convenience method to apply a mapping function to all of the elements of a list,
68 * generating a new list.
70 * @param source list whose elements are to be mapped, or {@code null}
71 * @param mapFunc mapping function
72 * @return a new list, containing mappings of all of the items in the original list
74 public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc) {
76 return new ArrayList<>();
79 return source.stream().map(mapFunc).collect(Collectors.toList());