Example usage for java.math BigInteger BigInteger

List of usage examples for java.math BigInteger BigInteger

Introduction

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

Prototype

private BigInteger(long val) 

Source Link

Document

Constructs a BigInteger with the specified value, which may not be zero.

Usage

From source file:com.cyphermessenger.utils.Utils.java

public static int randomInt() {
    byte[] bytes = new byte[4];
    RANDOM.nextBytes(bytes);//from w w  w  .j  ava 2s.c om
    return new BigInteger(bytes).intValue();
}

From source file:cz.cvut.kbss.jsonld.jackson.serialization.JacksonJsonWriterTest.java

@Test
public void writeNumberBigIntegerWritesBigInteger() throws Exception {
    final BigInteger number = new BigInteger(Integer.toString(Integer.MAX_VALUE));
    writer.writeNumber(number);// w w w  .ja  v  a2  s  .c o m
    verify(generator).writeNumber(number);
}

From source file:org.datagator.tools.importer.impl.CsvInputStreamExtractor.java

@Override
public AtomType nextAtom() throws IOException {
    JsonToken token = _parser.nextToken();
    while (token != null) {
        switch (token) {
        case START_ARRAY:
            _numFields = 0;/*from  w  ww . java 2  s  .c  om*/
            _data = null;
            return _atom = AtomType.START_RECORD;
        case END_ARRAY:
            _data = _numFields;
            return _atom = AtomType.END_RECORD;
        case VALUE_STRING:
            _numFields += 1;
            String raw = _parser.getText();
            if (raw == null || raw.isEmpty()) {
                _data = null;
                return _atom = AtomType.NULL;
            }
            try {
                switch (_parser.getNumberType()) {
                case INT:
                case LONG:
                    _data = Long.parseLong(raw);
                    return _atom = AtomType.INTEGER;
                case BIG_INTEGER:
                    _data = new BigInteger(raw);
                    return _atom = AtomType.INTEGER;
                case FLOAT:
                case DOUBLE:
                    _data = Double.parseDouble(raw);
                    return _atom = AtomType.FLOAT;
                case BIG_DECIMAL:
                    _data = new BigDecimal(raw);
                    return _atom = AtomType.FLOAT;
                default:
                    break;
                }
            } catch (JsonParseException ioe) {
                ; // this can be silently ignored
            }
            _data = raw;
            return _atom = AtomType.STRING;
        case VALUE_NULL:
            _data = null;
            return _atom = AtomType.NULL;
        case START_OBJECT:
        case END_OBJECT:
        case FIELD_NAME:
        case VALUE_EMBEDDED_OBJECT:
        case VALUE_NUMBER_INT:
        case VALUE_NUMBER_FLOAT:
        case VALUE_TRUE:
        case VALUE_FALSE:
        case NOT_AVAILABLE:
        default:
            break;
        }
        token = _parser.nextToken();
    }
    _data = null;
    return this._atom = null;
}

From source file:me.yanaga.querydsl.args.core.single.SingleBigIntegerArgumentTest.java

@Test
public void testAppendDefaultTwoArguments() {
    SingleBigIntegerArgument argument = SingleBigIntegerArgument.of(new BigInteger("123"));
    BooleanBuilder builder = new BooleanBuilder();
    argument.append(builder, QPerson.person.oneBigInteger, QPerson.person.anotherBigInteger);
    Person result = new JPAQuery(entityManager).from(QPerson.person).where(builder)
            .uniqueResult(QPerson.person);
    assertThat(result.getOneBigInteger()).isEqualTo(new BigInteger("123"));
}

From source file:edu.wisc.hr.demo.RandomEarningStatementDao.java

@Override
public EarningStatements getEarningStatements(String emplid) {

    if (emplIdToEarningStatement.containsKey(emplid)) {
        return emplIdToEarningStatement.get(emplid);
    }/*from  ww  w.  j a  v a2 s  .  c om*/

    EarningStatements earningStatements = new EarningStatements();

    int howManyEarningStatements = random.nextInt(20);

    // "earned" is the date period in which earned, as in
    // "11/03/2013 - 11/16/2013" . Get one such label for each earning statement
    List<String> payPeriodLabels = payPeriodGenerator.payPeriods(howManyEarningStatements);

    for (String periodLabel : payPeriodLabels) {
        EarningStatement earningStatement = new EarningStatement();

        int randomDocId = random.nextInt(Integer.MAX_VALUE);
        BigInteger randomDocIdAsBigInteger = new BigInteger(Integer.toString(randomDocId));
        earningStatement.setDocId(randomDocIdAsBigInteger);

        int randomDollars = random.nextInt(3000);
        int randomDimes = random.nextInt(10);
        int randomPennies = random.nextInt(10);

        // TODO: use a format string instead
        String amountString = "$".concat(Integer.toString(randomDollars)).concat(".")
                .concat(Integer.toString(randomDimes)).concat(Integer.toString(randomPennies));

        earningStatement.setAmount(amountString);

        // "earned" is the pay period
        earningStatement.setEarned(periodLabel);

        earningStatement.setFullTitle("What is a full title?");
        earningStatement.setPaid("Paid?");

        earningStatements.getEarningStatements().add(earningStatement);
    }

    this.emplIdToEarningStatement.put(emplid, earningStatements);

    return earningStatements;
}

