Java tutorial
//package com.java2s; /* * Lightmare, Lightweight embedded EJB container (works for stateless session beans) with JPA / Hibernate support * * Copyright (c) 2013, Levan Tsinadze, or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program 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 this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; public class Main { public static final int EMPTY_ARRAY_LENGTH = 0; /** * Creates new {@link List} from passed {@link Collection} instance * * @param collection * @return {@link List} translated from collection */ public static <T> List<T> translateToList(Collection<T> collection) { List<T> list; if (valid(collection)) { list = new ArrayList<T>(collection); } else { list = Collections.emptyList(); } return list; } /** * Checks passed {@link Collection} instance on null and on emptiness * returns true if it is not null and is not empty * * @param collection * @return <code></code> */ public static boolean valid(Collection<?> collection) { return (collection != null && !collection.isEmpty()); } /** * Checks passed {@link Map} instance on null and emptiness returns true if * it is not null and is not empty * * @param map * @return <code>boolean</code> */ public static boolean valid(Map<?, ?> map) { return (map != null && !map.isEmpty()); } /** * Checks if passed array of {@link Object}'s instances is not null and is * not empty * * @param array * @return <code>boolean</code> */ public static boolean valid(Object[] array) { return (array != null && array.length > EMPTY_ARRAY_LENGTH); } }