Example usage for java.math BigInteger ONE

List of usage examples for java.math BigInteger ONE

Introduction

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

Prototype

BigInteger ONE

To view the source code for java.math BigInteger ONE.

Click Source Link

Document

The BigInteger constant one.

Usage

From source file:com.google.uzaygezen.core.ranges.BigIntegerRange.java

static BigInteger overlap(List<BigIntegerRange> x, List<BigIntegerRange> y) {
    int n = x.size();
    Preconditions.checkArgument(y.size() == n, "x and y must have the same number of values");
    BigInteger overlap = BigInteger.ONE;
    // Stop early if overlap.signum() becomes zero.
    for (int i = 0; i < n & overlap.signum() != 0; ++i) {
        BigIntegerRange xRange = x.get(i);
        BigIntegerRange yRange = y.get(i);
        overlap = overlap.multiply(xRange.overlap(yRange));
    }/*from   w w w  . j  ava 2  s  .  co m*/
    return overlap;
}

From source file:RandomUtil.java

public static BigInteger randomBitFlip(BigInteger n) {
    if (n.equals(BigInteger.ONE))
        return BigInteger.ONE;
    if (n.equals(BigInteger.ZERO))
        return BigInteger.ZERO;

    BigInteger toRet = BigInteger.ONE;
    while (toRet.equals(BigInteger.ONE) || toRet.equals(BigInteger.ZERO)) {
        byte[] bytes = n.toByteArray();
        getInstance().random.nextBytes(bytes);
        // could allow up to maxExclusive by converting and checking value
        // but this is faster, even if it doesn't give us full range
        bytes[0] = 0;/*ww w.  j  a  va2 s.  c om*/
        toRet = new BigInteger(bytes);
    }
    return toRet;
}

From source file:com.spotify.hdfs2cass.CassandraPartitionerTest.java

@Test
public void testGetPartition() throws Exception {
    final int maxNodes = 5;

    final List<String> tokenRanges = new ArrayList<String>();

    BigInteger start = BigInteger.ZERO;
    BigInteger step = RandomPartitioner.MAXIMUM.divide(BigInteger.valueOf(maxNodes));
    for (int i = 0; i < maxNodes - 1; i++) {
        BigInteger end = start.add(step);

        tokenRanges.add(String.format("%d:%d", start, end));
        start = end.add(BigInteger.ONE);
    }/*from  w  w w  .ja  v  a  2 s. c o m*/

    tokenRanges.add(String.format("%d:0", start));

    final JobConf conf = new JobConf();
    conf.set(ClusterInfo.SPOTIFY_CASSANDRA_TOKENS_PARAM, StringUtils.join(tokenRanges, ","));
    conf.set(ClusterInfo.SPOTIFY_CASSANDRA_PARTITIONER_PARAM, "org.apache.cassandra.dht.RandomPartitioner");

    CassandraPartitioner instance = new CassandraPartitioner();
    instance.configure(conf);

    Text key = new Text("foobar");
    assertEquals(2, instance.getPartition(key, null, 5));

    key = new Text("someotherkey");
    assertEquals(1, instance.getPartition(key, null, 5));

    key = new Text("1ce5cf4b861941f4aa799ae39ac9daa4");
    assertEquals(4, instance.getPartition(key, null, 5));
}

From source file:org.apache.usergrid.persistence.cassandra.SimpleIndexBucketLocatorImpl.java

/** Get a token */
private static BigInteger initialToken(int size, int position) {
    BigInteger decValue = MINIMUM;
    if (position != 0) {
        decValue = MAXIMUM.divide(new BigInteger("" + size)).multiply(new BigInteger("" + position))
                .subtract(BigInteger.ONE);
    }//  www .  ja v  a2  s .c  om
    return decValue;
}

From source file:com.google.uzaygezen.core.BigIntegerContent.java

@Override
public boolean isOne() {
    return value.equals(BigInteger.ONE);
}

From source file:org.easycassandra.persistence.ColumnFamilyInformation.java

public BigInteger increment() {
    id = id.add(BigInteger.ONE);
    return id;
}

From source file:org.usergrid.persistence.cassandra.SimpleIndexBucketLocatorImpl.java

/**
 * Get a token//w  ww.j  a  va  2s . c o m
 * 
 * @param size
 * @param position
 * @return
 */
private static BigInteger initialToken(int size, int position) {
    BigInteger decValue = MINIMUM;
    if (position != 0)
        decValue = MAXIMUM.divide(new BigInteger("" + size)).multiply(new BigInteger("" + position))
                .subtract(BigInteger.ONE);
    return decValue;
}

From source file:cherry.foundation.type.SecureBigIntegerTest.java

@Test
public void testToString() {
    SecureBigInteger sec = plainValueOf(BigInteger.ONE);
    assertThat(sec.toString(), is("SecureBigInteger[1]"));
}

From source file:cc.redberry.core.number.NumberUtils.java

/**
 * Computes the integer square root of a number.
 *
 * @param n The number./*from   ww w .  j  av a2 s  . c  o m*/
 * @return The integer square root, i.e. the largest number whose square
 *         doesn't exceed n.
 */
public static BigInteger sqrt(BigInteger n) {
    if (n.signum() >= 0) {
        final int bitLength = n.bitLength();
        BigInteger root = BigInteger.ONE.shiftLeft(bitLength / 2);

        while (!isSqrtXXX(n, root))
            root = root.add(n.divide(root)).divide(TWO);
        return root;
    } else
        throw new ArithmeticException("square root of negative number");
}

From source file:org.eclipse.equinox.p2.cudf.solver.ParanoidOptimizationFunction.java

public List<WeightedObject<Object>> createOptimizationFunction(InstallableUnit metaIu) {
    List<WeightedObject<Object>> weightedObjects = new ArrayList<WeightedObject<Object>>();
    BigInteger weight = BigInteger.valueOf(slice.size() + 1);
    removed(weightedObjects, weight, metaIu);
    changed(weightedObjects, BigInteger.ONE, metaIu);
    if (!weightedObjects.isEmpty()) {
        return weightedObjects;
    }/*from w  ww . j  a v a2  s. c o  m*/
    return null;
}