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.GenerateXMLFromPropertiesMojo.java

/**
 * This will update the <repoInstances> element.
 *///  w  w  w  . j a  va 2s.  c  om
private void updateRepoInstances() {
    RepoInstances repoInstances = application.getRepoInstances();

    RvRepoInstance rvRepoInstance = repoInstances.getRvRepoInstance();
    rvRepoInstance.setDiscoveryTimout(BigInteger.valueOf(repoRvDiscoveryTimeout));
    rvRepoInstance.setTimeout(BigInteger.valueOf(repoRvTimeout));
    rvRepoInstance.setDaemon(repoRvDaemon);
    rvRepoInstance.setService(repoRvService);
    rvRepoInstance.setNetwork(repoRvNetwork);
    rvRepoInstance.setRegionalSubject(repoRvRegionalSubject);
    rvRepoInstance.setOperationRetry(BigInteger.valueOf(repoRvOperationRetry));
    rvRepoInstance.setExtraPropertyFile(repoRvExtraPropertyFile);
    rvRepoInstance.setServer(repoRvServer);
    rvRepoInstance.setUser(repoRvUser);
    rvRepoInstance.setPassword(repoRvPassword);

    HttpRepoInstance httpRepoInstance = repoInstances.getHttpRepoInstance();
    httpRepoInstance.setTimeout(BigInteger.valueOf(repoHttpTimeout));
    httpRepoInstance.setUrl(repoHttpUrl);
    httpRepoInstance.setServer(repoHttpServer);
    httpRepoInstance.setUser(repoHttpUser);
    httpRepoInstance.setPassword(repoHttpPassword);
    httpRepoInstance.setExtraPropertyFile(repoHttpExtraPropertyFile);

    LocalRepoInstance localRepoInstance = repoInstances.getLocalRepoInstance();
    EncodingType encoding;
    try {
        encoding = EncodingType.valueOf(repoLocalEncoding);
    } catch (IllegalArgumentException e) {
        encoding = EncodingType.UTF_8;
    }
    localRepoInstance.setEncoding(encoding);

    repoInstances.setRvRepoInstance(rvRepoInstance);
    repoInstances.setHttpRepoInstance(httpRepoInstance);
    repoInstances.setLocalRepoInstance(localRepoInstance);

    RepoType repoType;
    try {
        repoType = RepoType.valueOf(repoSelectInstance.toUpperCase());
    } catch (IllegalArgumentException e) {
        repoType = RepoType.LOCAL;
    }
    repoInstances.setSelected(repoType);
}

From source file:hydrograph.ui.validators.impl.AdditionalParamDBValidationRule.java

/**
 * The Function will compare bigInteger values
 * @param value1//w  w w  .  ja  v  a 2  s.  com
 * @param value2
 * @return
 */
private boolean compareBigIntegerValue(String value1, String value2) {
    if (StringUtils.isNotBlank(value1) && StringUtils.isNotBlank(value2) && validateNumericField(value1)
            && validateNumericField(value2)) {
        BigInteger int1 = BigInteger.valueOf(Long.parseLong(value1));
        BigInteger int2 = BigInteger.valueOf(Long.parseLong(value2));
        if (int1.compareTo(int2) == -1) {
            return false;
        }

    }
    return true;
}

From source file:de.jdellay.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    int provider = Integer.parseInt(sp.getString(Configuration.PREFS_KEY_EXCHANGE_PROVIDER, "0"));
    boolean forceRefresh = sp.getBoolean(Configuration.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false);
    if (forceRefresh)
        sp.edit().putBoolean(Configuration.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false).commit();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        float newCcnBtcConversion = -1;
        if ((ccnBtcConversion == -1 && newCcnBtcConversion == -1) || forceRefresh)
            newCcnBtcConversion = requestCcnBtcConversion(provider);

        if (newCcnBtcConversion != -1)
            ccnBtcConversion = newCcnBtcConversion;

        if (CCNBtcConversion == -1)
            return null;

        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, ccnBtcConversion, userAgent,
                    BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, ccnBtcConversion, userAgent,
                    BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            String providerUrl;//from   ww  w . j av a2  s. c  o  m
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.vircurex.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            float mBTCRate = ccnBtcConversion * 1000;
            String strmBTCRate = String.format(Locale.US, "%.5f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC", new ExchangeRate("mBTC",
                    new BigDecimal(GenericUtils.toNanoCoins(strmBTCRate, 0)).toBigInteger(), providerUrl));
            newExchangeRates.put("CCN",
                    new ExchangeRate("CCN", BigInteger.valueOf(100000000), "priceofccn.com"));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null || ccnBtcConversion == -1)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final ExchangeRate rate = bestExchangeRate(selectionArgs[0]);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}

From source file:com.facebook.infrastructure.service.StorageService.java

