Here you can find the source of isIntValue(BigInteger bi)
Parameter | Description |
---|---|
bi | The BigInteger to convert. |
bi
is in the correct range return true
, otherwise return false
.
public static boolean isIntValue(BigInteger bi)
//package com.java2s; /*********************************************************** * $Id$/*from w w w .j ava2 s. c om*/ * * PKCS#15 cryptographic provider of the opensc project. * http://www.opensc-project.org * * Licensed 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. * * Created: 01.01.2008 * ***********************************************************/ import java.math.BigInteger; public class Main { private static BigInteger MIN_INT_BIG_INTEGER = BigInteger.valueOf(Integer.MIN_VALUE); private static BigInteger MAX_INT_BIG_INTEGER = BigInteger.valueOf(Integer.MAX_VALUE); /** * Checks, whether a BigInteger my be converted to an integer, * i.e. {@link BigInteger#intValue()} does neither overflow nor underflow. * * @param bi The BigInteger to convert. * @return If <code>bi</code> is in the correct range return <code>true</code>, * otherwise return <code>false</code>. */ public static boolean isIntValue(BigInteger bi) { if (bi.compareTo(MIN_INT_BIG_INTEGER) < 0) return false; if (bi.compareTo(MAX_INT_BIG_INTEGER) > 0) return false; return true; } }