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.livinglogic.ul4.FunctionInt.java

public static Object call(Object obj) {
    if (obj instanceof String) {
        try {//w  w  w.  j  av a2  s.  c o  m
            return Integer.valueOf((String) obj);
        } catch (NumberFormatException ex1) {
            try {
                return Long.valueOf((String) obj);
            } catch (NumberFormatException ex2) {
                return new BigInteger((String) obj);
            }
        }
    } else if (obj instanceof Integer || obj instanceof Byte || obj instanceof Short || obj instanceof Long)
        return obj;
    else if (obj instanceof BigInteger)
        return Utils.narrowBigInteger((BigInteger) obj);
    else if (obj instanceof Boolean)
        return ((Boolean) obj).booleanValue() ? NumberUtils.INTEGER_ONE : NumberUtils.INTEGER_ZERO;
    else if (obj instanceof Float || obj instanceof Double)
        return ((Number) obj).intValue();
    else if (obj instanceof BigDecimal)
        return ((BigDecimal) obj).toBigInteger();
    throw new ArgumentTypeMismatchException("int({})", obj);
}

From source file:dingwen.Command.java

public static void removeShapeCmd(String command, ShapeCache shapeCache) {
    BigInteger id = null;//from   w ww. java  2 s .  c  o  m
    if (NumberUtils.isNumber(command.substring(command.indexOf(" ") + 1))) {
        id = new BigInteger(command.substring(command.indexOf(" ") + 1));
        Shape shape = shapeCache.removeShape(id);
        if (shape == null) {
            System.out.println(CommonStatement.SHAPE_NOT_EXISTS);
        } else {
            System.out.println("Removed shape " + id + " : " + shape.toString());
        }
    } else {
        System.out.println(CommonStatement.ID_INVALID);
    }
}

From source file:Main.java

public static String byteArrayToHexString(byte[] bytes) {
    int oldLength = bytes.length;
    byte[] positiveBytes = new byte[oldLength + 1];
    System.arraycopy(bytes, 0, positiveBytes, 1, oldLength);
    positiveBytes[0] = 1;/*from   w w  w. j  av a 2  s .  com*/
    BigInteger bigInt = new BigInteger(positiveBytes);
    String hex = bigInt.toString(16);
    return hex.substring(1);
}

From source file:PrimeCheck.java

public PrimeCheck() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel pnl = new JPanel();
    JButton btnCheck = new JButton("Check");
    ActionListener al;// w  w w  . j a v a  2  s. c  o m
    al = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                BigInteger bi = new BigInteger("1234567");
                System.out.println("One moment...");
                new PrimeCheckTask(bi).execute();
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid input");
            }
        }
    };
    btnCheck.addActionListener(al);
    pnl.add(btnCheck);
    getContentPane().add(pnl, BorderLayout.NORTH);
    pack();
    setResizable(false);
    setVisible(true);
}

From source file:CRC32HashBuilder.java

/**
 * {@inheritDoc}/*from   w w w . j  a  va 2s.co m*/
 */
public String getHash(final InputStream input) throws IOException {
    if (input == null) {
        throw new IllegalArgumentException("Content cannot be null!");
    }
    final Checksum checksum = new CRC32();
    final byte[] bytes = new byte[1024];
    int len = 0;
    while ((len = input.read(bytes)) >= 0) {
        checksum.update(bytes, 0, len);
    }

    final String hash = new BigInteger(Long.toString(checksum.getValue())).toString(16);
    return hash;
}

From source file:kltn.dao.UserDAO.java

public boolean login(String username, String password) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    String md5 = new BigInteger(DigestUtils.md5(password)).toString(16);
    System.out.println(md5);/* ww  w .  j  a v  a  2  s.  c om*/
    List<String> list = null;
    Transaction tx = null;
    try {

        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(User.class);
        cr.add(Restrictions.eq("username", username));
        cr.add(Restrictions.eq("password", md5));
        list = cr.list();
        System.out.println(list.size());
        tx.commit();
    } catch (HibernateException he) {
        if (tx != null && tx.isActive()) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return (list.size() == 1);
}

From source file:Main.java

public static BigInteger getBigInteger(Object value) {
    BigInteger ret = null;/*from  ww w .  j  a  va2 s .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:jp.co.ntts.vhut.util.MacConversionUtil.java

/**
 * ??????./*from  w  ww .  j  av  a2 s. com*/
 * @param mac 
 * @param macStart 
 * @return ?
 */
public static int getMacAddressOrder(String mac, String macStart) {
    BigInteger biMacTarget = new BigInteger(addrToByte(mac));
    BigInteger biMacStart = new BigInteger(addrToByte(macStart));
    return biMacTarget.subtract(biMacStart).intValue();
}

From source file:PalidromeArray.java

public static PalidromeArray fromString(String s) {
    String[] arr = s.split("\\|");
    BigInteger[] bi = new BigInteger[arr.length];
    for (int i = 0; i < arr.length; i++)
        bi[i] = new BigInteger(arr[i]);

    return new PalidromeArray(bi);
}

From source file:com.l2jfree.util.HexUtil.java

/**
 * Converts a byte array to a legacy HexID.
 * /*www. jav a2 s. c o m*/
 * @param hex a byte array
 * @return HexID
 */
public static String hexToString(byte[] hex) {
    if (hex == null)
        return "null";

    return new BigInteger(hex).toString(16);
}