From source file:de.dominicscheurer.passwords.SafePwdGen.java

/**
 * Same as {@link #getBase64(String)}, but for the base "X" instead of 64.
 * //  w ww.  j av a2s.c om
 * @param input
 *            Input to encode.
 * @param dictionary
 *            The characters corresponding to the base "X".
 * @return Base64-encoded input value.
 * @throws UnsupportedEncodingException
 */
private static String getBaseX(String input, char[] dictionary) throws UnsupportedEncodingException {
    BaseX encoder = new BaseX(dictionary);
    return encoder.encode(new BigInteger(input.getBytes()));
}

From source file:soa.governance.chapter2.traffic.services.ws.WSServiceTest.java

private Account getTestAccount() {
    Address address = new Address();
    address.setCity("Shortsight");
    address.setNumber(new BigInteger("10"));
    address.setStreet("Street");
    Account account = new Account();
    account.setAddress(address);//from  w ww  . ja  v  a2 s.  c  o  m
    ListOfPlates plates = new ListOfPlates();
    plates.getLicensePlate().add("PPOOLL");
    plates.getLicensePlate().add("LLKKJJ");
    account.setLicensePlates(plates);
    account.setName("Sophie Anna");
    account.setSsn("2345678");

    return account;
}

From source file:com.mfizz.ruby.marshal.MarshalTest.java

@Test
public void marshalBignum() throws Exception {
    byte[] actualBytes = Marshal.dump(new RubyBignum(new BigInteger("12345678910111212333")));

    // ruby: Marshal.dump(12345678910111212333).unpack('H*')
    byte[] bytes = hextobytes("04086c2b092de335fc8ea954ab");

    Assert.assertArrayEquals(bytes, actualBytes);
}

From source file:com.cyphermessenger.utils.Utils.java

public static long randomLong() {
    byte[] bytes = new byte[8];
    RANDOM.nextBytes(bytes);/*from  ww w.  j  a  va 2  s .  co  m*/
    return new BigInteger(bytes).longValue();
}

From source file:edu.usu.sdl.openstorefront.core.util.EntityUtil.java

/**
 * This will set default on the fields that are marked with a default and
 * are null//  ww w.  j a va  2s. c  o m
 *
 * @param entity
 */
public static void setDefaultsOnFields(Object entity) {
    Objects.requireNonNull(entity, "Entity must not be NULL");
    List<Field> fields = getAllFields(entity.getClass());
    for (Field field : fields) {
        DefaultFieldValue defaultFieldValue = field.getAnnotation(DefaultFieldValue.class);
        if (defaultFieldValue != null) {
            field.setAccessible(true);
            try {
                if (field.get(entity) == null) {
                    String value = defaultFieldValue.value();
                    Class fieldClass = field.getType();
                    if (fieldClass.getSimpleName().equalsIgnoreCase(String.class.getSimpleName())) {
                        field.set(entity, value);
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Long.class.getSimpleName())) {
                        field.set(entity, value);
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Integer.class.getSimpleName())) {
                        field.set(entity, Integer.parseInt(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Boolean.class.getSimpleName())) {
                        field.set(entity, Convert.toBoolean(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Double.class.getSimpleName())) {
                        field.set(entity, Double.parseDouble(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Float.class.getSimpleName())) {
                        field.set(entity, Float.parseFloat(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(BigDecimal.class.getSimpleName())) {
                        field.set(entity, Convert.toBigDecimal(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Date.class.getSimpleName())) {
                        field.set(entity, TimeUtil.fromString(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(BigInteger.class.getSimpleName())) {
                        field.set(entity, new BigInteger(value));
                    }
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                throw new OpenStorefrontRuntimeException(
                        "Unable to get value on " + entity.getClass().getName(), "Check entity passed in.");
            }
        }
    }
}