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.sun.identity.openid.provider.Codec.java

/**
 * TODO: Description./*from  ww w .  j  a  v a  2  s .  c o  m*/
 * 
 * @param value
 *            TODO.
 * @return TODO.
 * @throws DecodeException
 *             TODO.
 */
public static BigInteger decodeBigInteger(String value) throws DecodeException {
    byte[] bytes = decodeBytes(value);

    if (bytes == null) {
        return null;
    }

    try {
        return new BigInteger(bytes);
    }

    catch (NumberFormatException nfe) {
        throw new DecodeException("big integer could not be decoded");
    }
}

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

private static BigInteger[] toNumbers(String bruch) {
    BigInteger[] numbers = new BigInteger[2];
    String[] parts = StringUtils.split(bruch, "/");
    try {//from   w ww  .  j  ava  2 s  .  c om
        switch (parts.length) {
        case 1:
            Bruch dezimalBruch = toBruch(new BigDecimal(parts[0]));
            numbers[0] = dezimalBruch.getZaehler();
            numbers[1] = dezimalBruch.getNenner();
            break;
        case 2:
            numbers[0] = new BigInteger(parts[0]);
            numbers[1] = new BigInteger(parts[1]);
            break;
        default:
            throw new LocalizedIllegalArgumentException(bruch, "fraction");
        }
        return numbers;
    } catch (IllegalArgumentException ex) {
        throw new LocalizedIllegalArgumentException(bruch, "fraction", ex);
    }
}

From source file:com.splicemachine.testutil.RandomDerbyDecimalBuilder.java

public static BigDecimal buildOne(int precision, int scale, boolean negative) {
    checkArgument(precision >= PRECISION_MIN && precision <= PRECISION_MAX);
    checkArgument(scale <= precision);

    BigInteger unscaledVal = new BigInteger((negative ? "-" : "") + RandomStringUtils.randomNumeric(precision));
    return new BigDecimal(unscaledVal, scale);
}

From source file:info.savestate.saveybot.JSONFileManipulator.java

public String getSlot(String slotString, boolean largeResponse) {
    try {//from ww  w .  ja  va 2 s.  c o  m
        return getSlot(new BigInteger(slotString));
    } catch (Exception e) {
        // going to load all slots made by user.
    }
    JSONArray json = getJSON();
    if (!largeResponse) {
        int entries = 0;
        for (int i = 0; i < json.length(); i++) {
            JSONObject o = json.getJSONObject(i);
            if (o == null)
                continue;
            if (o.getString("name").toLowerCase().equals(slotString.toLowerCase()))
                entries++;
        }
        if (entries > 0)
            return slotString + " owns " + entries + " savestates!!! :D/";
        return slotString + " doesnt own any savestates );";
    }
    StringBuilder slots = new StringBuilder();
    int entries = 0;
    for (int i = 0; i < json.length(); i++) {
        JSONObject o = json.getJSONObject(i);
        if (o == null)
            continue;
        if (o.getString("name").toLowerCase().equals(slotString.toLowerCase())) {
            entries++;
            slots.append(o.getString("slot")).append(", ");
        }
    }
    if (entries > 0) {
        slots.deleteCharAt(slots.length() - 1);
        slots.deleteCharAt(slots.length() - 1);
        return "owha! " + slotString + " owns slot(s) " + slots.toString() + "!!!! :D :D :D/";
    }
    return slotString + " doesn't own any savestates!! (u should fix that !! O:)";
}

From source file:com.jim.im.broker.handler.PublishInterceptHandler.java

@Override
public void onPublish(InterceptPublishMessage msg) {
    BigInteger messageId = new BigInteger(msg.getPayload().array());
    final ImMessage imMessage = messageRepo.findOne(messageId);
    final ActiveMQTopic mqTopicName = new ActiveMQTopic(IMConstant.MQ_FORWARD_TOPIC_NAME);
    MessageConverter messageConverter = jmsTemplate.getMessageConverter();
    jmsTemplate.send(mqTopicName, new MessageCreator() {
        @Override/*from w w w. ja  v  a  2 s . c  o  m*/
        public Message createMessage(Session session) throws JMSException {
            Message message = messageConverter.toMessage(imMessage, session);
            message.setStringProperty(IMConstant.BROKER_NAME, brokerName);
            return message;
        }
    });
}

From source file:io.fineo.drill.exec.store.dynamo.key.LengthBasedCompoundKeyMapper.java

@Override
@JsonIgnore//from w  w  w .jav a 2  s.co m
public Map<String, Object> mapSortKey(Object value) {
    String val = (String) value;
    String p1 = val.substring(0, length);
    String p2 = val.substring(length);
    Map<String, Object> out = new HashMap<>();
    // need to make sure that you actually write a big decimal representation to match what
    // dynamo generates as values
    out.put(spec.getKeyNames().get(2), new BigDecimal(new BigInteger(p1)));
    out.put(spec.getKeyNames().get(3), new BigDecimal(new BigInteger(p2)));
    return out;
}

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

/**
 *  Check if zero//from   www .  j av a  2s .c o m
 * @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:com.przemo.projectmanagementweb.services.SprintService.java

public BigInteger getAvailableTime(Sprint s) {
    List<BigInteger> l = HibernateUtil
            .runSQLQuery("select sum(estimated_time) from task where sprint=" + s.getId());
    if (!l.isEmpty() && l.get(0) != null) {
        return l.get(0);
    } else {//from w  w  w .ja va 2  s.c o m
        return new BigInteger("0");
    }
}

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/*w  ww  . ja v a  2  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:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomFilterQuery.java

@Override
protected void process(DebsRecord record) {
    // TODO Auto-generated method stub
    String str = record.getHack_license() + record.getDropoff_latitude() + record.getDropoff_longitude()
            + record.getPickup_latitude() + record.getPickup_longitude();

    MessageDigest md = null;// ww  w  . jav a 2  s  . c  om
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String[] str2hash = new String[k];
    for (int i = 0; i < 10; i++) {
        str2hash[i] = salt[i] + str;
        try {
            md.update(str2hash[i].toString().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        byte[] res = md.digest();
        BigInteger indiceB = new BigInteger(res);
        int indice = indiceB.intValue();
        if (indice < 0)
            indice = -indice;
        indice = indice % 14378;
        if (!bloomFilter.get(indice))
            bloomFilter.set(indice);
    }

}