Java Code Examples for java.math.BigInteger#ZERO

The following examples show how to use java.math.BigInteger#ZERO . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigIntSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
public static void writeBigInteger(BigInteger record, DataOutputView target) throws IOException {
	// null value support
	if (record == null) {
		target.writeInt(0);
		return;
	}
	// fast paths for 0, 1, 10
	// only reference equality is checked because equals would be too expensive
	else if (record == BigInteger.ZERO) {
		target.writeInt(1);
		return;
	}
	else if (record == BigInteger.ONE) {
		target.writeInt(2);
		return;
	}
	else if (record == BigInteger.TEN) {
		target.writeInt(3);
		return;
	}
	// default
	final byte[] bytes = record.toByteArray();
	// the length we write is offset by four, because null and short-paths for ZERO, ONE, and TEN
	target.writeInt(bytes.length + 4);
	target.write(bytes);
}
 
Example 2
Source File: ListingModelAdapter.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void checkIndex(BigInteger index, AddressSet addressSet) {
	BigInteger indexAfter = getIndexAfter(index);
	if (indexAfter == null) {
		indexAfter = addressToIndexMap.getIndexCount();
	}
	BigInteger indexBefore = getIndexBefore(index.add(BigInteger.ONE));
	if (indexBefore == null) {
		indexBefore = BigInteger.ZERO;
	}
	if (indexAfter.subtract(indexBefore)
			.compareTo(addressToIndexMap.getMiniumUnviewableGapSize()) > 0) {
		Address start = addressToIndexMap.getAddress(indexBefore.add(BigInteger.ONE));
		Address end = addressToIndexMap.getAddress(indexAfter.subtract(BigInteger.ONE));
		if (start != null && end != null &&
			start.getAddressSpace().equals(end.getAddressSpace())) {
			addressSet.add(start, end);
		}
	}
}
 
Example 3
Source File: EmptyNavigableSet.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testSubSetRanges(String description, NavigableSet navigableSet) {
    Object first = isDescending(navigableSet) ? BigInteger.TEN : BigInteger.ZERO;
    Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;

    NavigableSet subSet = navigableSet.subSet(first, true, last, true);

    // same subset
    subSet.subSet(first, true, last, true);

    // slightly smaller
    NavigableSet ns = subSet.subSet(first, false, last, false);
    // slight exapansion
    assertThrows(() -> {
        ns.subSet(first, true, last, true);
    },
        IllegalArgumentException.class,
        description + ": Expansion should not be allowed");

    // much smaller
    subSet.subSet(first, false, BigInteger.ONE, false);
}
 
Example 4
Source File: Statistics.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Getter for total statistics of severity records for patch source.
 *
 * @return total statistics of severity records.
 */
public final String getTotalStatisticsPatch() {
    BigInteger totalSeverityNumber = BigInteger.ZERO;
    for (BigInteger number : severityNumPatch.values()) {
        totalSeverityNumber = totalSeverityNumber.add(number);
    }

    final BigInteger removedNumber;
    if (uniqueMessagesBase > 0) {
        removedNumber = BigInteger.valueOf(uniqueMessagesBase);
    }
    else {
        removedNumber = null;
    }

    final BigInteger addedNumber;
    if (uniqueMessagesPatch > 0) {
        addedNumber = BigInteger.valueOf(uniqueMessagesPatch);
    }
    else {
        addedNumber = null;
    }

    return buildStatisticsString(totalSeverityNumber, removedNumber, addedNumber);
}
 
Example 5
Source File: Contract.java    From aion_api with MIT License 6 votes vote down vote up
private void reset() {
    this.inputParams.clear();
    this.outputParams.clear();
    this.eventsName.clear();

    this.functionName = "";
    this.functionDefined = false;
    this.functionBuilt = false;
    this.eventDefined = false;
    this.abiFunc = null;
    this.isConstant = true;
    this.isConstructor = false;
    this.txNrgLimit = 0L;
    this.txNrgPrice = 0L;
    this.txValue = BigInteger.ZERO;

    nonBlock = false;
    this.errorCode = 1;
}
 
Example 6
Source File: Segment.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
public BigInteger countTokens(BigInteger rangeSize) {
  BigInteger tokens = BigInteger.ZERO;
  for (RingRange tokenRange:tokenRanges) {
    tokens = tokens.add(tokenRange.span(rangeSize));
  }

  return tokens;
}
 
