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:fr.fastconnect.factory.tibco.bw.maven.packaging.ApplicationManagement.java

/**
 * /application/services/bw/*//from  w ww  .  j  av a2s. c o  m
 */
private Object addBwParameter(Bw bw, String key, String value) {
    if ("enabled".equals(key)) {
        bw.setEnabled(Boolean.parseBoolean(value));
    } else if ("failureCount".equals(key)) {
        bw.setFailureCount(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("failureInterval".equals(key)) {
        bw.setFailureInterval(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("isFt".equals(key)) {
        setIsFt(bw, Boolean.parseBoolean(value));
    } else if ("faultTolerant".equals(key)) {
        return getBWFaultTolerant(bw);
    }
    return bw;
}

From source file:com.chinamobile.bcbsp.util.Bytes.java

/**
 * Split passed range. Expensive operation relatively. Uses BigInteger math.
 * Useful splitting ranges for MapReduce jobs.
 *
 * @param a/* w  ww  . j ava2  s. c  o  m*/
 *        Beginning of range
 * @param b
 *        End of range
 * @param num
 *        Number of times to split range. Pass 1 if you want to split the
 *        range in two; i.e. one split.
 * @return Array of dividing values
 */
public static byte[][] split(final byte[] a, final byte[] b, final int num) {
    byte[] aPadded;
    byte[] bPadded;
    if (a.length < b.length) {
        aPadded = padTail(a, b.length - a.length);
        bPadded = b;
    } else if (b.length < a.length) {
        aPadded = a;
        bPadded = padTail(b, a.length - b.length);
    } else {
        aPadded = a;
        bPadded = b;
    }
    if (compareTo(aPadded, bPadded) >= 0) {
        throw new IllegalArgumentException("b <= a");
    }
    if (num <= 0) {
        throw new IllegalArgumentException("num cannot be < 0");
    }
    byte[] prependHeader = { 1, 0 };
    BigInteger startBI = new BigInteger(add(prependHeader, aPadded));
    BigInteger stopBI = new BigInteger(add(prependHeader, bPadded));
    BigInteger diffBI = stopBI.subtract(startBI);
    BigInteger splitsBI = BigInteger.valueOf(num + 1);
    if (diffBI.compareTo(splitsBI) < 0) {
        return null;
    }
    BigInteger intervalBI;
    try {
        intervalBI = diffBI.divide(splitsBI);
    } catch (Exception e) {
        LOG.error("Exception caught during division", e);
        return null;
    }
    byte[][] result = new byte[num + 2][];
    result[0] = a;
    for (int i = 1; i <= num; i++) {
        BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
        byte[] padded = curBI.toByteArray();
        if (padded[1] == 0) {
            padded = tail(padded, padded.length - 2);
        } else {
            padded = tail(padded, padded.length - 1);
        }
        result[i] = padded;
    }
    result[num + 1] = b;
    return result;
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.ApplicationManagement.java

/**
 * /application/services/adapter/*/*  ww w.  j  ava 2s  .c  o  m*/
 */
private Object addAdapterParameter(Adapter adapter, String key, String value) {
    if ("enabled".equals(key)) {
        adapter.setEnabled(Boolean.parseBoolean(value));
    } else if ("failureCount".equals(key)) {
        adapter.setFailureCount(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("failureInterval".equals(key)) {
        adapter.setFailureInterval(BigInteger.valueOf(Long.parseLong(value)));
    }
    return adapter;
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

/**
 * @see com.sun.honeycomb.adm.client.AdminClient#enableDisk(HCDisk)
 *//*from  ww  w  . j  a  v  a  2 s  . co  m*/
public int enableDisk(HCDisk disk) throws MgmtException, ConnectException, PermissionException {

    if (!loggedIn())
        throw new PermissionException();
    if (null == disk)
        throw new MgmtException("Attempted to enable nonexistent disk.");

    Object[] params = { Long.toString(this._sessionId), disk.getDiskId(), disk.getNodeId().toString() };

    this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_ENABLE_DISK, params, "enableDisk");

    BigInteger result = disk.enable(new StatusCallback(), BigInteger.valueOf(0));
    return result.intValue();
}

From source file:com.sourcesense.opencmis.server.HstCmisRepository.java

private void addPropertyInteger(PropertiesImpl props, String typeId, Set<String> filter, String id,
        long value) {
    if (!checkAddProperty(props, typeId, filter, id)) {
        return;/*from   ww w  . ja va  2 s  . c  o  m*/
    }

    props.addProperty(new PropertyIntegerImpl(id, BigInteger.valueOf(value)));
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

/**
 * @see com.sun.honeycomb.adm.client.AdminClient#disableDisk(HCDisk)
 *///from  ww  w.  j a  v a2  s .co  m
public int disableDisk(HCDisk disk) throws MgmtException, ConnectException, PermissionException {

    if (!loggedIn())
        throw new PermissionException();
    if (null == disk)
        throw new MgmtException("Attempted to disable nonexistent disk.");

    Object[] params = { Long.toString(this._sessionId), disk.getDiskId(), disk.getNodeId().toString() };
    this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_DISABLE_DISK, params, "disableDisk");

    BigInteger result = disk.disable(new StatusCallback(), BigInteger.valueOf(0));
    return result.intValue();
}

From source file:com.bonsai.wallet32.WalletService.java

public void sweepKey(ECKey key, long fee, int accountId, JSONArray outputs) {
    mLogger.info("sweepKey starting");

    mLogger.info("key addr " + key.toAddress(mParams).toString());

    Transaction tx = new Transaction(mParams);

    long balance = 0;
    ArrayList<Script> scripts = new ArrayList<Script>();
    try {/*from  w  w w. jav  a2  s. c om*/
        for (int ii = 0; ii < outputs.length(); ++ii) {
            JSONObject output;
            output = outputs.getJSONObject(ii);

            String tx_hash = output.getString("tx_hash");
            int tx_output_n = output.getInt("tx_ouput_n"); //this typo is necessary for Groestlcoin
            String script = output.getString("script");

            // Reverse byte order, create hash.
            Sha256Hash hash = new Sha256Hash(/*WalletUtil.msgHexToBytes(*/tx_hash/*)*/);

            tx.addInput(new TransactionInput(mParams, tx, new byte[] {},
                    new TransactionOutPoint(mParams, tx_output_n, hash)));

            scripts.add(new Script(Hex.decode(script)));

            balance += output.getLong("value");
        }
    } catch (JSONException e) {
        e.printStackTrace();
        throw new RuntimeException("trouble parsing unspent outputs");
    }

    // Compute balance - fee.
    long amount = balance - fee;
    mLogger.info(String.format("sweeping %d", amount));

    // Figure out the destination address.
    Address to = mHDWallet.nextReceiveAddress(accountId);
    mLogger.info("sweeping to " + to.toString());

    // Add output.
    tx.addOutput(BigInteger.valueOf(amount), to);

    WalletUtil.signTransactionInputs(tx, Transaction.SigHash.ALL, key, scripts);

    mLogger.info("tx bytes: " + new String(Hex.encode(tx.bitcoinSerialize())));
    // mKit.peerGroup().broadcastTransaction(tx);
    broadcastTransaction(mKit.peerGroup(), tx);

    mLogger.info("sweepKey finished");
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

/**
 * @see com.sun.honeycomb.adm.client.AdminClient#onlineDisk(HCDisk)
 *///from w  w  w . j  a  va 2  s.c  om
public int onlineDisk(HCDisk disk) throws MgmtException, ConnectException, PermissionException {

    if (!loggedIn())
        throw new PermissionException();
    if (null == disk)
        throw new MgmtException("Attempted to online nonexistent disk.");

    Object[] params = { Long.toString(this._sessionId), disk.getDiskId(), disk.getNodeId().toString() };
    this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_ONLINE_DISK, params, "onlineDisk");

    BigInteger result = disk.online(new StatusCallback(), BigInteger.valueOf(0));
    return result.intValue();
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

/**
 * @see com.sun.honeycomb.adm.client.AdminClient#offlineDisk(HCDisk)
 *//*from  ww  w  .  j  ava2  s  .  com*/
public int offlineDisk(HCDisk disk) throws MgmtException, ConnectException, PermissionException {

    if (!loggedIn())
        throw new PermissionException();
    if (null == disk)
        throw new MgmtException("Attempted to offline nonexistent disk.");

    Object[] params = { Long.toString(this._sessionId), disk.getDiskId(), disk.getNodeId().toString() };
    this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_OFFLINE_DISK, params, "offlineDisk");

    BigInteger result = disk.offline(BigInteger.valueOf(0));
    return result.intValue();
}