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.List;
25 import java.util.function.Function;
26 import java.util.stream.Collectors;
29 * Utility class for Policy Framework concept utilities.
31 * @author Liam Fallon (liam.fallon@est.tech)
33 public final class PfUtils {
35 // Cannot be subclassed
39 * Compare two objects using their equals methods, nulls are allowed.
41 * @param leftObject the first object
42 * @param rightObject the second object
43 * @return a measure of the comparison
45 public static int compareObjects(final Object leftObject, final Object rightObject) {
46 if (leftObject == null && rightObject == null) {
50 if (leftObject == null) {
54 if (rightObject == null) {
58 if (!leftObject.equals(rightObject)) {
59 return leftObject.hashCode() - rightObject.hashCode();
66 * Convenience method to apply a mapping function to all of the elements of a list,
67 * generating a new list.
69 * @param source list whose elements are to be mapped, or {@code null}
70 * @param mapFunc mapping function
71 * @return a new list, containing mappings of all of the items in the original list
73 public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc) {
78 return source.stream().map(mapFunc).collect(Collectors.toList());