Java SortedSet Type Check isSortedSet(final Object value)

Here you can find the source of isSortedSet(final Object value)

Description

Returns true if the given object is a non-null instance of SortedSet .

License

Open Source License

Parameter

Parameter Description
value The object to be evaluated.

Return

true if the given object is a non-null instance of . false otherwise.

Declaration

public static boolean isSortedSet(final Object value) 

Method Source Code

//package com.java2s;
/*/*from   w w  w . j a  v  a 2s.c o  m*/
 * 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.SortedSet;

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

    /**
     * Returns {@code true} if the given object is an instance of {@link SortedSet}.
     *
     * @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 SortedSet}. {@code false} otherwise.
     */
    public static boolean isSortedSet(final Object value, final boolean acceptNull) {
        return isType(SortedSet.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. isSortedSet(Object object)
  2. isSortedSetType(Class type)