Java Collection Search hasValue(Collection collection)

Here you can find the source of hasValue(Collection collection)

Description

Is this a non-null collection w/ at least 1 item in it?

License

Open Source License

Parameter

Parameter Description
collection The collection to test

Return

Is it a collection with data in it?

Declaration

public static boolean hasValue(Collection<?> collection) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    /**/*from w  w  w  .  j  av a2 s. c om*/
     * Does the given string have a "meaningful" value? This means its non-null/empty. Additionally, all-whitespace
     * strings will return false as those are not "meaningful" values.
     * @param text The text to test
     * @return Does the text have a meaningful value?
     */
    public static boolean hasValue(String text) {
        return (text != null) && text.trim().length() > 0;
    }

    /**
     * Is this a non-null collection w/ at least 1 item in it?
     * @param collection The collection to test
     * @return Is it a collection with data in it?
     */
    public static boolean hasValue(Collection<?> collection) {
        return (collection != null) && collection.size() > 0;
    }
}

Related

  1. hasLength(final Collection collection)
  2. hasNoValue(Collection collection)
  3. hasOneItem(final Collection col)
  4. hasOtherThan(Collection a, Collection b)
  5. hasValidElement(Collection collection)
  6. indexOf(Collection stringCollection, String str)
  7. indexOf(final Collection c, final Object elem)
  8. indexOfInstance(final Collection collection, final T instance)
  9. indexOfObjectIdentity(Collection collection, Object object)