Example usage for java.util Collection isEmpty

List of usage examples for java.util Collection isEmpty

Introduction

In this page you can find the example usage for java.util Collection isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:com.enonic.cms.core.content.binary.ContentBinaryDataEntity.java

public static List<ContentBinaryDataEntity> createNewFrom(Collection<BinaryDataAndBinary> collection) {
    List<ContentBinaryDataEntity> list = new ArrayList<ContentBinaryDataEntity>();
    if (collection == null || collection.isEmpty()) {
        return list;
    }//from w  ww . java2 s  .c  o m

    for (BinaryDataAndBinary binaryDataAndBinary : collection) {
        list.add(createNewFrom(binaryDataAndBinary));
    }

    return list;
}

From source file:eu.scidipes.toolkits.palibrary.utils.XMLUtils.java

/**
 * Transforms a collection of {@link FormField} objects into a simple XML document
 * //from   w w  w .j  a  va  2 s .co m
 * @param fields
 *            a collection of form fields
 * @return an xml document representing the form fields, or null if the passed collection is null or empty, or all
 *         form fields have an empty value
 */
public static Node formFieldsToMetadata(final Collection<? extends FormField> fields) {
    if (fields != null && !fields.isEmpty()) {
        try {
            final Document xml;

            synchronized (documentBuilderFactory) {
                xml = documentBuilderFactory.newDocumentBuilder().newDocument();
            }

            xml.setXmlStandalone(true);
            final Element metaData = xml.createElement("metadata");
            int completedFieldCount = 0;

            for (final FormField field : fields) {
                if (!StringUtils.isEmpty(field.getValue())) {
                    completedFieldCount++;
                    final Element metaDataEntry = xml.createElement("metadataentry");
                    final Element entryName = xml.createElement("entryname");
                    final Element entryValue = xml.createElement("entryvalue");

                    entryName.setTextContent(field.getDisplayName());
                    entryValue.setTextContent(field.getValue());

                    metaDataEntry.appendChild(entryName);
                    metaDataEntry.appendChild(entryValue);
                    metaData.appendChild(metaDataEntry);
                }
            }

            if (completedFieldCount > 0) {
                xml.appendChild(metaData);
                return xml;
            } else {
                return null;
            }

        } catch (final ParserConfigurationException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return null;
}

From source file:io.atomix.core.tree.DocumentPath.java

/**
 * Returns the path that points to the least common ancestor of the specified
 * collection of paths.//  w  w  w  . j av  a  2 s  . c  o  m
 *
 * @param paths collection of path
 * @return path to least common ancestor
 */
public static DocumentPath leastCommonAncestor(Collection<DocumentPath> paths) {
    if (paths.isEmpty()) {
        return null;
    }
    return DocumentPath.from(
            StringUtils.getCommonPrefix(paths.stream().map(DocumentPath::toString).toArray(String[]::new)));
}

From source file:hu.webhejj.commons.text.StringUtils.java

/** @return a string representation of an enum set suitable for storage in a database */
public static <E extends Enum<E>> String enumCollectionToString(Collection<E> enumSet) {

    if (enumSet != null && !enumSet.isEmpty()) {
        StringBuilder buf = new StringBuilder();
        buf.append(",");

        for (Enum<E> value : enumSet) {
            buf.append(value);//  w  w  w . java  2  s .c  o m
            buf.append(",");
        }

        return buf.toString();
    }

    return null;
}

From source file:Main.java

/**
 * Transforms a collection of Integers into a comma delimited String. If the
 * given collection of elements are null or is empty, an empty String is
 * returned./*from w  ww . j av a  2s.c o m*/
 *
 * @param delimitPrefix whether to prefix the string with a delimiter.
 * @param delimitSuffix whether to suffix the string with a delimiter.
 * @param elements      the collection of Integers
 * @return a comma delimited String.
 */
public static String getCommaDelimitedString(Collection<?> elements, boolean delimitPrefix,
        boolean delimitSuffix) {
    final StringBuilder builder = new StringBuilder();

    if (elements != null && !elements.isEmpty()) {
        if (delimitPrefix) {
            builder.append(DELIMITER);
        }

        builder.append(getCommaDelimitedString(elements));

        if (delimitSuffix) {
            builder.append(DELIMITER);
        }
    }

    return builder.toString();
}

From source file:Main.java

/**
 * Checks whether the extension of the filename is one of those specified.
 * <p>/* w  w  w .  ja va 2 s.  c om*/
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extensions  the extensions to check for, null checks for no extension
 * @return true if the filename is one of the extensions
 */
public static boolean isExtension(String filename, Collection<String> extensions) {
    if (filename == null) {
        return false;
    }
    if (extensions == null || extensions.isEmpty()) {
        return indexOfExtension(filename) == -1;
    }
    String fileExt = getExtension(filename);
    for (String extension : extensions) {
        if (fileExt.equals(extension)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Creates an array of the given Collection's elements, but with the given
 * <code>Class</code> as element type. Useful for arrays of objects that
 * implement multiple interfaces and a "typed view" onto these objects is
 * required.//from  w ww .ja v a  2 s.  co  m
 * 
 * @param objects a Collection of objects
 * @param clazz the desired service type of the new array
 * @return <code>null</code> when objects is <code>null</code>, or a new
 *         array containing the elements of the source array which is typed to
 *         the given <code>clazz</code> parameter.
 * @throws IllegalArgumentException if the <code>clazz</code> argument is
 *             <code>null</code>.
 * @throws ArrayStoreException if the elements in <code>objects</code> cannot
 *             be cast to <code>clazz</code>.
 */
public static <T> T[] toArrayOfComponentType(Collection objects, Class<T> clazz) {
    if (objects == null) {
        return null;
    }

    if (clazz == null) {
        throw new IllegalArgumentException("Array target class must not be null");
    }

    if (objects.isEmpty()) {
        return (T[]) Array.newInstance(clazz, 0);
    }

    int i = 0, size = objects.size();
    T[] result = (T[]) Array.newInstance(clazz, size);
    Iterator iter = objects.iterator();

    while (i < size && iter.hasNext()) {
        result[i++] = (T) iter.next();
    }

    return result;
}

From source file:com.bstek.dorado.util.Assert.java

/**
 * ????message?<br>// w w w.j  a v a 2 s .  c  om
 * ???nullsize0
 * @param collection ?
 * @param message ??
 */
public static void notEmpty(Collection<?> collection, String message) {
    if (collection == null || collection.isEmpty()) {
        throw new IllegalArgumentException(message);
    }
}

From source file:com.precioustech.fxtrading.utils.TradingUtils.java

/**
 * A utility method that is an alternative to having to write null and empty
 * checks for collections at various places in the code. Akin to
 * StringUtils.isEmpty() which returns true if input String is null or 0
 * length.//w ww  . jav a  2  s . c o  m
 * 
 * @param collection
 * @return boolean true if collection is null or is empty else false.
 * @see StringUtils#isEmpty(CharSequence)
 */
public static final boolean isEmpty(Collection<?> collection) {
    return collection == null || collection.isEmpty();
}

From source file:Main.java

/**
 * Checks if the given collection is empty.
 *
 * @param c//from ww  w . jav a2 s.c om
 *          collection to check
 * @return <code>true</code> if the given reference is <code>null</code> or collection is empty
 */
public static boolean isEmpty(final Collection<?> c) {
    return c == null || c.isEmpty();
}