Example usage for java.math BigInteger add

List of usage examples for java.math BigInteger add

Introduction

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

Prototype

BigInteger add(long val) 

Source Link

Document

Package private methods used by BigDecimal code to add a BigInteger with a long.

Usage

From source file:com.mothsoft.alexis.engine.numeric.TopicActivityDataSetImporter.java

private void importTopicDataForUser(final Long userId, final Date startDate, final Date endDate) {
    logger.debug(String.format("Importing topic activity for user: %d between %s and %s", userId,
            startDate.toString(), endDate.toString()));

    final List<Long> topicIds = this.transactionTemplate.execute(new TransactionCallback<List<Long>>() {
        @SuppressWarnings("unchecked")
        @Override/*from w  w w  . j  a v a2s.c  om*/
        public List<Long> doInTransaction(TransactionStatus txStatus) {
            final Query query = TopicActivityDataSetImporter.this.em
                    .createQuery("SELECT id FROM Topic WHERE userId = :userId ORDER BY id ASC");
            query.setParameter("userId", userId);
            return query.getResultList();
        }
    });

    BigInteger total = BigInteger.ZERO;

    for (final Long topicId : topicIds) {
        BigInteger count = importTopicDataForTopic(topicId, startDate, endDate);
        total = total.add(count);
    }

    recordAggregateTopicActivity(userId, startDate, total);

}

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  ww w .j av  a2  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.kinesis.datavis.utils.StreamUtils.java

/**
 * Split a shard by dividing the hash key space in half.
 *
 * @param streamName Name of the stream that contains the shard to split.
 * @param shardId The id of the shard to split.
 *
 * @throws IllegalArgumentException When either streamName or shardId are null or empty.
 * @throws LimitExceededException Shard limit for the account has been reached.
 * @throws ResourceNotFoundException The stream or shard cannot be found.
 * @throws InvalidArgumentException If the shard is closed and no eligible for splitting.
 * @throws AmazonClientException Error communicating with Amazon Kinesis.
 *
 *//* w w  w  . ja  v  a 2s  .  c om*/
public void splitShardEvenly(String streamName, String shardId) throws LimitExceededException,
        ResourceNotFoundException, AmazonClientException, InvalidArgumentException, IllegalArgumentException {
    if (streamName == null || streamName.isEmpty()) {
        throw new IllegalArgumentException("stream name is required");
    }
    if (shardId == null || shardId.isEmpty()) {
        throw new IllegalArgumentException("shard id is required");
    }

    DescribeStreamResult result = kinesis.describeStream(streamName);
    StreamDescription description = result.getStreamDescription();

    // Find the shard we want to split
    Shard shardToSplit = null;
    for (Shard shard : description.getShards()) {
        if (shardId.equals(shard.getShardId())) {
            shardToSplit = shard;
            break;
        }
    }

    if (shardToSplit == null) {
        throw new ResourceNotFoundException(
                "Could not find shard with id '" + shardId + "' in stream '" + streamName + "'");
    }

    // Check if the shard is still open. Open shards do not have an ending sequence number.
    if (shardToSplit.getSequenceNumberRange().getEndingSequenceNumber() != null) {
        throw new InvalidArgumentException("Shard is CLOSED and is not eligible for splitting");
    }

    // Calculate the median hash key to use as the new starting hash key for the shard.
    BigInteger startingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getStartingHashKey());
    BigInteger endingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getEndingHashKey());
    BigInteger[] medianHashKey = startingHashKey.add(endingHashKey).divideAndRemainder(new BigInteger("2"));
    BigInteger newStartingHashKey = medianHashKey[0];

    if (!BigInteger.ZERO.equals(medianHashKey[1])) {
        // In order to more evenly distributed the new hash key ranges across the new shards we will "round up" to
        // the next integer when our current hash key range is not evenly divisible by 2.
        newStartingHashKey = newStartingHashKey.add(BigInteger.ONE);
    }

    // Submit the split shard request
    kinesis.splitShard(streamName, shardId, newStartingHashKey.toString());
}

From source file:com.subgraph.vega.internal.http.proxy.ssl.CertificateCreator.java

private BigInteger getNextSerialNumber() {
    BigInteger serial = BigInteger.valueOf(System.currentTimeMillis());
    synchronized (serials) {
        while (serials.contains(serial))
            serial = serial.add(BigInteger.ONE);
        serials.add(serial);// ww  w .j a va  2s.  c o m
        return serial;
    }
}

From source file:com.alertlogic.aws.analytics.poc.StreamUtils.java

