Tabnine Logo
IterableUtils.emptyIteratorIfNull
Code IndexAdd Tabnine to your IDE (free)

How to use
emptyIteratorIfNull
method
in
org.apache.commons.collections4.IterableUtils

Best Java code snippets using org.apache.commons.collections4.IterableUtils.emptyIteratorIfNull (Showing top 14 results out of 315)

origin: org.apache.commons/commons-collections4

/**
 * Applies the closure to each element of the provided iterable.
 *
 * @param <E> the element type
 * @param iterable  the iterator to use, may be null
 * @param closure  the closure to apply to each element, may not be null
 * @throws NullPointerException if closure is null
 */
public static <E> void forEach(final Iterable<E> iterable, final Closure<? super E> closure) {
  IteratorUtils.forEach(emptyIteratorIfNull(iterable), closure);
}
origin: org.apache.commons/commons-collections4

/**
 * Gets a new list with the contents of the provided iterable.
 *
 * @param <E> the element type
 * @param iterable  the iterable to use, may be null
 * @return a list of the iterator contents
 */
public static <E> List<E> toList(final Iterable<E> iterable) {
  return IteratorUtils.toList(emptyIteratorIfNull(iterable));
}
origin: org.apache.commons/commons-collections4

/**
 * Executes the given closure on each but the last element in the iterable.
 * <p>
 * If the input iterable is null no change is made.
 *
 * @param <E> the type of object the {@link Iterable} contains
 * @param iterable  the iterable to get the input from, may be null
 * @param closure  the closure to perform, may not be null
 * @return the last element in the iterable, or null if iterable is null or empty
 */
public static <E> E forEachButLast(final Iterable<E> iterable, final Closure<? super E> closure) {
  return IteratorUtils.forEachButLast(emptyIteratorIfNull(iterable), closure);
}
origin: org.apache.commons/commons-collections4

/**
 * Returns the number of elements contained in the given iterator.
 * <p>
 * A <code>null</code> or empty iterator returns {@code 0}.
 *
 * @param iterable  the iterable to check, may be null
 * @return the number of elements contained in the iterable
 */
public static int size(final Iterable<?> iterable) {
  if (iterable instanceof Collection<?>) {
    return ((Collection<?>) iterable).size();
  }
  return IteratorUtils.size(emptyIteratorIfNull(iterable));
}
origin: org.apache.commons/commons-collections4

/**
 * Finds the first element in the given iterable which matches the given predicate.
 * <p>
 * A <code>null</code> or empty iterator returns null.
 *
 * @param <E> the element type
 * @param iterable  the iterable to search, may be null
 * @param predicate  the predicate to use, may not be null
 * @return the first element of the iterable which matches the predicate or null if none could be found
 * @throws NullPointerException if predicate is null
 */
public static <E> E find(final Iterable<E> iterable, final Predicate<? super E> predicate) {
  return IteratorUtils.find(emptyIteratorIfNull(iterable), predicate);
}
origin: org.apache.commons/commons-collections4

/**
 * Answers true if a predicate is true for any element of the iterable.
 * <p>
 * A <code>null</code> or empty iterable returns false.
 *
 * @param <E> the type of object the {@link Iterable} contains
 * @param iterable  the {@link Iterable} to use, may be null
 * @param predicate  the predicate to use, may not be null
 * @return true if any element of the collection matches the predicate, false otherwise
 * @throws NullPointerException if predicate is null
 */
public static <E> boolean matchesAny(final Iterable<E> iterable, final Predicate<? super E> predicate) {
  return IteratorUtils.matchesAny(emptyIteratorIfNull(iterable), predicate);
}
origin: org.apache.commons/commons-collections4

/**
 * Answers true if the provided iterable is empty.
 * <p>
 * A <code>null</code> iterable returns true.
 *
 * @param iterable  the {@link Iterable to use}, may be null
 * @return true if the iterable is null or empty, false otherwise
 */
public static boolean isEmpty(final Iterable<?> iterable) {
  if (iterable instanceof Collection<?>) {
    return ((Collection<?>) iterable).isEmpty();
  }
  return IteratorUtils.isEmpty(emptyIteratorIfNull(iterable));
}
origin: org.apache.commons/commons-collections4

/**
 * Returns the index of the first element in the specified iterable that
 * matches the given predicate.
 * <p>
 * A <code>null</code> or empty iterable returns -1.
 *
 * @param <E> the element type
 * @param iterable  the iterable to search, may be null
 * @param predicate  the predicate to use, may not be null
 * @return the index of the first element which matches the predicate or -1 if none matches
 * @throws NullPointerException if predicate is null
 */
public static <E> int indexOf(final Iterable<E> iterable, final Predicate<? super E> predicate) {
  return IteratorUtils.indexOf(emptyIteratorIfNull(iterable), predicate);
}
origin: org.apache.commons/commons-collections4

/**
 * Returns a string representation of the elements of the specified iterable.
 * <p>
 * The string representation consists of a list of the iterable's elements,
 * enclosed in square brackets ({@code "[]"}). Adjacent elements are separated
 * by the characters {@code ", "} (a comma followed by a space). Elements are
 * converted to strings as by {@code String.valueOf(Object)}.
 *
 * @param <E> the element type
 * @param iterable  the iterable to convert to a string, may be null
 * @return a string representation of {@code iterable}
 */
public static <E> String toString(final Iterable<E> iterable) {
  return IteratorUtils.toString(emptyIteratorIfNull(iterable));
}
origin: org.apache.commons/commons-collections4

