Java Code Examples for java.math.BigInteger#ZERO

The following examples show how to use java.math.BigInteger#ZERO . These examples are extracted from open source projects. 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 Project: flink   File: BigIntSerializer.java    License: 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
@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 3
/**
 * 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 4
Source Project: aion_api   File: Contract.java    License: 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 5
Source Project: ghidra   File: ListingModelAdapter.java    License: 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 6
Source Project: nuls-v2   File: NativeAddress.java    License: 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 7
/**
 * 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 8
Source Project: aion   File: ByteUtilExtendTest.java    License: 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 9
/**
 * 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 10
Source Project: coming   File: BigFraction_s.java    License: 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 11
@Override
public BigDecimal getBigDecimal() {
    if (sign == 0) {
        return new BigDecimal(BigInteger.ZERO);
    }
    return new BigDecimal(toString());
}
 
Example 12
Source Project: dble   File: ItemCondOr.java    License: 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 13
Source Project: cassandra-reaper   File: Segment.java    License: 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 14
Source Project: ghidra   File: OpBehaviorIntLess.java    License: 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;
}
 
Example 15
Source Project: aion   File: ContractIntegTest.java    License: 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 16
Source Project: etherjar   File: UIntType.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BigInteger getMinValue() {
    return BigInteger.ZERO;
}
 
Example 17
@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 18
Source Project: ethereumj   File: RLP.java    License: 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 19
Source Project: nuls-v2   File: DeleteContractData.java    License: MIT License 4 votes vote down vote up
@Override
public BigInteger getValue() {
    return BigInteger.ZERO;
}
 
Example 20
Source Project: brooklyn-server   File: BitList.java    License: 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())));
}