Example usage for java.math BigInteger ONE

List of usage examples for java.math BigInteger ONE

Introduction

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

Prototype

BigInteger ONE

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

Click Source Link

Document

The BigInteger constant one.

Usage

From source file:org.apache.juddi.v3.tck.JUDDI_300_MultiNodeIntegrationTest.java

public static void testSetupReplicationConfig() {
    //this only runs if it is JUDDI and Replication is enabled
    if (!TckPublisher.isReplicationEnabled() || !TckPublisher.isJUDDI()) {
        logger.info("TCK says that replication is disabled...skipping replication config...");
        return;// ww w  .  j a v  a  2  s  .  co m
    }
    try {
        init();
        refreshTokens();
        logger.info("fetching current replication config...");

        ReplicationConfiguration replicationNode1 = null;
        try {
            replicationNode1 = juddiApiServiceNode1.getReplicationNodes(rootNode1Token);
        } catch (Exception ex) {
            System.out.println("Error getting replication config");
            ex.printStackTrace();
            Assert.fail(ex.getMessage());

        }
        //if (replicationNode1.getCommunicationGraph() == null) {
        replicationNode1.setCommunicationGraph(new CommunicationGraph());
        //}

        replicationNode1.getOperator().clear();
        replicationNode1.getSignature().clear();

        Operator op = new Operator();
        op.setOperatorNodeID("uddi:juddi.apache.org:node1");
        op.setSoapReplicationURL(manager.getClientConfig().getUDDINode(CFG_node1_MARY).getReplicationUrl());
        op.setOperatorStatus(OperatorStatusType.NORMAL);
        op.getContact().add(new Contact());
        op.getContact().get(0).getPersonName().add(new PersonName("bob", "en"));
        op.getContact().get(0).setUseType("admin");
        //if (!Contains(replicationNode1.getOperator(), op)) {
        replicationNode1.getOperator().add(op);
        //}

        op = new Operator();
        op.setOperatorNodeID("uddi:another.juddi.apache.org:node2");
        op.setSoapReplicationURL(manager.getClientConfig().getUDDINode(CFG_node2_SAM).getReplicationUrl());
        op.setOperatorStatus(OperatorStatusType.NORMAL);
        op.getContact().add(new Contact());
        op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
        op.getContact().get(0).setUseType("admin");
        //if (!Contains(replicationNode1.getOperator(), op)) 
        {
            replicationNode1.getOperator().add(op);
        }
        //if (!replicationNode1.getCommunicationGraph().getNode().contains("uddi:another.juddi.apache.org:node2")) {
        replicationNode1.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2");
        //}
        //if (!replicationNode1.getCommunicationGraph().getNode().contains("uddi:juddi.apache.org:node1")) {
        replicationNode1.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1");
        //}
        replicationNode1.setSerialNumber(0L);
        replicationNode1.setTimeOfConfigurationUpdate("");
        replicationNode1.setMaximumTimeToGetChanges(BigInteger.ONE);
        replicationNode1.setMaximumTimeToSyncRegistry(BigInteger.ONE);

        if (replicationNode1.getRegistryContact().getContact() == null) {
            replicationNode1.getRegistryContact().setContact(new Contact());
            replicationNode1.getRegistryContact().getContact().getPersonName()
                    .add(new PersonName("unknown", null));
        }

        if (TckCommon.isDebug()) {
            JAXB.marshal(replicationNode1, System.out);
        }

        logger.info(manager.getClientConfig().getConfigurationFile()
                + " Setting replication config on Node 1...@" + ((BindingProvider) juddiApiServiceNode1)
                        .getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
        logger.info("Setting replication url on Node 1...@"
                + manager.getClientConfig().getUDDINode(CFG_node1_MARY).getReplicationUrl());
        juddiApiServiceNode1.setReplicationNodes(rootNode1Token, replicationNode1);
        logger.info("Setting replication config on Node 2...@" + ((BindingProvider) juddiApiServiceNode2)
                .getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
        logger.info("Setting replication url on Node 2...@"
                + manager.getClientConfig().getUDDINode(CFG_node2_SAM).getReplicationUrl());
        juddiApiServiceNode2.setReplicationNodes(rootNode2Token, replicationNode1);

    } catch (Exception ex) {
        TckCommon.PrintMarker();
        ex.printStackTrace();
        TckCommon.PrintMarker();
    }
}

From source file:net.pms.util.Rational.java

/**
 * Returns an instance that represents the value of {@code value}.
 *
 * @param value the value.//ww w  .  j a v  a  2 s  .c o  m
 * @return An instance that represents the value of {@code value}.
 */
@Nonnull
public static Rational valueOf(long value) {
    BigInteger numerator = BigInteger.valueOf(value);
    return new Rational(numerator, BigInteger.ONE, BigInteger.ONE, numerator, BigInteger.ONE);
}

From source file:com.amazonaws.services.kinesis.clientlibrary.proxies.KinesisLocalFileProxy.java

@Override
public GetRecordsResult get(String serializedKinesisIterator, int maxRecords)
        throws ResourceNotFoundException, InvalidArgumentException, ExpiredIteratorException {
    IteratorInfo iterator = deserializeIterator(serializedKinesisIterator);

    BigInteger startingPosition = new BigInteger(iterator.sequenceNumber);
    BigInteger lastRecordsSeqNo = BigInteger.ONE;
    List<Record> recordsToReturn = new ArrayList<Record>();
    List<Record> shardRecords = shardedDataRecords.get(iterator.shardId);
    if (shardRecords == null) {
        throw new ResourceNotFoundException(iterator.shardId + " does not exist");
    }//from  w w  w.  ja va2s  .c  o m

    boolean isHasMoreShards = false;

    for (int i = 0; i < shardRecords.size(); i++) {
        Record record = shardRecords.get(i);
        BigInteger recordSequenceNumber = new BigInteger(record.getSequenceNumber());
        // update lastRecordsSeqNo so if we return no records, it will be the seqNo of the last record.
        lastRecordsSeqNo = recordSequenceNumber;
        if (recordSequenceNumber.compareTo(startingPosition) >= 0) {
            // Set endIndex (of sublist) to cap at either maxRecords or end of list.
            int endIndex = Math.min(i + maxRecords, shardRecords.size());
            recordsToReturn.addAll(shardRecords.subList(i, endIndex));

            lastRecordsSeqNo = new BigInteger(shardRecords.get(endIndex - 1).getSequenceNumber());
            if (endIndex < shardRecords.size()) {
                isHasMoreShards = true;
            }

            break;
        }
    }

    GetRecordsResult response = new GetRecordsResult();
    response.setRecords(recordsToReturn);

    // Set iterator only if the shard is not closed.
    if (isHasMoreShards || (!closedShards.contains(iterator.shardId))) {
        /*
         * Use the sequence number of the last record returned + 1 to compute the next iterator.
         */
        response.setNextShardIterator(
                serializeIterator(iterator.shardId, lastRecordsSeqNo.add(BigInteger.ONE).toString()));
        LOG.debug("Returning a non null iterator for shard " + iterator.shardId);
    } else {
        LOG.info("Returning null iterator for shard " + iterator.shardId);
    }

    return response;
}

From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#getNotClosedIssuesId(java.util.Calendar)}.
 *///w w  w  .  j  a  v  a2 s .  co  m
@Test
public void testGetNotClosedIssuesId() {

    final Calendar cal = Calendar.getInstance();
    final Calendar cal2 = Calendar.getInstance();
    cal2.add(Calendar.MINUTE, 10);

    final Timestamp before = new java.sql.Timestamp(cal.getTimeInMillis());
    final Timestamp after = new java.sql.Timestamp(cal2.getTimeInMillis());

    final Operation op = sequenceOf(
            insertInto("mantis_project_table").columns("id", "name").values(1, "project_1")
                    .values(2, "project_2").build(),

            insertInto("mantis_enum_status").columns("id", "name").values(1, "Open").values(90, "Close")
                    .build(),

            insertInto("mantis_bug_table").columns("id", "project_id", "summary", "last_sync", "status_id")
                    .values(1, 1, "sum", before, 1).values(2, 1, "sum", after, 1)
                    .values(3, 1, "sum", before, 90).values(4, 2, "sum", before, 1).build());

    lauchOperation(op);

    cal.add(Calendar.MINUTE, 5);

    final List<BigInteger> list = dao.getNotClosedIssuesId(cal, BigInteger.ONE);
    assertEquals(1, list.size());
    assertEquals(BigInteger.ONE, list.get(0));
}

From source file:org.estatio.dom.invoice.Invoice.java

@Programmatic
public BigInteger nextItemSequence() {
    BigInteger nextItemSequence = getLastItemSequence() == null ? BigInteger.ONE
            : getLastItemSequence().add(BigInteger.ONE);
    setLastItemSequence(nextItemSequence);
    return nextItemSequence;
}

From source file:org.hyperledger.fabric.sdk.MemberServicesImpl.java

/**
 * Process a batch of tcerts after having retrieved them from the TCA.
 *//*from  ww w . j av a  2  s  .c  o  m*/
private List<TCert> processTCertBatch(GetTCertBatchRequest req, TCertCreateSetResp resp)
        throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException,
        BadPaddingException, InvalidAlgorithmParameterException, CryptoException, IOException {
    String enrollKey = req.getEnrollment().getKey();
    byte[] tCertOwnerKDFKey = resp.getCerts().getKey().toByteArray();
    List<Ca.TCert> tCerts = resp.getCerts().getCertsList();

    byte[] byte1 = new byte[] { 1 };
    byte[] byte2 = new byte[] { 2 };

    byte[] tCertOwnerEncryptKey = Arrays.copyOfRange(cryptoPrimitives.calculateMac(tCertOwnerKDFKey, byte1), 0,
            32);
    byte[] expansionKey = cryptoPrimitives.calculateMac(tCertOwnerKDFKey, byte2);

    List<TCert> tCertBatch = new ArrayList<>(tCerts.size());

    // Loop through certs and extract private keys
    for (Ca.TCert tCert : tCerts) {
        X509Certificate x509Certificate;
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            x509Certificate = (X509Certificate) cf.generateCertificate(tCert.getCert().newInput());
        } catch (Exception ex) {
            logger.debug("Warning: problem parsing certificate bytes; retrying ... ", ex);
            continue;
        }

        // extract the encrypted bytes from extension attribute
        byte[] tCertIndexCT = fromDer(x509Certificate.getExtensionValue(TCERT_ENC_TCERT_INDEX));
        byte[] tCertIndex = cryptoPrimitives.aesCBCPKCS7Decrypt(tCertOwnerEncryptKey, tCertIndexCT);

        byte[] expansionValue = cryptoPrimitives.calculateMac(expansionKey, tCertIndex);

        // compute the private key
        BigInteger k = new BigInteger(1, expansionValue);
        BigInteger n = ((ECPrivateKey) cryptoPrimitives.ecdsaKeyFromPrivate(Hex.decode(enrollKey)))
                .getParameters().getN().subtract(BigInteger.ONE);
        k = k.mod(n).add(BigInteger.ONE);

        BigInteger D = ((ECPrivateKey) cryptoPrimitives.ecdsaKeyFromPrivate(Hex.decode(enrollKey))).getD()
                .add(k);
        D = D.mod(((ECPrivateKey) cryptoPrimitives.ecdsaKeyFromPrivate(Hex.decode(enrollKey))).getParameters()
                .getN());

        // Put private and public key in returned tcert
        TCert tcert = new TCert(tCert.getCert().toByteArray(), cryptoPrimitives.ecdsaKeyFromBigInt(D));

        tCertBatch.add(tcert);
    }

    if (tCertBatch.size() == 0) {
        throw new RuntimeException("Failed fetching TCertBatch. No valid TCert received.");
    }

    return tCertBatch;
}

From source file:net.pms.util.Rational.java

/**
 * Returns an instance that represents the value of {@code value}.
 *
 * @param value the value.//  www .  j  ava  2  s  .c  o  m
 * @return An instance that represents the value of {@code value}.
 */
@Nullable
public static Rational valueOf(@Nullable BigInteger value) {
    if (value == null) {
        return null;
    }
    return new Rational(value, BigInteger.ONE, BigInteger.ONE, value, BigInteger.ONE);
}

From source file:org.lwes.EventTest.java

@Test
public void testIntBounds() {
    final Event evt = createEvent();
    evt.setEventName("Test");

    evt.setByte("byte_min", Byte.MIN_VALUE);
    evt.setByte("byte_zero", (byte) 0);
    evt.setByte("byte_one", (byte) 1);
    evt.setByte("byte_max", Byte.MAX_VALUE);

    evt.setInt16("int16_min", Short.MIN_VALUE);
    evt.setInt16("int16_zero", (short) 0);
    evt.setInt16("int16_one", (short) 1);
    evt.setInt16("int16_max", Short.MAX_VALUE);

    evt.setInt32("int32_min", Integer.MIN_VALUE);
    evt.setInt32("int32_zero", 0);
    evt.setInt32("int32_one", 1);
    evt.setInt32("int32_max", Integer.MAX_VALUE);

    evt.setInt64("int64_min", Long.MIN_VALUE);
    evt.setInt64("int64_zero", 0);
    evt.setInt64("int64_one", 1);
    evt.setInt64("int64_max", Long.MAX_VALUE);

    evt.setUInt16("uint16_zero", 0);
    evt.setUInt16("uint16_one", 1);
    evt.setUInt16("uint16_max", 0xffff);

    evt.setUInt32("uint32_zero", 0);
    evt.setUInt32("uint32_one", 1);
    evt.setUInt32("uint32_max", 0xffffffffL);

    evt.setUInt64("uint64_zero", BigInteger.ZERO);
    evt.setUInt64("uint64_one", BigInteger.ONE);
    evt.setUInt64("uint64_max", BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE));

    evt.setInt16Array("int16[]", new short[] { Short.MIN_VALUE, 0, 1, Short.MAX_VALUE });
    evt.setInt32Array("int32[]", new int[] { Integer.MIN_VALUE, 0, 1, Integer.MAX_VALUE });
    evt.setInt64Array("int64[]", new long[] { Long.MIN_VALUE, 0, 1, Long.MAX_VALUE });
    evt.setUInt16Array("uint16[]", new int[] { 0, 1, 0xffff });
    evt.setUInt32Array("uint32[]", new long[] { 0, 1, 0xffffffffL });
    evt.setUInt64Array("uint64[]", new BigInteger[] { BigInteger.ZERO, BigInteger.ONE,
            BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE) });
    evt.setUInt64Array("uint64[] prim", new long[] { 0, 1, -1 });

    final Event evt2 = createEvent();
    evt2.deserialize(evt.serialize());/* w  ww .  j  av a  2 s.c  om*/
    //assertEquals(evt, evt2);

    assertEquals(Byte.MIN_VALUE, evt.getByte("byte_min").byteValue());
    assertEquals((byte) 0, evt.getByte("byte_zero").byteValue());
    assertEquals((byte) 1, evt.getByte("byte_one").byteValue());
    assertEquals(Byte.MAX_VALUE, evt.getByte("byte_max").byteValue());

    assertEquals(Short.MIN_VALUE, evt.getInt16("int16_min").shortValue());
    assertEquals((short) 0, evt.getInt16("int16_zero").shortValue());
    assertEquals((short) 1, evt.getInt16("int16_one").shortValue());
    assertEquals(Short.MAX_VALUE, evt.getInt16("int16_max").shortValue());

    assertEquals(Integer.MIN_VALUE, evt.getInt32("int32_min").intValue());
    assertEquals(0, evt.getInt32("int32_zero").intValue());
    assertEquals(1, evt.getInt32("int32_one").intValue());
    assertEquals(Integer.MAX_VALUE, evt.getInt32("int32_max").intValue());

    assertEquals(Long.MIN_VALUE, evt.getInt64("int64_min").longValue());
    assertEquals(0, evt.getInt64("int64_zero").longValue());
    assertEquals(1, evt.getInt64("int64_one").longValue());
    assertEquals(Long.MAX_VALUE, evt.getInt64("int64_max").longValue());

    assertEquals(0, evt.getUInt16("uint16_zero").intValue());
    assertEquals(1, evt.getUInt16("uint16_one").intValue());
    assertEquals(0xffff, evt.getUInt16("uint16_max").intValue());

    assertEquals(0, evt.getUInt32("uint32_zero").longValue());
    assertEquals(1, evt.getUInt32("uint32_one").longValue());
    assertEquals(0xffffffffL, evt.getUInt32("uint32_max").longValue());

    assertEquals(BigInteger.ZERO, evt.getUInt64("uint64_zero"));
    assertEquals(BigInteger.ONE, evt.getUInt64("uint64_one"));
    assertEquals(BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE), evt.getUInt64("uint64_max"));

    assertArrayEquals(new short[] { Short.MIN_VALUE, 0, 1, Short.MAX_VALUE }, evt.getInt16Array("int16[]"));
    assertArrayEquals(new int[] { Integer.MIN_VALUE, 0, 1, Integer.MAX_VALUE }, evt.getInt32Array("int32[]"));
    assertArrayEquals(new long[] { Long.MIN_VALUE, 0, 1, Long.MAX_VALUE }, evt.getInt64Array("int64[]"));
    assertArrayEquals(new int[] { 0, 1, 0xffff }, evt.getUInt16Array("uint16[]"));
    assertArrayEquals(new long[] { 0, 1, 0xffffffffL }, evt.getUInt32Array("uint32[]"));
    assertArrayEquals(new BigInteger[] { BigInteger.ZERO, BigInteger.ONE,
            BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE) }, evt.getUInt64Array("uint64[]"));
    assertArrayEquals(
            new BigInteger[] { BigInteger.ZERO, BigInteger.ONE,
                    BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE) },
            evt.getUInt64Array("uint64[] prim"));
}

