Example usage for java.math BigInteger valueOf

List of usage examples for java.math BigInteger valueOf

Introduction

In this page you can find the example usage for java.math BigInteger valueOf.

Prototype

private static BigInteger valueOf(int val[]) 

Source Link

Document

Returns a BigInteger with the given two's complement representation.

Usage

From source file:net.ripe.ipresource.IpRange.java

private boolean canBeDividedByThePowerOfTwo(BigInteger number, int power) {
    return number.remainder(BigInteger.valueOf(2).pow(power)).equals(BigInteger.ZERO);
}

From source file:net.ripe.ipresource.Ipv4Address.java

@Override
public final BigInteger getValue() {
    return BigInteger.valueOf(value());
}

From source file:co.rsk.peg.BridgeState.java

public byte[] getEncoded() throws IOException {
    byte[] rlpBtcBlockchainBestChainHeight = RLP
            .encodeBigInteger(BigInteger.valueOf(this.btcBlockchainBestChainHeight));
    byte[] rlpBtcTxHashesAlreadyProcessed = RLP
            .encodeElement(BridgeSerializationUtils.serializeSet(btcTxHashesAlreadyProcessed));
    byte[] rlpBtcUTXOs = RLP.encodeElement(BridgeSerializationUtils.serializeList(btcUTXOs));
    byte[] rlpRskTxsWaitingForBroadcasting = RLP
            .encodeElement(BridgeSerializationUtils.serializePairMap(rskTxsWaitingForBroadcasting));
    byte[] rlpRskTxsWaitingForConfirmations = RLP
            .encodeElement(BridgeSerializationUtils.serializeMap(rskTxsWaitingForConfirmations));
    byte[] rlpRskTxsWaitingForSignatures = RLP
            .encodeElement(BridgeSerializationUtils.serializeMap(rskTxsWaitingForSignatures));

    return RLP.encodeList(rlpBtcBlockchainBestChainHeight, rlpBtcTxHashesAlreadyProcessed, rlpBtcUTXOs,
            rlpRskTxsWaitingForBroadcasting, rlpRskTxsWaitingForConfirmations, rlpRskTxsWaitingForSignatures);
}

From source file:libra.preprocess.common.kmerhistogram.KmerRangePartitioner.java

public KmerRangePartition[] getEqualRangePartitions() {
    KmerRangePartition[] partitions = new KmerRangePartition[this.numPartitions];

    // calc 4^kmerSize
    BigInteger kmerend = BigInteger.valueOf(4).pow(this.kmerSize);

    BigInteger slice_width = kmerend.divide(BigInteger.valueOf(this.numPartitions));
    if (kmerend.mod(BigInteger.valueOf(this.numPartitions)).intValue() != 0) {
        slice_width = slice_width.add(BigInteger.ONE);
    }/*from w  w  w  . j av  a  2  s .c om*/

    for (int i = 0; i < this.numPartitions; i++) {
        BigInteger slice_begin = slice_width.multiply(BigInteger.valueOf(i));
        if (slice_begin.add(slice_width).compareTo(kmerend) > 0) {
            slice_width = kmerend.subtract(slice_begin);
        }

        BigInteger slice_end = slice_begin.add(slice_width).subtract(BigInteger.ONE);

        KmerRangePartition slice = new KmerRangePartition(this.kmerSize, this.numPartitions, i, slice_width,
                slice_begin, slice_end);
        partitions[i] = slice;
    }

    return partitions;
}

From source file:com.base.dao.sql.ReflectionUtils.java

public static BigInteger bigIntValue(Object value) throws NumberFormatException {
    if (value == null)
        return BigInteger.valueOf(0L);
    Class c = value.getClass();// w  ww  . jav  a2s  .com
    if (c == BigInteger.class)
        return (BigInteger) value;
    if (c == BigDecimal.class)
        return ((BigDecimal) value).toBigInteger();
    if (c.getSuperclass() == Number.class)
        return BigInteger.valueOf(((Number) value).longValue());
    if (c == Boolean.class)
        return BigInteger.valueOf(((Boolean) value).booleanValue() ? 1 : 0);
    if (c == Character.class)
        return BigInteger.valueOf(((Character) value).charValue());
    return new BigInteger(stringValue(value, true));
}

From source file:com.coinprism.model.APIClient.java

/**
 * Gets the list of recent transactions for a given address.
 *
 * @param address the address for which to query the recent transactions
 * @return a list of transactions/* ww  w .  jav a  2 s  .c o  m*/
 */
