Example usage for java.math BigInteger ZERO

List of usage examples for java.math BigInteger ZERO

Introduction

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

Prototype

BigInteger ZERO

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

Click Source Link

Document

The BigInteger constant zero.

Usage

From source file:org.stem.domain.DHT.java

public int getSection(byte[] keyBytes) {
    BigInteger token = new BigInteger(new String(Hex.encodeHex(keyBytes)), 16);
    BigInteger sectionSize = capacity.divide(BigInteger.valueOf(sections));

    int quotient = token.divide(sectionSize).intValue();
    BigInteger mod = token.mod(sectionSize);
    int index;/* w  w  w. j  a v a  2 s .c  om*/
    if (quotient == 0)
        index = 0;
    else if (mod.equals(BigInteger.ZERO))
        index = Math.max(quotient - 1, 0);
    else
        index = Math.max(quotient, 0);

    if (index >= sections) {
        return sections - 1;
    }

    return index;
}

From source file:com.offbynull.peernetic.common.identification.IdGenerator.java

/**
 * Constructs a {@link DefaultIdGenerator} object using a {@link Random} as its underlying source.
 * @param random random number generator (should be a {@link SecureRandom} instance in most cases)
 * @param limit maximum value the id generated can be
 * @throws NullPointerException if any arguments are {@code null}
 * @throws IllegalArgumentException if limit is 0
 *///from  w  w w .j a  va  2  s  .  c  om
public IdGenerator(Random random, byte[] limit) {
    Validate.notNull(random);
    Validate.notNull(limit);
    Validate.isTrue(limit.length > 0 && !new BigInteger(1, limit).equals(BigInteger.ZERO));
    this.random = random;
    this.limit = Arrays.copyOf(limit, limit.length);
}

From source file:co.rsk.remasc.RemascStorageProviderTest.java

@Test
public void getDefautRewardBalance() {
    String accountAddress = randomAddress();
    Repository repository = new RepositoryImpl();

    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);

    Assert.assertEquals(BigInteger.ZERO, provider.getRewardBalance());
}

From source file:me.ferrybig.javacoding.webmapper.test.session.DefaultDataStorageTest.java

@Test
public void getDataAsChoosesCorrectBackendTypeTest() {
    List<Object> list = new ArrayList<>();
    list.add(new Object());
    list.add(BigInteger.ZERO);
    list.add("string");
    list.add(Boolean.FALSE);/*from  w  ww . j av a 2 s.c o m*/
    list.add(new JSONObject());
    data.setData(list);
    assertEquals("string", extr(data.getDataAs(String.class)));
}

From source file:com.impetus.kundera.utils.NumericUtils.java

/**
 *  Check if zero/*  w w  w.  ja  va  2 s .c om*/
 * @param value        value string
 * @param valueClazz   value class 
 * @return             
 */
public static final boolean checkIfZero(String value, Class valueClazz) {
    boolean returnValue = false;
    if (value != null && NumberUtils.isNumber(value) && numberTypes.get(valueClazz) != null) {
        switch (numberTypes.get(valueClazz)) {

        case INTEGER:
            returnValue = Integer.parseInt(value) == (NumberUtils.INTEGER_ZERO);
            break;

        case FLOAT:
            returnValue = Float.parseFloat(value) == (NumberUtils.FLOAT_ZERO);
            break;

        case LONG:
            returnValue = Long.parseLong(value) == (NumberUtils.LONG_ZERO);
            break;

        case BIGDECIMAL:
            returnValue = new BigDecimal(value) == (BigDecimal.ZERO);
            break;

        case BIGINTEGER:
            returnValue = new BigInteger(value) == (BigInteger.ZERO);
            break;

        case SHORT:
            returnValue = new Short(value) == (NumberUtils.SHORT_ZERO);
            break;
        }
    }

    return returnValue;
}

From source file:Main.java

public static String encodeBase58(byte[] input) {
    if (input == null) {
        return null;
    }//from w ww . ja  va2  s. com
    StringBuilder str = new StringBuilder((input.length * 350) / 256 + 1);
    BigInteger bn = new BigInteger(1, input);
    long rem;
    while (true) {
        BigInteger[] divideAndRemainder = bn.divideAndRemainder(BASE58_CHUNK_MOD);
        bn = divideAndRemainder[0];
        rem = divideAndRemainder[1].longValue();
        if (bn.compareTo(BigInteger.ZERO) == 0) {
            break;
        }
        for (int i = 0; i < BASE58_CHUNK_DIGITS; i++) {
            str.append(BASE58[(int) (rem % 58)]);
            rem /= 58;
        }
    }
    while (rem != 0) {
        str.append(BASE58[(int) (rem % 58)]);
        rem /= 58;
    }
    str.reverse();
    int nLeadingZeros = 0;
    while (nLeadingZeros < input.length && input[nLeadingZeros] == 0) {
        str.insert(0, BASE58[0]);
        nLeadingZeros++;
    }
    return str.toString();
}