From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaBuilder.java

private void registerComplexTypeChildElement(ExplicitGroup all, String name, String description, DataType type,
        boolean required) {
    name = hyphenize(name);/*from   w w w  . j a  v a2  s . c o m*/

    // this top level element is for declaring the object inside a config or operation
    TopLevelElement objectElement = new TopLevelElement();
    objectElement.setName(name);
    objectElement.setMinOccurs(required ? BigInteger.ONE : BigInteger.ZERO);
    objectElement.setMaxOccurs("1");
    objectElement.setComplexType(newLocalComplexTypeWithBase(type, description));
    objectElement.setAnnotation(createDocAnnotation(description));

    all.getParticle().add(objectFactory.createElement(objectElement));
}

From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java

private void stepThree(final int i) throws Exception {
    BigInteger n = this.pubKey.getModulus();
    BigInteger r;/*from  ww w  .ja  v  a  2s  . c  om*/
    BigInteger upperBound;
    BigInteger lowerBound;
    BigInteger max;
    BigInteger min;
    BigInteger[] tmp;
    ArrayList<Interval> ms = new ArrayList<>(15);

    for (Interval interval : this.m) {
        upperBound = step3ComputeUpperBound(this.si, n, interval.upper);
        lowerBound = step3ComputeLowerBound(this.si, n, interval.lower);

        r = lowerBound;
        // lowerBound <= r <= upperBound
        while (r.compareTo(upperBound) < 1) {
            // ceil((2*B+r*n)/si)
            max = (BigInteger.valueOf(2).multiply(this.bigB)).add(r.multiply(n));
            tmp = max.divideAndRemainder(this.si);
            if (BigInteger.ZERO.compareTo(tmp[1]) != 0) {
                max = tmp[0].add(BigInteger.ONE);
            } else {
                max = tmp[0];
            }

            // floor((3*B-1+r*n)/si
            min = BigInteger.valueOf(3).multiply(this.bigB);
            min = min.subtract(BigInteger.ONE);
            min = min.add(r.multiply(n));
            min = min.divide(this.si);

            // build new interval
            if (interval.lower.compareTo(max) > 0) {
                max = interval.lower;
            }
            if (interval.upper.compareTo(min) < 0) {
                min = interval.upper;
            }
            if (max.compareTo(min) <= 0) {
                ms.add(new Interval(max, min));
            }
            // one further....
            r = r.add(BigInteger.ONE);
        }
    }

    loggerInstance.log(getClass(), " # of intervals for M" + i + ": " + ms.size(), Logger.LogLevel.INFO);

    if (ms.size() == 0) {
        throw new Exception("Zero intervals left, validity oracle seems to be wrong!");
    }

    this.m = ms.toArray(new Interval[ms.size()]);
}