Java BigDecimal byteOverflow(BigDecimal value)

Here you can find the source of byteOverflow(BigDecimal value)

Description

Checks for overflow when converting a BigDecimal to a byte.

License

Apache License

Parameter

Parameter Description
BigDecimal the input value

Return

true if no overflow occurs

Declaration

public static boolean byteOverflow(BigDecimal value) 

Method Source Code

//package com.java2s;
/**/*from   w ww  . j  a  va2  s .c  o m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
    private static final BigDecimal BIGDECIMAL_BYTE_MAX = new BigDecimal(Byte.MAX_VALUE);
    private static final BigDecimal BIGDECIMAL_BYTE_MIN = new BigDecimal(Byte.MIN_VALUE);
    private static final BigInteger BIGINT_BYTE_MAX = new BigInteger(BIGDECIMAL_BYTE_MAX.toString());
    private static final BigInteger BIGINT_BYTE_MIN = new BigInteger(BIGDECIMAL_BYTE_MIN.toString());

    /**
     * Checks for overflow when converting a double to a byte.
     * @param    Double    the input value
     * @return             true if no overflow occurs
     */
    public static boolean byteOverflow(Double value) {
        return value < Byte.MIN_VALUE || value > Byte.MAX_VALUE ? false : true;
    }

    /**
     * Checks for overflow when converting a float to a byte.
     * @param    Float    the input value
     * @return            true if no overflow occurs
     */
    public static boolean byteOverflow(Float value) {
        return value < Byte.MIN_VALUE || value > Byte.MAX_VALUE ? false : true;
    }

    /**
     * Checks for overflow when converting a long to a byte.
     * @param    Long    the input value
     * @return           true if no overflow occurs
     */
    public static boolean byteOverflow(Long value) {
        return value < Byte.MIN_VALUE || value > Byte.MAX_VALUE ? false : true;
    }

    /**
     * Checks for overflow when converting an integer to a byte.
     * @param    Integer    the input value
     * @return              true if no overflow occurs
     */
    public static boolean byteOverflow(Integer value) {
        return value < Byte.MIN_VALUE || value > Byte.MAX_VALUE ? false : true;
    }

    /**
     * Checks for overflow when converting a short to a byte.
     * @param    Short    the input value
     * @return            true if no overflow occurs
     */
    public static boolean byteOverflow(Short value) {
        return value < Byte.MIN_VALUE || value > Byte.MAX_VALUE ? false : true;
    }

    /**
     * Checks for overflow when converting a BigDecimal to a byte.
     * @param    BigDecimal    the input value
     * @return                 true if no overflow occurs
     */
    public static boolean byteOverflow(BigDecimal value) {
        return value.compareTo(BIGDECIMAL_BYTE_MAX) > 0 || value.compareTo(BIGDECIMAL_BYTE_MIN) < 0 ? false : true;
    }

    /**
     * Checks for overflow when converting a BigInteger to a byte.
     * @param    BigInteger    the input value
     * @return                 true if no overflow occurs
     */
    public static boolean byteOverflow(BigInteger value) {
        return value.compareTo(BIGINT_BYTE_MAX) > 0 || value.compareTo(BIGINT_BYTE_MIN) < 0 ? false : true;
    }
}

Related

  1. bigDecimalListToArray(List list)
  2. bigDecimalObjectValue(Object input)
  3. bigDecimalParse(String value)
  4. bigDecimalPrint(BigDecimal value)
  5. bigDecimalProperty(ObjectNode node, String propertyName, BigDecimal propertyValue)
  6. cloneBigDecimal(BigDecimal bdOriginal)
  7. createJsonNumber(BigDecimal d)
  8. createReconFileHeader(int totalCount, BigDecimal totalAmount)
  9. cuberoot(BigDecimal b)