Returns if the collection contains only empty objects (i.e. - Java java.util

Java examples for java.util:Collection Contain

Description

Returns if the collection contains only empty objects (i.e.

Demo Code

/**//  ww  w  . j a  v  a  2s  . c o m
 * Helpful methods for collections.
 * 
 * ## Legal stuff
 * 
 * Copyright 2014-2014 Ekkart Kleinod <ekleinod@edgesoft.de>
 * 
 * This file is part of edgeUtils.
 * 
 * edgeUtils 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.
 * 
 * edgeUtils 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 edgeUtils.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author Ekkart Kleinod
 * @version 0.2
 * @since 0.2
 */
//package com.java2s;

import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection theCollection = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out.println(isEmptyString(theCollection));
    }

    /**
     * Returns if the collection contains only empty objects (i.e. every contained object.toString returns "").
     * 
     * @param theCollection collection to check
     * @return does collection contain only empty objects
     *  @retval true only empty objects
     *  @retval false at least one nonempty object
     * 
     * @version 0.2
     * @since 0.2
     */
    public static <T> boolean isEmptyString(Collection<T> theCollection) {
        if (theCollection == null) {
            return false;
        }

        boolean bReturn = true;

        for (T theObject : theCollection) {
            if (!theObject.toString().isEmpty()) {
                bReturn = false;
            }
        }

        return bReturn;
    }
}

Related Tutorials