/**
 * Answers true if a predicate is true for every element of an iterable.
 * <p>
 * A <code>null</code> or empty iterable returns true.
 *
 * @param <E> the type of object the {@link Iterable} contains
 * @param iterable  the {@link Iterable} to use, may be null
 * @param predicate  the predicate to use, may not be null
 * @return true if every element of the collection matches the predicate or if the
 *   collection is empty, false otherwise
 * @throws NullPointerException if predicate is null
 */
public static <E> boolean matchesAll(final Iterable<E> iterable, final Predicate<? super E> predicate) {
  return IteratorUtils.matchesAll(emptyIteratorIfNull(iterable), predicate);
}
origin: org.apache.commons/commons-collections4

/**
 * Checks if the object is contained in the given iterable.
 * <p>
 * A <code>null</code> or empty iterable returns false.
 *
 * @param <E> the type of object the {@link Iterable} contains
 * @param iterable  the iterable to check, may be null
 * @param object  the object to check
 * @return true if the object is contained in the iterable, false otherwise
 */
public static <E> boolean contains(final Iterable<E> iterable, final Object object) {
  if (iterable instanceof Collection<?>) {
    return ((Collection<E>) iterable).contains(object);
  }
  return IteratorUtils.contains(emptyIteratorIfNull(iterable), object);
}
origin: org.apache.commons/commons-collections4

/**
 * Returns a string representation of the elements of the specified iterable.
 * <p>
 * The string representation consists of a list of the iterable's elements,
 * enclosed in square brackets ({@code "[]"}). Adjacent elements are separated
 * by the characters {@code ", "} (a comma followed by a space). Elements are
 * converted to strings as by using the provided {@code transformer}.
 *
 * @param <E> the element type
 * @param iterable  the iterable to convert to a string, may be null
 * @param transformer  the transformer used to get a string representation of an element
 * @return a string representation of {@code iterable}
 * @throws NullPointerException if {@code transformer} is null
 */
public static <E> String toString(final Iterable<E> iterable,
                 final Transformer<? super E, String> transformer) {
  if (transformer == null) {
    throw new NullPointerException("Transformer must not be null.");
  }
  return IteratorUtils.toString(emptyIteratorIfNull(iterable), transformer);
}
origin: org.apache.commons/commons-collections4

/**
 * Returns a string representation of the elements of the specified iterable.
 * <p>
 * The string representation consists of a list of the iterable's elements,
 * enclosed by the provided {@code prefix} and {@code suffix}. Adjacent elements
 * are separated by the provided {@code delimiter}. Elements are converted to
 * strings as by using the provided {@code transformer}.
 *
 * @param <E> the element type
 * @param iterable  the iterable to convert to a string, may be null
 * @param transformer  the transformer used to get a string representation of an element
 * @param delimiter  the string to delimit elements
 * @param prefix  the prefix, prepended to the string representation
 * @param suffix  the suffix, appended to the string representation
 * @return a string representation of {@code iterable}
 * @throws NullPointerException if either transformer, delimiter, prefix or suffix is null
 */
public static <E> String toString(final Iterable<E> iterable,
                 final Transformer<? super E, String> transformer,
                 final String delimiter,
                 final String prefix,
                 final String suffix) {
  return IteratorUtils.toString(emptyIteratorIfNull(iterable),
                 transformer, delimiter, prefix, suffix);
}
origin: org.apache.commons/commons-collections4

/**
 * Returns the <code>index</code>-th value in the <code>iterable</code>'s {@link Iterator}, throwing
 * <code>IndexOutOfBoundsException</code> if there is no such element.
 * <p>
 * If the {@link Iterable} is a {@link List}, then it will use {@link List#get(int)}.
 *
 * @param <T> the type of object in the {@link Iterable}.
 * @param iterable  the {@link Iterable} to get a value from, may be null
 * @param index  the index to get
 * @return the object at the specified index
 * @throws IndexOutOfBoundsException if the index is invalid
 */
public static <T> T get(final Iterable<T> iterable, final int index) {
  CollectionUtils.checkIndexBounds(index);
  if (iterable instanceof List<?>) {
    return ((List<T>) iterable).get(index);
  }
  return IteratorUtils.get(emptyIteratorIfNull(iterable), index);
}
org.apache.commons.collections4IterableUtilsemptyIteratorIfNull

Javadoc

Returns an empty iterator if the argument is null, or iterable.iterator() otherwise.

Popular methods of IterableUtils

  • find
    Finds the first element in the given iterable which matches the given predicate. A null or empty it
  • get
    Returns the index-th value in the iterable's Iterator, throwing IndexOutOfBoundsException if there i
  • forEach
    Applies the closure to each element of the provided iterable.
  • isEmpty
    Answers true if the provided iterable is empty. A null iterable returns true.
  • matchesAny
    Answers true if a predicate is true for any element of the iterable. A null or empty iterable return
  • countMatches
    Counts the number of elements in the input iterable that match the predicate. A null iterable matche
  • emptyIterable
    Gets an empty iterable. This iterable does not contain any elements.
  • forEachButLast
    Executes the given closure on each but the last element in the iterable. If the input iterable is nu
  • indexOf
    Returns the index of the first element in the specified iterable that matches the given predicate. A
  • toList
    Gets a new list with the contents of the provided iterable.
  • boundedIterable
    Returns a view of the given iterable that contains at most the given number of elements. The returne
  • chainedIterable
    Combines the provided iterables into a single iterable. The returned iterable has an iterator that t
  • boundedIterable,
  • chainedIterable,
  • checkNotNull,
  • collatedIterable,
  • contains,
  • emptyIfNull,
  • filteredIterable,
  • frequency,
  • loopingIterable

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setContentView (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • JPanel (javax.swing)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now