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.pms.util.Rational.java

/**
 * Returns a {@link Rational} whose value is {@code (this + value)}.
 *
 * @param value the value to be added to this {@link Rational}.
 * @return The addition result./* w  ww  .j a  v a2 s  . c o  m*/
 */
@Nonnull
public Rational add(long value) {
    return add(BigInteger.valueOf(value));
}

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

/**
 * /application/services/bw/bindings/binding/*
 *///from   w ww .j a  v a  2s . c  o m
private Object addBindingParameter(Binding binding, String key, String value) {
    if ("machine".equals(key)) {
        binding.setMachine(value);
    } else if ("product".equals(key)) {
        if (binding.getProduct() == null) {
            binding.setProduct(new Product());
        }
        return binding.getProduct();
    } else if ("container".equals(key)) {
        binding.setContainer(value);
    } else if ("description".equals(key)) {
        binding.setDescription(value);
    } else if ("contact".equals(key)) {
        binding.setContact(value);
    } else if ("setting".equals(key)) {
        if (binding.getSetting() == null) {
            binding.setSetting(new Setting());
        }
        return binding.getSetting();
    } else if ("ftWeight".equals(key)) {
        binding.setFtWeight(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("shutdown".equals(key)) {
        if (binding.getShutdown() == null) {
            binding.setShutdown(new Shutdown());
        }
        return binding.getShutdown();
    }

    return binding;
}

From source file:com.ephesoft.gxt.rv.server.ReviewValidateServiceImpl.java

private List<Span> getSortedList(final List<Span> spanList) {
    final Set<Span> set = new TreeSet<Span>(new Comparator<Span>() {

        public int compare(final Span firstSpan, final Span secSpan) {
            BigInteger s1Y0 = firstSpan.getCoordinates().getY0();
            BigInteger s1Y1 = firstSpan.getCoordinates().getY1();
            final BigInteger s2Y0 = secSpan.getCoordinates().getY0();
            final BigInteger s2Y1 = secSpan.getCoordinates().getY1();
            final int halfOfSecSpan = (s2Y1.intValue() - s2Y0.intValue()) / 2;
            final int y1 = s2Y1.intValue() + halfOfSecSpan;
            final int y0 = s2Y0.intValue() - halfOfSecSpan;

            // following if else code is to handle abnormal(out of synch) value y0 or y1 coordinate of new span.
            if (isApproxEqual(s1Y0.intValue(), s2Y0.intValue()) && s1Y1.intValue() > y1) {
                s1Y1 = BigInteger.valueOf(y1);
                firstSpan.getCoordinates().setY1(s1Y1);
            } else if (isApproxEqual(s1Y1.intValue(), s2Y1.intValue()) && s1Y0.intValue() < y0) {
                s1Y0 = BigInteger.valueOf(y0);
                firstSpan.getCoordinates().setY0(s1Y0);
            }//from  w ww  .  j  a  v  a2 s.c o  m
            final BigInteger s1Y = s1Y1.add(s1Y0);
            final BigInteger s2Y = s2Y1.add(s2Y0);

            // calculating middle of old span.
            final int oldSpanMid = s2Y.intValue() / 2;
            int returnValue = 0;

            // if old span's y coordinate's middle lies within range of new span's y coordinates or not. if true, the two spans
            // belong to same line compare them further on their x coordinates, else they belong to two different lines.
            if (oldSpanMid >= s1Y0.intValue() && oldSpanMid <= s1Y1.intValue()) {
                final BigInteger s1X1 = firstSpan.getCoordinates().getX1();
                final BigInteger s2X1 = secSpan.getCoordinates().getX1();
                returnValue = s1X1.compareTo(s2X1);
            } else {
                returnValue = s1Y.compareTo(s2Y);
            }
            return returnValue;
        }
    });
    set.addAll(spanList);
    final List<Span> spanSortedList = new LinkedList<Span>();
    spanSortedList.addAll(set);

    // TODO add the clear method to remove all elements of set since it not
    // required after adding it to linked list.
    // set.clear();

    return spanSortedList;

}

From source file:com.healthmarketscience.jackcess.Column.java

/**
 * Decodes "Currency" values./*from  w w  w .j  a  va 2 s  .  co  m*/
 * 
 * @param buffer Column value that points to currency data
 * @return BigDecimal representing the monetary value
 * @throws IOException if the value cannot be parsed 
 */
private static BigDecimal readCurrencyValue(ByteBuffer buffer) throws IOException {
    if (buffer.remaining() != 8) {
        throw new IOException("Invalid money value.");
    }

    return new BigDecimal(BigInteger.valueOf(buffer.getLong(0)), 4);
}

From source file:jp.aegif.nemaki.cmis.aspect.impl.CompileServiceImpl.java

private List<RenditionData> compileRenditions(CallContext callContext, String repositoryId, Content content) {
    List<RenditionData> renditions = new ArrayList<RenditionData>();

    List<Rendition> _renditions = contentService.getRenditions(repositoryId, content.getId());
    if (CollectionUtils.isNotEmpty(_renditions)) {
        for (Rendition _rd : _renditions) {
            RenditionDataImpl rd = new RenditionDataImpl();
            rd.setStreamId(_rd.getId());
            rd.setMimeType(_rd.getMimetype());
            rd.setBigLength(BigInteger.valueOf(_rd.getLength()));
            rd.setKind(_rd.getKind());// ww  w  .  j  a  v  a 2s  .co  m
            rd.setTitle(_rd.getTitle());
            rd.setBigHeight(BigInteger.valueOf(_rd.getHeight()));
            rd.setBigWidth(BigInteger.valueOf(_rd.getWidth()));
            rd.setRenditionDocumentId(_rd.getRenditionDocumentId());

            renditions.add(rd);
        }
    }

    return renditions;
}

From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java

public void reportCapabilities(int in) {
    BigInteger bigInt = BigInteger.valueOf(in);
    if (bigInt.testBit(0)) {
        mBrowsable = true;//from   ww w.  j av a 2  s. c  o  m
        collection();
    }
    if (bigInt.testBit(1)) {
        mPlaylistSync = true;
    }
    if (bigInt.testBit(2)) {
        mAccountFactory = true;
    }
    if (bigInt.testBit(3)) {
        mUrlLookup = true;
    }
    if (bigInt.testBit(4)) {
        mConfigTestable = true;
    }
}

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

/**
 * /application/services/bw/bindings/binding/setting/*
 *//*from  www  .  ja va  2 s .  c om*/
private Object addSettingParameter(Setting setting, String key, String value) {
    if ("startOnBoot".equals(key)) {
        setting.setStartOnBoot(Boolean.parseBoolean(value));
    } else if ("enableVerbose".equals(key)) {
        setting.setEnableVerbose(Boolean.parseBoolean(value));
    } else if ("maxLogFileSize".equals(key)) {
        setting.setMaxLogFileSize(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("maxLogFileCount".equals(key)) {
        setting.setMaxLogFileCount(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("threadCount".equals(key)) {
        setting.setThreadCount(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("NTService".equals(key)) {
        if (setting.getNTService() == null) {
            setting.setNTService(new NTService());
        }
        return setting.getNTService();
    } else if ("java".equals(key)) {
        if (setting.getJava() == null) {
            setting.setJava(new Java());
        }
        return setting.getJava();
    }
    return setting;
}

From source file:com.clustercontrol.performance.operator.Operator.java

/**
 * ???????pollingTarget???????//from w ww.  j  a va2  s  .co m
 * @throws CollectedDataNotFoundException 
 */
private double getMibValueDiff(CollectorPollingMstData data, DataTable currentTable, DataTable previousTable,
        String currentEntryKey, String previousEntryKey) throws CollectedDataNotFoundException {

    // return?
    double ret = 0;

    // ????
    long previousValue = getMibValueLong(previousTable, data, previousEntryKey);

    // ???
    long currentValue = getMibValueLong(currentTable, data, currentEntryKey);

    // long??
    long diff = currentValue - previousValue;

    // ????
    if (diff >= 0) {
        ret = diff;

        // ?????double???
    } else {

        // ??Counter32???????????
        if ("Counter32".equals(data.getValueType()) || "Uint32".equals(data.getValueType())) {
            diff = COUNTER32_MAX_VALUE + 1 + diff;
            ret = convLongToDouble(diff);

            // ??Counter64???????????
        } else if ("Counter64".equals(data.getValueType()) || "Uint64".equals(data.getValueType())) {
            ret = COUTNER64_MAX_VALUE.add(BigInteger.valueOf(diff + 1)).doubleValue();

        }
    }

    return ret;
}

From source file:com.bonsai.btcreceive.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 {//  ww  w .j  a v  a 2s  . c  o m
        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_output_n");
            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 = mHDReceiver.nextReceiveAddress();
    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:fr.fastconnect.factory.tibco.bw.maven.packaging.ApplicationManagement.java

/**
 * /application/services/bw/bindings/binding/setting/java/*
 *///from   w w  w. ja  va  2 s .c  o  m
private Object addJavaParameter(Java java, String key, String value) {
    if ("prepandClassPath".equals(key)) {
        java.setPrepandClassPath(value);
    } else if ("appendClassPath".equals(key)) {
        java.setAppendClassPath(value);
    } else if ("initHeapSize".equals(key)) {
        java.setInitHeapSize(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("maxHeapSize".equals(key)) {
        java.setMaxHeapSize(BigInteger.valueOf(Long.parseLong(value)));
    } else if ("threadStackSize".equals(key)) {
        java.setThreadStackSize(BigInteger.valueOf(Long.parseLong(value)));
    }

    return java;
}