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:com.offbynull.peernetic.common.identification.Id.java

/**
 * Adds two IDs together. The limit of the IDs must match.
 * @param lhs right-hand side/*from   w  ww .  j  a v  a 2 s .  c  o  m*/
 * @param rhs right-hand side
 * @return {@code lhs + rhs}, wrapped if it exceeds the limit
 * @throws NullPointerException if any argument is {@code null}
 * @throws IllegalArgumentException if the limit from {@code lhs} doesn't match the limit from {@code rhs}
 */
public static Id add(Id lhs, Id rhs) {
    Validate.notNull(lhs);
    Validate.notNull(rhs);
    Validate.isTrue(lhs.limit.equals(rhs.limit));

    BigInteger added = lhs.data.add(rhs.data);
    if (added.compareTo(lhs.limit) > 0) {
        added = added.subtract(lhs.limit).subtract(BigInteger.ONE);
    }

    Id addedId = new Id(added, lhs.limit);

    return addedId;
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsVersionsWriterTest.java

/**
 * Build the items to write.// w w w  . j  a  v a 2  s .c o m
 *
 * @return items
 */
private List<ProjectVersionData> buildItems() {
    final List<ProjectVersionData> items = new ArrayList<ProjectVersionData>();

    final ProjectVersionData item1 = new ProjectVersionData();
    item1.setId(BigInteger.ONE);
    item1.setName("new_version_1");
    item1.setProject_id(BigInteger.ONE);

    final ProjectVersionData item2 = new ProjectVersionData();
    item2.setId(BigInteger.valueOf(2));
    item2.setName("new_version_2");
    item2.setProject_id(BigInteger.ONE);

    items.add(item1);
    items.add(item2);

    return items;
}

From source file:org.sonar.plugins.mantis.MantisSensorTest.java

@Before
public void setUp() throws Exception {
    final MantisSoapService service = new MantisSoapService(null) {

        @Override//from www  .j ava  2 s  .co  m
        protected MantisConnectLocator createMantisConnectLocator() {
            MantisConnectLocator locator = mock(MantisConnectLocator.class);
            MantisConnectPortType portType = mock(MantisConnectPortType.class);
            String[] status = new String[] { "new", "feedback", "acknowledged", "confirmed", "assigned",
                    "resolved", "validated", "closed" };
            String[] priorities = new String[] { "low", "normal", "high", "urgent", "immediate" };
            String[] users = new String[] { "user1", "user2", "user3", "user4", "user5", "user6", "user7",
                    "user8", "user9", "user10", "user11", "user12", "user13", "user14", "user15", "user16",
                    "user17", "user18", "user19", "user20" };

            try {
                List<IssueData> issues = new ArrayList<IssueData>();
                for (int i = 0; i < 1000; i++) {
                    IssueData issue = new IssueData();
                    issue.setId(BigInteger.valueOf(i + 1));
                    issue.setPriority(new ObjectRef(BigInteger.valueOf(i % 5), priorities[i % 5]));
                    issue.setStatus(new ObjectRef(BigInteger.valueOf(i % 8), status[i % 8]));
                    issue.setHandler(new AccountData(BigInteger.valueOf(i % 20), users[i % 20], users[i % 20],
                            users[i % 20] + "@gmail.com"));
                    issues.add(issue);
                }
                FilterData filter = new FilterData(BigInteger.ONE, null, BigInteger.ONE, true,
                        "current-version", "", "");
                when(locator.getMantisConnectPort()).thenReturn(portType);
                when(portType.mc_project_get_id_from_name("jer", "pwd", "myproject"))
                        .thenReturn(BigInteger.ONE);
                when(portType.mc_filter_get("jer", "pwd", BigInteger.ONE))
                        .thenReturn(new FilterData[] { filter });
                when(portType.mc_filter_get_issues("jer", "pwd", BigInteger.ONE, filter.getId(), BigInteger.ONE,
                        BigInteger.valueOf(50)))
                                .thenReturn((IssueData[]) issues.toArray(new IssueData[issues.size()]));
            } catch (Exception e) {
                fail();
            }
            return locator;
        }
    };

    sensor = new MantisSensor() {

        protected MantisSoapService createMantisSoapService() throws RemoteException {
            return service;
        }
    };
}

From source file:net.ripe.rpki.commons.provisioning.x509.ProvisioningIdentityCertificateBuilder.java

private void setUpImplicitRequirementsForBuilderHelper() {
    builderHelper.withSerial(BigInteger.ONE); // Self-signed! So this is the first!
    builderHelper.withValidityPeriod(//from ww  w  .j a  v a2 s. c om
            new ValidityPeriod(new DateTime(), new DateTime().plusYears(DEFAULT_VALIDITY_TIME_YEARS_FROM_NOW)));
    builderHelper.withCa(true);
    builderHelper.withKeyUsage(KeyUsage.keyCertSign | KeyUsage.cRLSign);
}

From source file:com.dianping.puma.datahandler.AbstractDataHandler.java

protected Object convertUnsignedValueIfNeeded(int pos, Object value, TableMetaInfo tableMeta) {
    Object newValue = value;/*from   ww  w .j  a va  2s .co  m*/
    if (value != null) {
        switch (tableMeta.getRawTypeCodes().get(pos)) {
        case BinlogConstants.MYSQL_TYPE_TINY:
            if ((value instanceof Integer) && (Integer) value < 0 && !tableMeta.getSignedInfos().get(pos)) {
                newValue = Integer.valueOf((Integer) value + (1 << 8));
            }
            break;
        case BinlogConstants.MYSQL_TYPE_INT24:
            if ((value instanceof Integer) && (Integer) value < 0 && !tableMeta.getSignedInfos().get(pos)) {
                newValue = Integer.valueOf((Integer) value + (1 << 24));
            }
            break;
        case BinlogConstants.MYSQL_TYPE_SHORT:
            if ((value instanceof Integer) && (Integer) value < 0 && !tableMeta.getSignedInfos().get(pos)) {
                newValue = Integer.valueOf((Integer) value + (1 << 16));
            }
            break;
        case BinlogConstants.MYSQL_TYPE_INT:
            if ((value instanceof Integer) && (Integer) value < 0 && !tableMeta.getSignedInfos().get(pos)) {
                newValue = Long.valueOf((Integer) value) + (1L << 32);
            } else {
                if (value instanceof Integer) {
                    newValue = Long.valueOf((Integer) value);
                }
            }
            break;
        case BinlogConstants.MYSQL_TYPE_LONGLONG:
            if ((value instanceof Long) && (Long) value < 0 && !tableMeta.getSignedInfos().get(pos)) {
                newValue = BigInteger.valueOf((Long) value).add(BigInteger.ONE.shiftLeft(64));
            } else {
                if (value instanceof Long) {
                    newValue = BigInteger.valueOf((Long) value);
                }
            }
            break;
        default:
            break;
        }

    }
    return newValue;
}

From source file:com.redhat.lightblue.metadata.types.BooleanTypeTest.java

@Test
public void testCompareEqual() {
    assertEquals(booleanType.compare((Object) BigInteger.ONE, (Object) BigInteger.ONE), 0);
}

From source file:com.cloudbees.maven.release.policy.impl.CloudBeesVersionPolicy.java

/**
 * {@inheritDoc}//ww w. j av  a  2s.  c o  m
 */
public VersionPolicyResult getDevelopmentVersion(VersionPolicyRequest versionPolicyRequest)
        throws PolicyException, VersionParseException {
    // this one is harder, we basically want to find the last incrementally updatable segment and bump it
    final VersionPolicyResult result = new VersionPolicyResult();
    String version = versionPolicyRequest.getVersion();
    if (version.endsWith("-SNAPSHOT")) {
        // if it is a -SNAPSHOT already, we shouldn't have been called, so we leave the value as is
        result.setVersion(version);
    } else {
        // find the first version format string (using "-" as separator)
        String[] comps = version.split("-");
        String externalRef = "";
        if (comps.length > 1 && !(version.contains("alpha") || version.contains("ALPHA")
                || version.contains("beta") || version.contains("BETA"))) {
            version = comps[0];
            for (int i = 1; i < comps.length; i++) {
                externalRef += "-" + comps[i];
            }
        }
        // find the last numeric segment and increment that
        Pattern separator = Pattern.compile("([\\.-])");
        Matcher m = separator.matcher(version);
        List<Integer> offsets = new ArrayList<Integer>();
        offsets.add(0);
        while (m.find()) {
            if (m.start() > 0) {
                offsets.add(m.start());
                offsets.add(m.start() + 1);
            }
        }
        offsets.add(version.length());
        boolean matched = false;
        for (int i = offsets.size() - 2; i >= 0; i -= 2) {
            final String segment = version.substring(offsets.get(i), offsets.get(i + 1));
            if (segment.matches("\\d+")) {
                result.setVersion(version.substring(0, offsets.get(i))
                        + new BigInteger(segment).add(BigInteger.ONE).toString()
                        + version.substring(offsets.get(i + 1)) + externalRef + "-SNAPSHOT");
                matched = true;
                break;
            }
            // we will handle -ALPHA -> BETA-1 and .ALPHA -> .BETA.1 (note we add a segment)
            if ("alpha".equals(segment)) {
                // from the regex it is either a '.' or a '-' so charAt is safe from multi-word code points
                char separatorChar = (offsets.get(i) > 0 ? version.charAt(offsets.get(i) - 1) : '-');
                result.setVersion(version.substring(0, offsets.get(i)) + "beta" + separatorChar + "1"
                        + version.substring(offsets.get(i + 1)) + "-SNAPSHOT");
                matched = true;
                break;
            }
            if ("ALPHA".equals(segment)) {
                // from the regex it is either a '.' or a '-' so charAt is safe from multi-word code points
                char separatorChar = (offsets.get(i) > 0 ? version.charAt(offsets.get(i) - 1) : '-');
                result.setVersion(version.substring(0, offsets.get(i)) + "BETA" + separatorChar + "1"
                        + version.substring(offsets.get(i + 1)) + "-SNAPSHOT");
                matched = true;
                break;
            }
            if ("beta".equals(segment)) {
                // from the regex it is either a '.' or a '-' so charAt is safe from multi-word code points
                char separatorChar = (offsets.get(i) > 0 ? version.charAt(offsets.get(i) - 1) : '-');
                result.setVersion(version.substring(0, offsets.get(i)) + "rc" + separatorChar + "1"
                        + version.substring(offsets.get(i + 1)) + "-SNAPSHOT");
                matched = true;
                break;
            }
            if ("BETA".equals(segment)) {
                // from the regex it is either a '.' or a '-' so charAt is safe from multi-word code points
                char separatorChar = (offsets.get(i) > 0 ? version.charAt(offsets.get(i) - 1) : '-');
                result.setVersion(version.substring(0, offsets.get(i)) + "RC" + separatorChar + "1"
                        + version.substring(offsets.get(i + 1)) + "-SNAPSHOT");
                matched = true;
                break;
            }
        }
        if (!matched) {
            throw new VersionParseException("Unsupported version number format: " + version);
        }
    }
    return result;
}

From source file:com.redhat.lightblue.metadata.types.BigIntegerTypeTest.java

@Test
public void testCompareEqual() {
    assertEquals(bigIntegerType.compare((Object) BigInteger.ONE, (Object) BigInteger.ONE), 0);
}

From source file:com.swdouglass.joid.DiffieHellman.java

/**
 * Creates a DiffieHellman instance.//from w  ww  .  ja va  2  s  .c  o  m
 *
 * @param mod the modulus to use. If null, use {@link #DEFAULT_MODULUS}.
 * @param gen the generator to use. If null, use
 * {@link #DEFAULT_GENERATOR}.
 */
public DiffieHellman(BigInteger mod, BigInteger gen) {
    modulus = (mod != null ? mod : DiffieHellman.DEFAULT_MODULUS);
    generator = (gen != null ? gen : DiffieHellman.DEFAULT_GENERATOR);

    int bits = modulus.bitLength();
    BigInteger max = modulus.subtract(BigInteger.ONE);
    while (true) {
        BigInteger pkey = new BigInteger(bits, random);
        if (pkey.compareTo(max) >= 0) { //too large
            continue;
        } else if (pkey.compareTo(BigInteger.ONE) <= 0) {//too small
            continue;
        }
        privateKey = pkey;
        publicKey = generator.modPow(privateKey, modulus);
        break;
    }
}

From source file:com.redhat.lightblue.metadata.types.BooleanTypeTest.java

@Test
public void testCompareNotEqual() {
    assertEquals(booleanType.compare((Object) BigInteger.ZERO, (Object) BigInteger.ONE), -1);
}