001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2021, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.oauth2.sdk.util;
019
020
021import java.util.LinkedList;
022import java.util.List;
023
024
025/**
026 * List utilities.
027 */
028public class ListUtils {
029        
030        
031        /**
032         * Returns a copy of the specified list with all {@code null} items
033         * removed.
034         *
035         * @param list The list. May be {@code null}.
036         *
037         * @return The list with all {@code null} items removed, {@code null}
038         *         if not specified.
039         */
040        public static <T> List<T> removeNullItems(final List<T> list) {
041                if (list == null) {
042                        return null;
043                }
044                List<T> out = new LinkedList<>();
045                for (T item: list) {
046                        if (item != null) {
047                                out.add(item);
048                        }
049                }
050                return out;
051        }
052        
053        
054        /**
055         * Prevents public instantiation.
056         */
057        private ListUtils() {}
058}