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:cn.dsgrp.field.stock.functional.rest.TaskRestFT.java

/**
 * //./* w w  w . j av  a2s. co  m*/
 */
@Test
@Category(Smoke.class)
public void createUpdateAndDeleteTask() {

    // create
    Task task = TaskData.randomTask();

    URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task);
    System.out.println(createdTaskUri.toString());
    Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(createdTask.getTitle()).isEqualTo(task.getTitle());

    // update
    String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/");
    task.setId(BigInteger.valueOf(Long.parseLong(id)));
    task.setTitle(TaskData.randomTitle());

    restTemplate.put(createdTaskUri, task);

    Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle());

    // delete
    restTemplate.delete(createdTaskUri);

    try {
        restTemplate.getForObject(createdTaskUri, Task.class);
        fail("Get should fail while feth a deleted task");
    } catch (HttpStatusCodeException e) {
        assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    }
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BigIntegerMapper.java

/**
 * Builds a new {@link BigDecimalMapper} using the specified max number of digits.
 *
 * @param field   The name of the field.
 * @param column  The name of the column to be mapped.
 * @param indexed If the field supports searching.
 * @param sorted  If the field supports sorting.
 * @param digits  The max number of digits. If {@code null}, the {@link #DEFAULT_DIGITS} will be used.
 *//*from   w w w  .j ava  2  s  .  co m*/
public BigIntegerMapper(String field, String column, Boolean indexed, Boolean sorted, Integer digits) {
    super(field, column, indexed, sorted, AsciiType.instance, UTF8Type.instance, Int32Type.instance,
            LongType.instance, IntegerType.instance);

    if (digits != null && digits <= 0) {
        throw new IndexException("Positive digits required");
    }

    this.digits = digits == null ? DEFAULT_DIGITS : digits;
    complement = BigInteger.valueOf(BASE).pow(this.digits).subtract(BigInteger.valueOf(1));
    BigInteger maxValue = complement.multiply(BigInteger.valueOf(2));
    hexDigits = encode(maxValue).length();
}

From source file:it.gualtierotesta.gdocx.GTr.java

/**
 * Set row height with specified rule//from  w ww.j av  a 2  s  .  c o m
 *
 * @param lHeight height of the row
 * @param eRule   height rule (for ex. STHeightRule.EXACT )
 * @return same GTr instance
 */
@Nonnull
public GTr height(final long lHeight, final STHeightRule eRule) {

    Validate.isTrue(0L < lHeight, "Height value not valid");
    Validate.notNull(eRule, "Rule not valid");

    final CTHeight cth = FACTORY.createCTHeight();
    cth.setVal(BigInteger.valueOf(lHeight));
    cth.setHRule(eRule);
    trPr.getCnfStyleOrDivIdOrGridBefore().add(FACTORY.createCTTrPrBaseTrHeight(cth));
    return this;
}

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.AbstractRanker.java

/**
 * Returns the frequency for a array of words
 * @param words/* ww  w .  java2s. co m*/
 * @return
 */
protected BigInteger freq(String[] words) {
    BigInteger total = BigInteger.valueOf(0l);

    for (NGram gram : finder.find(words)) {
        total = total.add(BigInteger.valueOf(gram.getFreq()));
    }

    return total;
}

From source file:de.undercouch.bson4jackson.BsonGeneratorTest.java

@Test
public void generatePrimitives() throws Exception {
    Map<String, Object> data = new LinkedHashMap<String, Object>();
    data.put("Int32", 5);
    data.put("Boolean1", true);
    data.put("Boolean2", false);
    data.put("String", "Hello");
    data.put("Long", 1234L);
    data.put("Null", null);
    data.put("Float", 1234.1234f);
    data.put("Double", 5678.5678);

    //BigInteger that can be serialized as an Integer
    data.put("BigInt1", BigInteger.valueOf(Integer.MAX_VALUE));

    //BigInteger that can be serialized as a Long
    BigInteger bi2 = BigInteger.valueOf(Integer.MAX_VALUE).multiply(BigInteger.valueOf(2));
    data.put("BigInt2", bi2);

    //BigInteger that will be serialized as a String
    BigInteger bi3 = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(Long.MAX_VALUE));
    data.put("BigInt3", bi3);

    BSONObject obj = generateAndParse(data);

    assertEquals(5, obj.get("Int32"));
    assertEquals(true, obj.get("Boolean1"));
    assertEquals(false, obj.get("Boolean2"));
    assertEquals("Hello", obj.get("String"));
    assertEquals(1234L, obj.get("Long"));
    assertEquals(null, obj.get("Null"));
    assertEquals(1234.1234f, (Double) obj.get("Float"), 0.00001);
    assertEquals(5678.5678, (Double) obj.get("Double"), 0.00001);
    assertEquals(Integer.MAX_VALUE, obj.get("BigInt1"));
    assertEquals(Long.valueOf(Integer.MAX_VALUE) * 2L, obj.get("BigInt2"));
    assertEquals(bi3.toString(), obj.get("BigInt3"));
}