From source file:ID.java

public static String getHexString(byte[] bytes) {
    // This method cannot change even if it's wrong.
    BigInteger bigInteger = BigInteger.ZERO;
    int shift = 0;
    for (int i = bytes.length; --i >= 0;) {
        BigInteger contrib = BigInteger.valueOf(bytes[i] & 0xFF);
        contrib = contrib.shiftLeft(shift);
        bigInteger = bigInteger.add(contrib);
        shift += 8;//from   ww  w. j ava 2s .  co m
    }
    return bigInteger.toString(16).toUpperCase();
}

From source file:com.nearinfinity.honeycomb.hbase.bulkload.FieldParser.java

/**
 * Try to parse a string into a byte string based on a column type.
 *
 * @param val    String value/*from   w w w . ja  v a2  s.c  o  m*/
 * @param schema Column schema to base value parsing on.
 * @return Byte string
 * @throws ParseException The string value could not be parsed into the column type.
 */
public static ByteBuffer parse(String val, ColumnSchema schema) throws ParseException {
    checkNotNull(val, "Should not be parsing null. Something went terribly wrong.");
    checkNotNull(schema, "Column metadata is null.");

    ColumnType type = schema.getType();

    if (val.length() == 0 && type != ColumnType.STRING && type != ColumnType.BINARY) {
        if (schema.getIsNullable()) {
            return null;
        }

        throw new IllegalArgumentException(
                "Expected a value for a" + " non-null SQL column, but no value was given.");
    }

    switch (type) {
    case LONG:
        return ByteBuffer.wrap(Longs.toByteArray(Long.parseLong(val)));
    case ULONG:
        BigInteger n = new BigInteger(val);
        if (n.compareTo(BigInteger.ZERO) == -1) {
            throw new IllegalArgumentException("negative value provided for unsigned column. value: " + val);
        }
        return ByteBuffer.wrap(Longs.toByteArray(n.longValue()));
    case DOUBLE:
        return ByteBuffer.wrap(Bytes.toBytes(Double.parseDouble(val)));
    case DATE:
        return extractDate(val, "yyyy-MM-dd", "yyyy-MM-dd", "yyyy/MM/dd", "yyyy.MM.dd", "yyyyMMdd");
    case TIME:
        return extractDate(val, "HH:mm:ss", "HH:mm:ss", "HHmmss");
    case DATETIME:
        return extractDate(val, "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss",
                "yyyy.MM.dd HH:mm:ss", "yyyyMMdd HHmmss");
    case DECIMAL:
        return extractDecimal(val, schema.getPrecision(), schema.getScale());
    case STRING:
    case BINARY:
    default:
        return ByteBuffer.wrap(val.getBytes(Charset.forName("UTF-8")));
    }
}

From source file:com.basho.riak.client.itest.ITestStats.java

@Test
public void testDeserializer() throws IOException {
    NodeStats.UndefinedStatDeserializer usd = new NodeStats.UndefinedStatDeserializer();
    SimpleModule module = new SimpleModule("UndefinedStatDeserializer", new Version(1, 0, 0, null, null, null));
    module.addDeserializer(BigInteger.class, usd);

    String json = "{\"vnode_gets\":\"deprecated\",\"vnode_gets_total\":12345678}";

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(module);//from www  .  ja  va 2  s  .  c  o  m
    NodeStats stats = mapper.readValue(json, NodeStats.class);
    assertEquals(stats.vnodeGets(), BigInteger.ZERO);
    assertEquals(stats.vnodeGetsTotal(), BigInteger.valueOf(12345678));

}

From source file:com.redhat.lightblue.metadata.types.BigIntegerTypeTest.java

@Test
public void testToJson() {
    JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true);
    JsonNode jsonNode = bigIntegerType.toJson(jsonNodeFactory, BigInteger.ZERO);
    assertTrue(new BigInteger(jsonNode.asText()).equals(BigInteger.ZERO));
}