Java Queue Usage isQueue(final Object value, final boolean acceptNull)

Here you can find the source of isQueue(final Object value, final boolean acceptNull)

Description

Returns true if the given object is an instance of Queue .

License

Open Source License

Parameter

Parameter Description
value The object to be evaluated.
acceptNull Indicates if this method may return true in case of null values.

Return

true if the given object is an instance of . false otherwise.

Declaration

public static boolean isQueue(final Object value, final boolean acceptNull) 

Method Source Code

//package com.java2s;
/*//from  w  w  w . ja v  a 2 s.com
 * Copyright (C) 2013 Marcius da Silva da Fonseca.
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA
 */

import java.util.Queue;

public class Main {
    /**
     * Returns {@code true} if the given object is a <b>non-null</b> instance of {@link Queue}.
     *
     * @param value The object to be evaluated.
     * @return {@code true} if the given object is a non-null instance of {@link Queue}. {@code false} otherwise.
     */
    public static boolean isQueue(final Object value) {
        return isQueue(value, false);
    }

    /**
     * Returns {@code true} if the given object is an instance of {@link Queue}.
     *
     * @param value The object to be evaluated.
     * @param acceptNull Indicates if this method may return {@code true} in case of {@code null} values.
     * @return {@code true} if the given object is an instance of {@link Queue}. {@code false} otherwise.
     */
    public static boolean isQueue(final Object value, final boolean acceptNull) {
        return isType(Queue.class, value, acceptNull);
    }

    /**
     * Returns {@code true} if the given object is a <b>non-null</b> instance of the given type.
     *
     * @param type  The type to be tested against the object.
     * @param value The object to be evaluated.
     * @return {@code true} if the given object is a non-null instance of the given type. {@code false} otherwise.
     * @throws IllegalArgumentException If the given type is invalid or null.
     */
    public static boolean isType(final Class<?> type, final Object value) {
        return isType(type, value, false);
    }

    /**
     * Returns {@code true} if the given object is an instance of the given type.
     *
     * @param type  The type to be tested against the object. Cannot be null.
     * @param value The object to be evaluated.
     * @param acceptNull Indicates if this method may return {@code true} in case of {@code null} values.
     * @return {@code true} if the given object is an instance of the given type. {@code false} otherwise.
     * @throws IllegalArgumentException If the given type is invalid or null.
     */
    public static boolean isType(final Class<?> type, final Object value, final boolean acceptNull) {
        if (type == null) {
            throw new IllegalArgumentException("The type cannot be null.");
        }
        return (value == null && acceptNull) || (value != null && type.isAssignableFrom(value.getClass()));
    }
}

Related

  1. convertQueueToArray(Queue q)
  2. elementFail(Queue q)
  3. get(Queue queue, int index)
  4. getAllElementsFromQueueAsList(Queue queue)
  5. isListBased(Class type)
  6. loadBalancingLeftHeavy(List tasks, int size)
  7. offerUntilSuccess(T entry, Queue queue)
  8. parsePathToStack(String path)
  9. pollWhileNotEmpty(Queue queue)

  10. HOME | Copyright © www.java2s.com 2016