Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.Queue;
import java.util.function.Consumer;
import com.google.common.base.Preconditions;

public class Main {
    /**
     * Polls every element within the specified {@link Queue} and performs the specified {@link Consumer} event for each
     * element.
     *
     * @param queue The Queue to poll each element for, may not be {@code null}.
     * @param consumer The Consumer event to execute for each polled element, may not be {@code null}.
     */
    public static <T> void pollAll(Queue<T> queue, Consumer<T> consumer) {
        Preconditions.checkNotNull(queue, "Queue may not be null");
        Preconditions.checkNotNull(consumer, "Consumer may not be null");

        T element;
        while ((element = queue.poll()) != null) {
            consumer.accept(element);
        }
    }
}