Java BigDecimal Parse isBigDecimal(final Object value)

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

Description

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

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 isBigDecimal(final Object value) 

Method Source Code


//package com.java2s;
/*/*from w w  w.  j av  a 2  s . 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.math.BigDecimal;

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

    /**
     * Returns {@code true} if the given object is an instance of {@link BigDecimal}.
     *
     * @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 BigDecimal}. {@code false} otherwise.
     */
    public static boolean isBigDecimal(final Object value, final boolean acceptNull) {
        return isType(BigDecimal.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. isBigDecimal(@Nonnull Class type)
  2. isBigDecimal(final N number)
  3. isBigDecimal(Number n)
  4. isBigDecimal(Object obj)
  5. isBigDecimal(Object v)
  6. isBigDecimal(String str)