/**
 * Split a shard by dividing the hash key space in half.
 *
 * @param streamName Name of the stream that contains the shard to split.
 * @param shardId The id of the shard to split.
 *
 * @throws IllegalArgumentException When either streamName or shardId are null or empty.
 * @throws LimitExceededException Shard limit for the account has been reached.
 * @throws ResourceNotFoundException The stream or shard cannot be found.
 * @throws InvalidArgumentException If the shard is closed and no eligible for splitting.
 * @throws AmazonClientException Error communicating with Amazon Kinesis.
 *
 *//*w w w  . j  a  v  a  2 s  . co m*/
public void splitShardEvenly(String streamName, String shardId) throws LimitExceededException,
        ResourceNotFoundException, AmazonClientException, InvalidArgumentException, IllegalArgumentException {
    if (streamName == null || streamName.isEmpty()) {
        throw new IllegalArgumentException("stream name is required");
    }
    if (shardId == null || shardId.isEmpty()) {
        throw new IllegalArgumentException("shard id is required");
    }

    DescribeStreamResult result = kinesis.describeStream(streamName);
    StreamDescription description = result.getStreamDescription();

    // Find the shard we want to split
    Shard shardToSplit = null;
    for (Shard shard : description.getShards()) {
        if (shardId.equals(shard.getShardId())) {
            shardToSplit = shard;
            break;
        }
    }

    if (shardToSplit == null) {
        throw new ResourceNotFoundException(
                "Could not find shard with id '" + shardId + "' in stream '" + streamName + "'");
    }

    // Check if the shard is still open. Open shards do not have an ending sequence number.
    if (shardToSplit.getSequenceNumberRange().getEndingSequenceNumber() != null) {
        throw new InvalidArgumentException("Shard is CLOSED and is not eligible for splitting");
    }

    // Calculate the median hash key to use as the new starting hash key for the shard.
    BigInteger startingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getStartingHashKey());
    BigInteger endingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getEndingHashKey());
    BigInteger[] medianHashKey = startingHashKey.add(endingHashKey).divideAndRemainder(new BigInteger("2"));
    BigInteger newStartingHashKey = medianHashKey[0];
    if (!BigInteger.ZERO.equals(medianHashKey[1])) {
        // In order to more evenly distributed the new hash key ranges across the new shards we will "round up" to
        // the next integer when our current hash key range is not evenly divisible by 2.
        newStartingHashKey = newStartingHashKey.add(BigInteger.ONE);
    }

    // Submit the split shard request
    kinesis.splitShard(streamName, shardId, newStartingHashKey.toString());
}

From source file:com.amazon.carbonado.repo.jdbc.TestH2.java

@Override
protected BigInteger expected(BigInteger bi) {
    // Used to detect that BigIntegerAdapter was selected.
    return bi.add(BigInteger.ONE);
}

From source file:de.jfachwert.math.Bruch.java

/**
 * Addition zweier Brueche./*  w ww  . j ava  2  s  .  c  om*/
 *
 * @param operand der zweite Bruch, der addiert wird.
 * @return addierter Bruch, evtl. gekuerzt
 */
public AbstractNumber add(Bruch operand) {
    BigInteger n = getNenner().multiply(operand.getNenner());
    BigInteger z1 = getZaehler().multiply(operand.getNenner());
    BigInteger z2 = operand.getZaehler().multiply(getNenner());
    return Bruch.of(z1.add(z2), n).kuerzen();
}

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

private void addQuantity(HashMap<String, BigInteger> map, String assetId, BigInteger quantity) {
    if (!map.containsKey(assetId))
        map.put(assetId, quantity);/*from   w ww  .  j a  v  a  2 s  .com*/
    else
        map.put(assetId, quantity.add(map.get(assetId)));
}

From source file:org.calrissian.accumulorecipes.featurestore.support.StatsCombiner.java

@Override
public Value reduce(Key key, Iterator<Value> iter) {

    long min = Long.MAX_VALUE;
    long max = Long.MIN_VALUE;
    long sum = 0;
    long count = 0;
    BigInteger sumSquare = BigInteger.valueOf(0);

    while (iter.hasNext()) {

        String stats[] = iter.next().toString().split(",");

        if (stats.length == 1) {
            long val = parseLong(stats[0]);
            min = min(val, min);
            max = max(val, max);
            sum += val;
            count += 1;// w  w w .j av a 2s  .  c o m
            sumSquare = sumSquare.add(BigInteger.valueOf(val * val));
        } else {
            min = min(parseLong(stats[0]), min);
            max = max(parseLong(stats[1]), max);
            sum += parseLong(stats[2]);
            count += parseLong(stats[3]);
            sumSquare = sumSquare.add(new BigInteger(stats[4]));
        }
    }

    String ret = join(",", Long.toString(min), Long.toString(max), Long.toString(sum), Long.toString(count),
            sumSquare.toString());

    return new Value(ret.getBytes());
}