Example usage for java.math BigInteger ZERO

List of usage examples for java.math BigInteger ZERO

Introduction

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

Prototype

BigInteger ZERO

To view the source code for java.math BigInteger ZERO.

Click Source Link

Document

The BigInteger constant zero.

Usage

From source file:org.hyperledger.common.ByteUtils.java

/**
 * convert a byte array to a human readable base58 string. Base58 is a Bitcoin specific encoding similar to widely used base64 but avoids using characters
 * of similar shape, such as 1 and l or O an 0
 *
 * @param b/* w  w  w .java 2s.  c om*/
 * @return
 */
public static String toBase58(byte[] b) {
    if (b.length == 0) {
        return "";
    }

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

    StringBuilder s = new StringBuilder();
    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:ec.edu.distri.clientejava.protocolo.model.ServicioAdicional.java

public ServicioAdicional() {
    costo = new BigDecimal(BigInteger.ZERO);

}

From source file:Util.java

public static BigInteger bitwiseGcd(BigInteger u, BigInteger v) {
    if (u.equals(BigInteger.ZERO))
        return v;
    if (v.equals(BigInteger.ZERO))
        return u;

    //      System.out.format("u=%s=%s\nu.getLowestSetBit()=%s\n%s>>%s=%s = %s\n", u, u.toString(2), u.getLowestSetBit(), u, u.getLowestSetBit(), u.shiftRight(u.getLowestSetBit()), u.shiftRight(u.getLowestSetBit()).toString(2));

    int uBit = u.getLowestSetBit();
    int vBit = v.getLowestSetBit();
    int k = (uBit <= vBit ? uBit : vBit);

    while (u.signum() > 0) {
        // first ensure that both are odd
        u = u.shiftRight(u.getLowestSetBit());
        v = v.shiftRight(v.getLowestSetBit());
        if (u.subtract(v).signum() >= 0) {
            u = (u.subtract(v)).shiftRight(1);
        } else {//from  w  w w  .  ja v a 2s  . c om
            v = (v.subtract(u)).shiftRight(1);
        }
    }

    return v.shiftLeft(k);
}

From source file:cc.redberry.core.number.NumberUtils.java

public static Rational createRational(BigFraction fraction) {
    //FUTURE investigate performance
    if (fraction.getNumerator().equals(BigInteger.ZERO))
        return Rational.ZERO;
    if (BigFraction.ONE.equals(fraction))
        return Rational.ONE;
    return new Rational(fraction);
}

From source file:com.spotify.hdfs2cass.CassandraPartitionerTest.java

@Test
public void testGetPartition() throws Exception {
    final int maxNodes = 5;

    final List<String> tokenRanges = new ArrayList<String>();

    BigInteger start = BigInteger.ZERO;
    BigInteger step = RandomPartitioner.MAXIMUM.divide(BigInteger.valueOf(maxNodes));
    for (int i = 0; i < maxNodes - 1; i++) {
        BigInteger end = start.add(step);

        tokenRanges.add(String.format("%d:%d", start, end));
        start = end.add(BigInteger.ONE);
    }/* w w  w  .j av  a2  s. c  o  m*/

    tokenRanges.add(String.format("%d:0", start));

    final JobConf conf = new JobConf();
    conf.set(ClusterInfo.SPOTIFY_CASSANDRA_TOKENS_PARAM, StringUtils.join(tokenRanges, ","));
    conf.set(ClusterInfo.SPOTIFY_CASSANDRA_PARTITIONER_PARAM, "org.apache.cassandra.dht.RandomPartitioner");

    CassandraPartitioner instance = new CassandraPartitioner();
    instance.configure(conf);

    Text key = new Text("foobar");
    assertEquals(2, instance.getPartition(key, null, 5));

    key = new Text("someotherkey");
    assertEquals(1, instance.getPartition(key, null, 5));

    key = new Text("1ce5cf4b861941f4aa799ae39ac9daa4");
    assertEquals(4, instance.getPartition(key, null, 5));
}

From source file:me.ferrybig.javacoding.webmapper.test.session.DefaultDataStorageTest.java

@Test
public void getDataAsSupportsOneBackendSuperCastTypeTest() {
    Object o;//from   w ww . j av a2s  .c om
    data.setData(Collections.singleton(o = BigInteger.ZERO));
    assertEquals(o, extr(data.getDataAs(Object.class)));
}

From source file:com.ar.dev.tierra.api.dao.impl.FiscalDAOImpl.java

@Override
public void ticket(List<DetalleFactura> detalles) {
    try (PrintWriter ticket = new PrintWriter("command/ticket.200")) {
        DecimalFormat decimalFormat = new DecimalFormat();
        decimalFormat.setMaximumFractionDigits(1);
        ticket.println("@" + (char) 28 + "T" + (char) 28 + "T");
        BigDecimal descuento = new BigDecimal(BigInteger.ZERO);
        for (DetalleFactura detalle : detalles) {
            if (detalle.getDescuentoDetalle() != null) {
                descuento = descuento.add(detalle.getDescuentoDetalle());
            }/* w  ww.  j a  v  a2  s.  c o  m*/
            String price = null;
            BigDecimal sinIVA = detalle.getProducto().getPrecioVenta().subtract(detalle.getProducto()
                    .getPrecioVenta().multiply(new BigDecimal(17.35)).divide(new BigDecimal(100)));
            price = sinIVA.setScale(4, RoundingMode.HALF_UP).toString();
            ticket.println("B" + (char) 28 /*Abrimos linea*/
                    + detalle.getProducto().getDescripcion() + (char) 28 /*Nombre producto*/
                    + detalle.getCantidadDetalle() + ".0" + (char) 28 /*Cantidad*/
                    + price.replace(",", ".") + (char) 28 /*Precio unitario*/
                    + "21.0" + (char) 28 /*Impuestos IVA*/
                    + "M" + (char) 28 /*Suma monto*/
                    + "0.0" + (char) 28 /*Impuestos internos*/
                    + "0" + (char) 28 /*Parametro display*/
                    + "b");
            /*Cierra de linea*/
        }
        if (!descuento.equals(new BigDecimal(BigInteger.ZERO))) {
            ticket.println("T" + (char) 28 /*Abrimos linea descuento*/
                    + "Descuento: " + (char) 28 /*Texto a mostrar*/
                    + descuento + (char) 28 /*Monto descuento*/
                    + "m" + (char) 28 /*m: descuento, M: aumento*/
                    + "0" + (char) 28 /*parametro display*/
                    + "T");
            /*cierre linea descuento*/
        }
        ticket.println("E");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(FiscalDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:RandomUtil.java

public static BigInteger randomBitFlip(BigInteger n) {
    if (n.equals(BigInteger.ONE))
        return BigInteger.ONE;
    if (n.equals(BigInteger.ZERO))
        return BigInteger.ZERO;

    BigInteger toRet = BigInteger.ONE;
    while (toRet.equals(BigInteger.ONE) || toRet.equals(BigInteger.ZERO)) {
        byte[] bytes = n.toByteArray();
        getInstance().random.nextBytes(bytes);
        // could allow up to maxExclusive by converting and checking value
        // but this is faster, even if it doesn't give us full range
        bytes[0] = 0;//from   ww  w  . j  a v a 2s. c  om
        toRet = new BigInteger(bytes);
    }
    return toRet;
}

From source file:com.artivisi.iso8583.Message.java

public void calculateBitmap() {
    LOGGER.debug("Number of active Data Element [{}]", dataElementContent.size());
    BigInteger bitmap = BigInteger.ZERO.setBit(128);
    for (Integer de : dataElementContent.keySet()) {
        LOGGER.debug("Set active flag for Data Element [{}]", de);
        if (de > 64) {
            bitmap = bitmap.setBit(128 - 1);
        }/*w  ww  . j  a v a2s.c om*/
        bitmap = bitmap.setBit(128 - de);
    }
    LOGGER.debug("Final bitmap bin : [{}]", bitmap.toString(2).substring(1));
    LOGGER.debug("Final bitmap hex : [{}]", bitmap.toString(16).substring(1));
    setPrimaryBitmapStream(StringUtils.rightPad(bitmap.toString(16).substring(1, 16), 16, "0"));
    if (bitmap.testBit(128 - 1)) {
        setSecondaryBitmapStream(StringUtils.rightPad(bitmap.toString(16).substring(17), 16, "0"));
    }
}

From source file:io.ecarf.core.cloud.task.processor.reason.phase1.SaveResultsSubTask.java

@Override
public Void call() throws Exception {

    BigInteger rows = BigInteger.ZERO;
    Long bytes = 0L;/*  www. j a v  a 2 s  .  c o m*/

    try {
        // block and wait for each job to complete then save results to a file

        QueryStats stats = this.cloud.saveBigQueryResultsToFile(term.getJobId(), term.getFilename());
        rows = stats.getTotalRows();
        bytes = stats.getTotalProcessedBytes();

    } catch (IOException ioe) {
        // transient backend errors
        log.warn("failed to save query results to file, jobId: " + term.getJobId(), ioe);
    }

    log.info("Query found " + rows + ", rows");

    term.setRows(rows).setBytes(bytes);

    return null;
}