From source file:org.gridobservatory.greencomputing.dao.TimeseriesDao.java

public BigInteger insert(T timeseriesType) {
    KeyHolder keyHolder = new GeneratedKeyHolder();

    PreparedStatementCreatorFactory preparedStatementCreatorFactory = new PreparedStatementCreatorFactory(
            "insert into time_series (constant_value,start_date,end_date,acquisition_count ) "
                    + "values (?, ?, ?, ?)",
            new int[] { Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.BIGINT });

    PreparedStatementCreator newPreparedStatementCreator = preparedStatementCreatorFactory
            .newPreparedStatementCreator(new Object[] {
                    timeseriesType.getConstantValue() != null ? timeseriesType.getConstantValue().getValue()
                            : "",
                    new Date(timeseriesType.getStartDate().longValue() * 1000),
                    new Date(timeseriesType.getEndDate().longValue() * 1000),
                    timeseriesType.getAcquisitionCount() });

    preparedStatementCreatorFactory.setReturnGeneratedKeys(true);
    this.getJdbcTemplate().update(newPreparedStatementCreator, keyHolder);
    BigInteger timeSeriesId = BigInteger.valueOf(keyHolder.getKey().longValue());

    insertTimeSeriesAcquisitions(timeSeriesId, timeseriesType.getA());

    return timeSeriesId;
}

From source file:ac.elements.parser.SimpleDBConverter.java

/**
 * Decodes zero-padded positive long value from the string representation
 * //from  ww  w .  ja  v  a 2 s  .  co m
 * com.xerox.amazonws.sdb.DataUtils
 * 
 * @param value
 *            zero-padded string representation of the long
 * @return original long value
 */
private static long decodeLong(String value) {
    BigInteger bi = new BigInteger(value, RADIX);
    bi = bi.add(BigInteger.valueOf(Long.MIN_VALUE));
    return bi.longValue();
}

From source file:Ternary.java

public Ternary(int toConvert) {
    this(BigInteger.valueOf(toConvert));
}

From source file:org.spring.cache.CachingWithGeodeIntegrationTest.java

@Test
public void bCacheHits() {
    assertThat(mathService.factorial(BigInteger.valueOf(0)), is(equalTo(BigInteger.ONE)));
    assertThat(mathService.wasCacheMiss(), is(false));
    assertThat(mathService.factorial(BigInteger.valueOf(1)), is(equalTo(BigInteger.ONE)));
    assertThat(mathService.wasCacheMiss(), is(false));
    assertThat(mathService.factorial(BigInteger.valueOf(2)), is(equalTo(MathService.TWO)));
    assertThat(mathService.wasCacheMiss(), is(false));
    assertThat(mathService.factorial(BigInteger.valueOf(4)), is(equalTo(BigInteger.valueOf(24))));
    assertThat(mathService.wasCacheMiss(), is(false));
    assertThat(mathService.factorial(BigInteger.valueOf(8)), is(equalTo(BigInteger.valueOf(40320))));
    assertThat(mathService.wasCacheMiss(), is(false));
}

From source file:com.streamsets.pipeline.stage.it.AllSdcTypesIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, true), true, Types.BOOLEAN, true },
            { Field.create(Field.Type.CHAR, 'A'), true, Types.VARCHAR, "A" },
            { Field.create(Field.Type.BYTE, (byte) 0x00), false, 0, null },
            { Field.create(Field.Type.SHORT, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.INTEGER, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.LONG, 10), true, Types.BIGINT, 10L },
            { Field.create(Field.Type.FLOAT, 1.5), true, Types.FLOAT, 1.5 },
            { Field.create(Field.Type.DOUBLE, 1.5), true, Types.DOUBLE, 1.5 },
            { Field.create(Field.Type.DATE, new Date(116, 5, 13)), true, Types.DATE, new Date(116, 5, 13) },
            { Field.create(Field.Type.DATETIME, date), true, Types.VARCHAR, datetimeFormat.format(date) },
            { Field.create(Field.Type.TIME, date), true, Types.VARCHAR, timeFormat.format(date) },
            { Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(1.5)), true, Types.DECIMAL,
                    new BigDecimal(BigInteger.valueOf(15), 1, new MathContext(2, RoundingMode.FLOOR)) },
            { Field.create(Field.Type.STRING, "StreamSets"), true, Types.VARCHAR, "StreamSets" },
            { Field.create(Field.Type.BYTE_ARRAY, new byte[] { (byte) 0x00 }), true, Types.BINARY,
                    new byte[] { (byte) 0x00 } },
            { Field.create(Field.Type.MAP, Collections.emptyMap()), false, 0, null },
            { Field.create(Field.Type.LIST, Collections.emptyList()), false, 0, null },
            { Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>()), false, 0, null }, });
}