Java tutorial
//package com.java2s; /* * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * * Alfresco is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Alfresco is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Alfresco. If not, see <http://www.gnu.org/licenses/>. */ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; public class Main { /** * This method joins two lists returning the a single list consisting of the first followed by the second. * * @param first first list. can be null. * @param second second list. can be null. * @return the concatenation of both lists. will not be null */ public static <T> List<T> nullSafeAppend(List<T> first, List<T> second) { return nullSafeAppend(first, second, false); } /** * This method joins two lists returning the a single list consisting of the first followed by the second. * * @param first first list. can be null. * @param second second list. can be null. * @param emptyResultIsNull if the result is empty, should we return null? * @return the concatenation of both lists or null */ public static <T> List<T> nullSafeAppend(List<T> first, List<T> second, boolean emptyResultIsNull) { List<T> result = new ArrayList<T>(); if (first != null) result.addAll(first); if (second != null) result.addAll(second); if (result.isEmpty() && emptyResultIsNull) { result = null; } return result; } public static boolean isEmpty(Map<?, ?> map) { if (map == null) { return true; } return map.isEmpty(); } public static boolean isEmpty(Collection<?> items) { if (items == null) { return true; } return items.isEmpty(); } }