Example 7
Source File: ItemCondOr.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BigInteger valInt() {
    for (Item item : list) {
        if (item.valBool()) {
            nullValue = false;
            return BigInteger.ONE;
        }
        if (item.isNullValue())
            nullValue = true;
    }
    return BigInteger.ZERO;
}
 
Example 8
Source File: DecimalDV.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BigDecimal getBigDecimal() {
    if (sign == 0) {
        return new BigDecimal(BigInteger.ZERO);
    }
    return new BigDecimal(toString());
}
 
Example 9
Source File: BigFraction_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Create a {@link BigFraction} given the numerator and denominator as
 * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms.
 *
 * @param num the numerator, must not be {@code null}.
 * @param den the denominator, must not be {@code null}.
 * @throws ZeroException if the denominator is zero.
 * @throws NullArgumentException if either of the arguments is null
 */
public BigFraction(BigInteger num, BigInteger den) {
    MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR);
    MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR);
    if (BigInteger.ZERO.equals(den)) {
        throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 10
Source File: Statistics.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Getter for total number of severity records for base source.
 *
 * @return total number of severity records.
 */
public final BigInteger getTotalNumBase() {
    BigInteger totalSeverityNumber = BigInteger.ZERO;
    for (BigInteger number : severityNumBase.values()) {
        totalSeverityNumber = totalSeverityNumber.add(number);
    }
    return totalSeverityNumber;
}
 
Example 11
Source File: ByteUtilExtendTest.java    From aion with MIT License 5 votes vote down vote up
@Test
public void testBigIntegerToBytesZero() {
    byte[] expecteds = new byte[] {0x00};
    BigInteger b = BigInteger.ZERO;
    byte[] actuals = ByteUtil.bigIntegerToBytes(b);
    assertArrayEquals(expecteds, actuals);
}
 
Example 12
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a {@link BigFraction} given the numerator and denominator as
 * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms.
 *
 * @param num the numerator, must not be {@code null}.
 * @param den the denominator, must not be {@code null}.
 * @throws ZeroException if the denominator is zero.
 * @throws NullArgumentException if either of the arguments is null
 */
public BigFraction(BigInteger num, BigInteger den) {
    MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR);
    MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR);
    if (BigInteger.ZERO.equals(den)) {
        throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 13
Source File: NativeAddress.java    From nuls-v2 with MIT License 5 votes vote down vote up
private static Result call(MethodCode methodCode, MethodArgs methodArgs, Frame frame, boolean returnResult) {
    ObjectRef addressRef = methodArgs.objectRef;
    ObjectRef methodNameRef = (ObjectRef) methodArgs.invokeArgs[0];
    ObjectRef methodDescRef = (ObjectRef) methodArgs.invokeArgs[1];
    ObjectRef argsRef = (ObjectRef) methodArgs.invokeArgs[2];
    ObjectRef valueRef = (ObjectRef) methodArgs.invokeArgs[3];

    String address = frame.heap.runToString(addressRef);
    String methodName = frame.heap.runToString(methodNameRef);
    String methodDesc = frame.heap.runToString(methodDescRef);
    String[][] args = getArgs(argsRef, frame);
    BigInteger value = frame.heap.toBigInteger(valueRef);
    if (value == null) {
        value = BigInteger.ZERO;
    }

    ProgramResult programResult = call(address, methodName, methodDesc, args, value, frame);

    if (!programResult.isSuccess()) {
        return new Result();
    }

    Object resultValue = null;
    if (returnResult && programResult.isSuccess()) {
        resultValue = frame.heap.newString(programResult.getResult());
    }

    Result result = NativeMethod.result(methodCode, resultValue, frame);
    return result;
}
 
Example 14
Source File: SendingTokensActivity.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
@OnClick(R.id.btn_confirm)
public void onConfirmClick(View view) {
    String amount = etSumSend.getText().toString();
    if (!amount.isEmpty()) {
        if (!isAmountMoreBalance(amount)) {

            BigInteger gasLimit;
            BigInteger value;
            String customData;

            gasLimit = gasLimitForFeeMode;
            value = BigInteger.ZERO;
            customData = getContractTransfer();

            networkManager.sendTransaction(getToAddress(), value, gasPrice, gasLimit, customData,
                    new Callback<RawTransactionResponse>() {
                        @Override
                        public void onResponse(RawTransactionResponse response) {
                            closeProgress();
                            if (response != null) {
                                String hash = response.getHash();
                                String blockNumber = response.getBlockNumber();

                                showCongratsActivity();
                            } else {

                                Toast.makeText(SendingTokensActivity.this,
                                        getString(R.string.transaction_not_sent_fee),
                                        Toast.LENGTH_LONG).show();
                            }

                        }
                    });
            showProgress(getString(R.string.progress_bar_sending_transaction));

        } else {
            showError(etSumSend, getString(R.string.withdraw_amount_more_than_balance));
        }
    } else {
        showError(etSumSend, getString(R.string.withdraw_amount_can_not_be_empty));
    }

}
 
Example 15
Source File: RLP.java    From ethereumj with MIT License 4 votes vote down vote up
public static byte[] encodeBigInteger(BigInteger srcBigInteger) {
	if(srcBigInteger == BigInteger.ZERO) 
		return encodeByte((byte)0);
	else 
		return encodeElement(asUnsignedByteArray(srcBigInteger));
}
 
Example 16
Source File: UIntType.java    From etherjar with Apache License 2.0 4 votes vote down vote up
@Override
public BigInteger getMinValue() {
    return BigInteger.ZERO;
}
 
Example 17
Source File: ContractIntegTest.java    From aion with MIT License 4 votes vote down vote up
@Test
public void tellFvmContractCallWithinDeployingBlock() throws IOException {
    if (txType == TransactionTypes.AVM_CREATE_CODE) {
        return;
    }

    String contractName = "InternalCallContract";
    byte[] deployCode = getDeployCode(contractName);
    long nrg = Constants.NRG_TRANSACTION_MAX;
    long nrgPrice = energyPrice;
    BigInteger value = BigInteger.ZERO;
    BigInteger nonce = BigInteger.ZERO;
    AionTransaction tx =
            AionTransaction.create(
                    deployerKey,
                    nonce.toByteArray(),
                    null,
                    value.toByteArray(),
                    deployCode,
                    nrg,
                    nrgPrice,
                    txType, null);
    RepositoryCache repo = blockchain.getRepository().startTracking();
    nonce = nonce.add(BigInteger.ONE);

    assertTrue(tx.isContractCreationTransaction());

    assertEquals(deployerBalance, repo.getBalance(deployer));
    assertEquals(deployerNonce, repo.getNonce(deployer));

    List<AionTransaction> ls = new ArrayList<>();
    ls.add(tx);

    byte[] input =
            Arrays.copyOfRange(HashUtil.keccak256("sendValueToContract()".getBytes()), 0, 4);
    AionTransaction tx2 =
            AionTransaction.create(
                    deployerKey,
                    nonce.toByteArray(),
                    TxUtil.calculateContractAddress(tx),
                    BigInteger.TEN.toByteArray(),
                    input,
                    nrg,
                    nrgPrice,
                    txType, null);
    assertFalse(tx2.isContractCreationTransaction());
    ls.add(tx2);

    BigInteger senderBalance = repo.getBalance(deployer);

    Block parent = blockchain.getBestBlock();
    MiningBlock block = blockchain.createBlock(parent, ls, false, parent.getTimestamp());

    Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(block);
    AionBlockSummary summary = result.getRight();
    assertTrue(result.getLeft().isSuccessful());

    AionAddress contractAddress = TxUtil.calculateContractAddress(tx);
    assertEquals(BigInteger.TEN, blockchain.getRepository().getBalance(contractAddress));
    assertEquals(
            senderBalance
                    .subtract(BigInteger.TEN)
                    .subtract(
                            BigInteger.valueOf(summary.getReceipts().get(0).getEnergyUsed())
                                    .multiply(BigInteger.valueOf(nrgPrice)))
                    .subtract(
                            BigInteger.valueOf(summary.getReceipts().get(1).getEnergyUsed())
                                    .multiply(BigInteger.valueOf(nrgPrice))),
            blockchain.getRepository().getBalance(deployer));

    repo = blockchain.getRepository().startTracking();
    assertEquals(BigInteger.TWO, repo.getNonce(deployer));
}
 
Example 18
Source File: DeleteContractData.java    From nuls-v2 with MIT License 4 votes vote down vote up
@Override
public BigInteger getValue() {
    return BigInteger.ZERO;
}
 
Example 19
Source File: BitList.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public BigInteger asBigInteger() {
    if (length==0) return BigInteger.ZERO;
    return new BigInteger(Bytes.toArray(Lists.reverse(asByteList())));
}
 
Example 20
Source File: OpBehaviorIntLess.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public BigInteger evaluateBinary(int sizeout, int sizein, BigInteger in1, BigInteger in2) {
	BigInteger res = (in1.compareTo(in2) < 0) ? BigInteger.ONE : BigInteger.ZERO;
	return res;
}