public static BigInteger hash(String key) {
    BigInteger h = BigInteger.ZERO;
    char val[] = key.toCharArray();
    for (int i = 0; i < StorageService.maxKeyHashLength_; i++) {
        if (i < val.length)
            h = StorageService.prime_.multiply(h).add(BigInteger.valueOf(val[i]));
        else//from   w ww . ja  v a 2s  . c o m
            h = StorageService.prime_.multiply(h).add(StorageService.prime_);
    }

    return h;
}

From source file:com.projity.server.data.mspdi.ModifiedMSPDIWriter.java

/**
 * This method writes data for a single assignment to an MSPDI file.
 *
 * @param factory//from  w  ww  .j  a  v  a2 s  .com
 *            ObjectFactory instance
 * @param mpx
 *            Resource assignment data
 * @param uid
 *            Unique ID for the new assignment
 * @return New MSPDI assignment instance
 * @throws JAXBException
 *             on xml creation errors
 */
protected Project.AssignmentsType.AssignmentType writeAssignment(ObjectFactory factory, ResourceAssignment mpx,
        int uid) throws JAXBException {
    Project.AssignmentsType.AssignmentType xml = super.writeAssignment(factory, mpx, uid);

    //Microsoft Project does something strange: The unassigned resource has a 0 id for the resource, but assignments use the (short)-1 value.
    if (mpx.getResourceID() == 0)
        xml.setResourceUID(BigInteger.valueOf(EnterpriseResource.UNASSIGNED_ID));

    Assignment projityAssignment = (Assignment) projityAssignmentMap.get(mpx);
    Calendar stop = DateTime.calendarInstance();
    stop.setTimeInMillis(projityAssignment.getStop());
    xml.setStop(stop);
    Calendar resume = DateTime.calendarInstance();
    resume.setTimeInMillis(projityAssignment.getResume());
    xml.setResume(resume);
    writeAssigmentBaselinesAndTimephased(factory, xml, mpx, uid);

    return (xml);
}

From source file:fr.acxio.tools.agia.cmis.CmisWriter.java

private ContentStream createStreamForNode(Document sDocument) throws IOException {
    ContentStream aResult = null;//w w w .  j a  v  a 2s.  co m
    if ((sDocument.getContentPath() != null) && (sDocument.getContentPath().length() > 0)) {
        File aFile = new File(sDocument.getContentPath());
        if (aFile.exists() && aFile.isFile()) {
            FileInputStream aInputStream = new FileInputStream(aFile);
            aResult = new ContentStreamImpl(aFile.getName(), BigInteger.valueOf(aFile.length()),
                    sDocument.getMimeType(), aInputStream);
        } else {
            throw new IOException("Cannot find content file: " + sDocument.getContentPath());
        }
    }
    return aResult;
}

From source file:org.teavm.flavour.json.test.SerializerTest.java

@Test
public void serializesBuiltInTypes() {
    BuiltInTypes o = new BuiltInTypes();
    o.boolField = true;/*  ww  w  .j  a  va 2  s. co  m*/
    o.byteField = 1;
    o.charField = '0';
    o.shortField = 2;
    o.intField = 3;
    o.longField = 4L;
    o.floatField = 5F;
    o.doubleField = 6.0;
    o.bigIntField = BigInteger.valueOf(7);
    o.bigDecimalField = BigDecimal.valueOf(8);
    o.list = Arrays.<Object>asList("foo", 1);
    o.map = new HashMap<>();
    o.map.put("key1", "value");
    o.map.put("key2", 23);
    o.set = new HashSet<>(Arrays.<Object>asList("bar", 2));

    JsonNode node = JSONRunner.serialize(o);

    assertEquals(true, node.get("boolField").asBoolean());
    assertEquals(1, node.get("byteField").asInt());
    assertEquals("0", node.get("charField").asText());
    assertEquals(2, node.get("shortField").asInt());
    assertEquals(3, node.get("intField").asInt());
    assertEquals(4, node.get("longField").asInt());
    assertEquals(5, node.get("floatField").asInt());
    assertEquals(6, node.get("doubleField").asInt());
    assertEquals(7, node.get("bigIntField").asInt());
    assertEquals(8, node.get("bigDecimalField").asInt());
    assertEquals(2, node.get("list").size());
    assertEquals("foo", node.get("list").get(0).textValue());
    assertEquals(1, node.get("list").get(1).intValue());
    assertEquals("value", node.get("map").get("key1").asText());
    assertEquals(23, node.get("map").get("key2").asInt());
    assertEquals(2, node.get("set").size());
}

From source file:org.pgptool.gui.encryption.implpgp.EncryptionServicePgpImpl.java

