Java BigDecimal Value Check isMaximumDecimalValue(BigDecimal maxValue)

Here you can find the source of isMaximumDecimalValue(BigDecimal maxValue)

Description

Checks if the specified BigDecimal value is a maximum value of a DECIMAL(x,0) data type.
This method will not consider a value smaller than the BIGINT data type maximum value as a potential DECIMAL maximum value.

License

Open Source License

Parameter

Parameter Description
maxValue a parameter

Declaration

public static boolean isMaximumDecimalValue(BigDecimal maxValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 neXtep Software and contributors.
 * All rights reserved./*from ww  w . j  a v  a 2 s .  c  o m*/
 *
 * This file is part of neXtep designer.
 *
 * NeXtep designer is free software: you can redistribute it 
 * and/or modify it under the terms of the GNU General Public 
 * License as published by the Free Software Foundation, either 
 * version 3 of the License, or any later version.
 *
 * NeXtep designer 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     neXtep Softwares - initial API and implementation
 *******************************************************************************/

import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public final static BigDecimal DATATYPE_BIGINT_MAX_VALUE = new BigDecimal("9223372036854775807");

    /**
     * Checks if the specified <code>BigDecimal</code> value is a maximum value of a
     * <code>DECIMAL(x,0)</code> data type.<br>
     * This method will not consider a value smaller than the <code>BIGINT</code> data type maximum
     * value as a potential <code>DECIMAL</code> maximum value.
     * 
     * @param maxValue
     * @return
     */
    public static boolean isMaximumDecimalValue(BigDecimal maxValue) {
        if (maxValue != null && maxValue.compareTo(DATATYPE_BIGINT_MAX_VALUE) > 0) {
            Pattern p = Pattern.compile("[^9]+"); //$NON-NLS-1$
            Matcher m = p.matcher(maxValue.toString());
            return !m.find();
        }

        return false;
    }
}

Related

  1. isLessThan(final BigDecimal thiss, final BigDecimal that)
  2. isLessThen(BigDecimal value1, BigDecimal value2)
  3. isLong(BigDecimal inValue)
  4. isLongNumber(BigDecimal minCar)
  5. isLowerThanOne(@Nonnull final BigDecimal aValue)
  6. isMoreThanZero(BigDecimal decimal)
  7. isNegative(BigDecimal amount)
  8. isNegative(BigDecimal inValue)
  9. isNotNullOrZero(final BigDecimal number)