public List<SingleAssetTransaction> getTransactions(String address)
        throws IOException, JSONException, ParseException, APIException {
    String json = executeHttpGet(this.baseUrl + "/v1/addresses/" + address + "/transactions");

    JSONArray transactions = new JSONArray(json);

    ArrayList<SingleAssetTransaction> assetBalances = new ArrayList<SingleAssetTransaction>();

    for (int i = 0; i < transactions.length(); i++) {
        JSONObject transactionObject = (JSONObject) transactions.get(i);
        String transactionId = transactionObject.getString("hash");

        Date date = null;
        if (!transactionObject.isNull("block_time"))
            date = parseDate(transactionObject.getString("block_time"));

        HashMap<String, BigInteger> quantities = new HashMap<String, BigInteger>();
        BigInteger satoshiDelta = BigInteger.ZERO;

        JSONArray inputs = transactionObject.getJSONArray("inputs");
        for (int j = 0; j < inputs.length(); j++) {
            JSONObject input = (JSONObject) inputs.get(j);
            if (isAddress(input, address)) {
                if (!input.isNull("asset_id"))
                    addQuantity(quantities, input.getString("asset_id"),
                            new BigInteger(input.getString("asset_quantity")).negate());

                satoshiDelta = satoshiDelta.subtract(BigInteger.valueOf(input.getLong("value")));
            }
        }

        JSONArray outputs = transactionObject.getJSONArray("outputs");
        for (int j = 0; j < outputs.length(); j++) {
            JSONObject output = (JSONObject) outputs.get(j);
            if (isAddress(output, address)) {
                if (!output.isNull("asset_id"))
                    addQuantity(quantities, output.getString("asset_id"),
                            new BigInteger(output.getString("asset_quantity")));

                satoshiDelta = satoshiDelta.add(BigInteger.valueOf(output.getLong("value")));
            }
        }

        if (!satoshiDelta.equals(BigInteger.ZERO))
            assetBalances.add(new SingleAssetTransaction(transactionId, date, null, satoshiDelta));

        for (String key : quantities.keySet()) {
            assetBalances.add(new SingleAssetTransaction(transactionId, date, getAssetDefinition(key),
                    quantities.get(key)));
        }
    }

    return assetBalances;
}

From source file:com.adobe.acs.commons.adobeio.service.impl.IntegrationServiceImpl.java

protected static byte[] buildPkcs8Key(String privateKey) {
    if (privateKey.contains("--BEGIN PRIVATE KEY--")) {
        return DECODER.decode(privateKey.replaceAll("-----\\w+ PRIVATE KEY-----", ""));
    }//from w ww  .  j  a  v  a2  s.c  om
    if (!privateKey.contains("--BEGIN RSA PRIVATE KEY--")) {
        LOGGER.error("Invalid cert format: {}", privateKey);
        return StringUtils.EMPTY.getBytes();
    }

    final byte[] innerKey = DECODER.decode(privateKey.replaceAll("-----\\w+ RSA PRIVATE KEY-----", ""));
    final byte[] result = new byte[innerKey.length + 26];
    System.arraycopy(DECODER.decode("MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKY="), 0, result, 0, 26);
    System.arraycopy(BigInteger.valueOf(result.length - 4).toByteArray(), 0, result, 2, 2);
    System.arraycopy(BigInteger.valueOf(innerKey.length).toByteArray(), 0, result, 24, 2);
    System.arraycopy(innerKey, 0, result, 26, innerKey.length);
    return result;
}

From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java

public BigInteger getNumNodes() {
    return BigInteger.valueOf(numNodes);
}

From source file:com.netflix.imfutility.cpl._2016.Cpl2016ContextBuilderStrategy.java

@Override
public BigFraction getCompositionTimecodeRate() {
    if (cpl2016.getCompositionTimecode() == null) {
        return null;
    }/*from   w w w.  j  av a  2s.  c  om*/
    BigInteger rate = cpl2016.getCompositionTimecode().getTimecodeRate();
    boolean isDropFrame = cpl2016.getCompositionTimecode().isTimecodeDropFrame();
    if (rate == null || BigInteger.ZERO.equals(rate)) {
        return null;
    }

    // return as-is if non-drop
    if (!isDropFrame) {
        return new BigFraction(rate);
    }

    // return as 30000/1001 for 30 if drop frame
    return new BigFraction(rate.multiply(BigInteger.valueOf(1000)), BigInteger.valueOf(1001));
}