private static void estimateFullOperationSize(SourceInfo encryptionSourceInfo, Updater progress) {
    if (progress == null) {
        return;/* w ww  .j  av a  2s  .co  m*/
    }
    progress.updateTotalSteps(BigInteger.valueOf(encryptionSourceInfo.getSize()));
}

From source file:NumberUtils.java

/**
 * Converts the given number to a <code>java.math.BigInteger</code>.
 *
 * @param number/*from  ww w . j a  v a2s.c o m*/
 * @return java.math.BigInteger
 * @throws IllegalArgumentException The given number is 'not a number' or infinite.
 */
public static BigInteger toBigInteger(Number number) throws IllegalArgumentException {
    if (number == null || number instanceof BigInteger)
        return (BigInteger) number;
    if (number instanceof BigDecimal)
        return ((BigDecimal) number).toBigInteger();
    if (isDoubleCompatible(number)) {
        if (isNaN(number) || isInfinite(number))
            throw new IllegalArgumentException("Argument must not be NaN or infinite.");
        return new BigDecimal(number.toString()).toBigInteger();
    } // => isLongCompatible(number) or unknown Number type
    return BigInteger.valueOf(number.longValue());
}

From source file:com.cloud.hypervisor.ovm3.resources.helpers.Ovm3HypervisorSupport.java

/**
 * fillHostInfo: Startup the routing for the host.
 *
 * @param cmd/*from w  w w  . j a v  a2s .  c  o  m*/
 */
public void fillHostInfo(StartupRoutingCommand cmd) {
    try {
        /* get data we need from parts */
        Linux host = new Linux(c);
        if (!host.getOvmVersion().startsWith("3.2.") && !host.getOvmVersion().startsWith("3.3.")) {
            LOGGER.error("Hypervisor not supported: " + host.getOvmVersion());
            throw new CloudRuntimeException("OVM 3.2. or 3.3. are only supported, not " + host.getOvmVersion());
        } else {
            LOGGER.debug("Hypervisor version: " + host.getOvmVersion());
        }
        cmd.setName(host.getHostName());
        cmd.setSpeed(host.getCpuKhz());
        cmd.setCpus(host.getTotalThreads());
        cmd.setCpuSockets(host.getCpuSockets());
        cmd.setMemory(host.getMemory().longValue());
        BigInteger totalmem = BigInteger.valueOf(host.getMemory().longValue());
        BigInteger freemem = BigInteger.valueOf(host.getFreeMemory().longValue());
        cmd.setDom0MinMemory(totalmem.subtract(freemem).longValue());
        // setPoolSync and setCaps.
        cmd.setGuid(config.getCsHostGuid());
        cmd.setDataCenter(config.getAgentZoneId().toString());
        cmd.setPod(config.getAgentPodId().toString());
        /* TODO: cmd.setOwner(host.getManagerUuid()); */
        cmd.setCluster(config.getAgentClusterId().toString());
        cmd.setHypervisorVersion(host.getOvmVersion());
        cmd.setVersion(host.getAgentVersion());
        cmd.setHypervisorType(HypervisorType.Ovm3);
        cmd.setCaps(host.getCapabilities());
        cmd.setPrivateIpAddress(c.getIp());
        cmd.setStorageIpAddress(c.getIp());
        Network net = new Network(c);
        String defaultBridge = net.getBridgeByIp(c.getIp()).getName();
        if (defaultBridge == null) {
            throw new CloudRuntimeException("Unable to obtain valid bridge with " + c.getIp());
        }

        if (config.getAgentPublicNetworkName() == null) {
            config.setAgentPublicNetworkName(defaultBridge);
        }
        if (config.getAgentPrivateNetworkName() == null) {
            config.setAgentPrivateNetworkName(config.getAgentPublicNetworkName());
        }
        if (config.getAgentGuestNetworkName() == null) {
            config.setAgentGuestNetworkName(config.getAgentPublicNetworkName());
        }
        if (config.getAgentStorageNetworkName() == null) {
            config.setAgentStorageNetworkName(config.getAgentPrivateNetworkName());
        }
        Map<String, String> d = cmd.getHostDetails();
        d.put("public.network.device", config.getAgentPublicNetworkName());
        d.put("private.network.device", config.getAgentPrivateNetworkName());
        d.put("guest.network.device", config.getAgentGuestNetworkName());
        d.put("storage.network.device", config.getAgentStorageNetworkName());
        d.put("ismaster", config.getAgentIsMaster().toString());
        d.put("hasmaster", config.getAgentHasMaster().toString());
        cmd.setHostDetails(d);
        LOGGER.debug("Add an Ovm3 host " + config.getAgentHostname() + ":" + cmd.getHostDetails());
    } catch (Ovm3ResourceException e) {
        throw new CloudRuntimeException("Ovm3ResourceException: " + e.getMessage(), e);
    }
}