001/** 002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.gnu.org/licenses/lgpl-3.0.txt 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package dev.tinyflow.core.util; 017 018import java.util.Collection; 019import java.util.List; 020 021public class CollectionUtil { 022 023 private CollectionUtil() { 024 } 025 026 027 public static <T> boolean noItems(Collection<?> collection) { 028 return collection == null || collection.isEmpty(); 029 } 030 031 032 public static boolean hasItems(Collection<?> collection) { 033 return !noItems(collection); 034 } 035 036 public static <T> T firstItem(List<T> list) { 037 if (list == null || list.isEmpty()) { 038 return null; 039 } 040 return list.get(0); 041 } 042 043 044 public static <T> T lastItem(List<T> list) { 045 if (list == null || list.isEmpty()) { 046 return null; 047 } 048 return list.get(list.size() - 1); 049 } 050}