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:Main.java

public static String toBase58(byte[] b) {
    if (b.length == 0) {
        return "";
    }//from w  w w . j  a v  a 2 s  .c o m

    int lz = 0;
    while (lz < b.length && b[lz] == 0) {
        ++lz;
    }

    StringBuffer s = new StringBuffer();
    BigInteger n = new BigInteger(1, b);
    while (n.compareTo(BigInteger.ZERO) > 0) {
        BigInteger[] r = n.divideAndRemainder(BigInteger.valueOf(58));
        n = r[0];
        char digit = b58[r[1].intValue()];
        s.append(digit);
    }
    while (lz > 0) {
        --lz;
        s.append("1");
    }
    return s.reverse().toString();
}

From source file:Main.java

private static void setterValue(PropertyDescriptor property, Object mapValue, Object object)
        throws InvocationTargetException, IllegalAccessException, ParseException {
    Method setter = property.getWriteMethod();
    if (mapValue == null) {
        setter.invoke(object, mapValue);
        return;/*  ww  w.  ja v  a  2 s.  c om*/
    }

    Class propertyType = property.getPropertyType();
    String type = propertyType.getName();
    String value = mapValue.toString();

    if (type.equals("java.lang.String")) {
        setter.invoke(object, value);
    } else if (type.equals("java.lang.Integer")) {
        setter.invoke(object, Integer.parseInt(value));
    } else if (type.equals("java.lang.Long")) {
        setter.invoke(object, Long.parseLong(value));
    } else if (type.equals("java.math.BigDecimal")) {
        setter.invoke(object, BigDecimal.valueOf(Double.parseDouble(value)));
    } else if (type.equals("java.math.BigInteger")) {
        setter.invoke(object, BigInteger.valueOf(Long.parseLong(value)));
    } else if (type.equals("java.util.Date")) {
        setter.invoke(object, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value));
    } else if (type.equals("java.lang.Boolean")) {
        setter.invoke(object, Boolean.valueOf(value));
    } else if (type.equals("java.lang.Float")) {
        setter.invoke(object, Float.parseFloat(value));
    } else if (type.equals("java.lang.Double")) {
        setter.invoke(object, Double.parseDouble(value));
    } else if (type.equals("java.lang.byte[]")) {
        setter.invoke(object, value.getBytes());
    } else {
        setter.invoke(object, value);
    }
}

From source file:MainClass.java

public static X509Certificate generateV1Certificate(KeyPair pair)
        throws InvalidKeyException, NoSuchProviderException, SignatureException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();

    certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
    certGen.setIssuerDN(new X500Principal("CN=Test Certificate"));
    certGen.setNotBefore(new Date(System.currentTimeMillis() - 10000));
    certGen.setNotAfter(new Date(System.currentTimeMillis() + 10000));
    certGen.setSubjectDN(new X500Principal("CN=Test Certificate"));
    certGen.setPublicKey(pair.getPublic());
    certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");

    return certGen.generateX509Certificate(pair.getPrivate(), "BC");
}

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

public static BigIntegerRange of(long start, long end) {
    return new BigIntegerRange(BigInteger.valueOf(start), BigInteger.valueOf(end));
}

From source file:org.namelessrom.devicecontrol.net.NetworkInfo.java

public static String getWifiIp() {
    final WifiManager wifiManager = (WifiManager) Application.get().getSystemService(Context.WIFI_SERVICE);
    int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
    if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
        ipAddress = Integer.reverseBytes(ipAddress);
    }/*from   w  w  w . j  ava  2s  . com*/

    final byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray();

    String ipAddressString;
    try {
        ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress();
    } catch (UnknownHostException ex) {
        ipAddressString = "0.0.0.0";
    }

    return ipAddressString;
}

From source file:com.aqnote.app.wifianalyzer.wifi.model.WiFiUtils.java

public static String convertIpAddress(int ipAddress) {
    try {/*from  ww w.j  a v  a2s  . c  o  m*/
        byte[] bytes = BigInteger.valueOf(ipAddress).toByteArray();
        ArrayUtils.reverse(bytes);
        return InetAddress.getByAddress(bytes).getHostAddress();
    } catch (Exception e) {
        return StringUtils.EMPTY;
    }
}

From source file:cn.dsgrp.field.stock.repository.TaskDaoTest.java

@Test
public void findTasksByUserId() throws Exception {
    List<Task> tasks = taskDao.findByUser(new User(BigInteger.valueOf(2)));
    //      assertThat(tasks.getContent()).hasSize(5);
    //      assertThat(tasks.getContent().get(0).getId()).isEqualTo(1);
    //      tasks = taskDao.findByUser(new User(BigInteger.valueOf(99999L)), new PageRequest(0, 100, Direction.ASC, "id"));
    //      assertThat(tasks.getContent()).isEmpty();
    //      assertThat(tasks.getContent()).isEmpty();
}

From source file:Main.java

public static BigInteger getBigInteger(Object value) {
    BigInteger ret = null;//  w  w  w. j  a  va  2s  . c o  m
    if (value != null) {
        if (value instanceof BigInteger) {
            ret = (BigInteger) value;
        } else if (value instanceof String) {
            ret = new BigInteger((String) value);
        } else if (value instanceof BigDecimal) {
            ret = ((BigDecimal) value).toBigInteger();
        } else if (value instanceof Number) {
            ret = BigInteger.valueOf(((Number) value).longValue());
        } else {
            throw new ClassCastException("Not possible to coerce [" + value + "] from class " + value.getClass()
                    + " into a BigInteger.");
        }
    }
    return ret;
}

From source file:net.michaelpigg.xbeelib.protocol.XbeeAddress.java

@Deprecated
public static XbeeAddress getAddress(Long address) {
    if (address == null || address < 0 || address > 65535) {
        throw new RuntimeException(String.format("Address %l is not valid", address));
    }//from w ww  .  j a v a  2s  .co  m
    return getAddress(BigInteger.valueOf(address).toByteArray());
}

From source file:dao.ParametrDao.java

public boolean hasCats(Long paramId) throws Exception {
    String sql = "select count(*) from param_category_link where parametr_id=:paramId";
    Query query = getCurrentSession().createSQLQuery(sql);
    query.setParameter("paramId", paramId);
    BigInteger res = (BigInteger) query.uniqueResult();
    //throw new Exception("res="+res);
    return res.compareTo(BigInteger.valueOf(0)) > 0;
}