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.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertUserIfNotExists(biz.futureware.mantis.rpc.soap.client.AccountData, java.math.BigInteger)}.
 *///from   w w w .  jav  a2s .  c  om
@Test
public void testInsertUserIfNotExistsItemNull() {
    final Operation op = insertInto("mantis_project_table").columns("id", "name").values(1, "project_1")
            .build();

    lauchOperation(op);

    dao.insertUserIfNotExists(null, BigInteger.ONE);
}

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

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

From source file:net.ripe.ipresource.IpRange.java

public List<IpRange> splitToPrefixes() {
    BigInteger rangeEnd = getEnd().getValue();
    BigInteger currentRangeStart = getStart().getValue();
    int startingPrefixLength = getType().getBitSize();
    List<IpRange> prefixes = new LinkedList<IpRange>();

    while (currentRangeStart.compareTo(rangeEnd) <= 0) {
        int maximumPrefixLength = getMaximumLengthOfPrefixStartingAtIpAddressValue(currentRangeStart,
                startingPrefixLength);/*  w w  w  . j a v a2 s  .c  o m*/
        BigInteger maximumSizeOfPrefix = rangeEnd.subtract(currentRangeStart).add(BigInteger.ONE);
        BigInteger currentSizeOfPrefix = BigInteger.valueOf(2).pow(maximumPrefixLength);

        while ((currentSizeOfPrefix.compareTo(maximumSizeOfPrefix) > 0) && (maximumPrefixLength > 0)) {
            maximumPrefixLength--;
            currentSizeOfPrefix = BigInteger.valueOf(2).pow(maximumPrefixLength);
        }

        BigInteger currentRangeEnd = currentRangeStart
                .add(BigInteger.valueOf(2).pow(maximumPrefixLength).subtract(BigInteger.ONE));
        IpRange prefix = (IpRange) IpResourceRange.assemble(currentRangeStart, currentRangeEnd, getType());

        prefixes.add(prefix);

        currentRangeStart = currentRangeEnd.add(BigInteger.ONE);
    }

    return prefixes;
}

From source file:co.rsk.core.NetworkStateExporterTest.java

@Test
public void testContracts() throws Exception {
    Repository repository = new RepositoryImpl(new TrieStoreImpl(new HashMapDB()));
    String address1String = "1000000000000000000000000000000000000000";
    byte[] address1 = Hex.decode(address1String);
    repository.createAccount(address1);//from  ww w. ja v  a2  s . c om
    repository.addBalance(address1, BigInteger.ONE);
    repository.increaseNonce(address1);
    ContractDetails contractDetails = new co.rsk.db.ContractDetailsImpl();
    contractDetails.setCode(new byte[] { 1, 2, 3, 4 });
    contractDetails.put(DataWord.ZERO, DataWord.ONE);
    contractDetails.putBytes(DataWord.ONE, new byte[] { 5, 6, 7, 8 });
    repository.updateContractDetails(address1, contractDetails);
    AccountState accountState = repository.getAccountState(address1);
    accountState.setStateRoot(contractDetails.getStorageHash());
    repository.updateAccountState(address1, accountState);

    Map result = writeAndReadJson(repository);

    Assert.assertEquals(1, result.keySet().size());
    Map address1Value = (Map) result.get(address1String);
    Assert.assertEquals(3, address1Value.keySet().size());
    Assert.assertEquals("1", address1Value.get("balance"));
    Assert.assertEquals("1", address1Value.get("nonce"));
    Map contract = (Map) address1Value.get("contract");
    Assert.assertEquals(2, contract.keySet().size());
    Assert.assertEquals("01020304", contract.get("code"));
    Map data = (Map) contract.get("data");
    Assert.assertEquals(2, data.keySet().size());
    Assert.assertEquals("01", data.get(Hex.toHexString(DataWord.ZERO.getData())));
    Assert.assertEquals("05060708", data.get(Hex.toHexString(DataWord.ONE.getData())));
}

From source file:net.big_oh.common.utils.CollectionsUtil.java

protected static <T> BigInteger countCombinations(int n, int k) throws IllegalArgumentException {
    // sanity check
    if (k < 0) {
        throw new IllegalArgumentException("The value of the k parameter cannot be less than zero.");
    }//w  w  w.  jav  a2  s.  c o  m
    if (k > n) {
        throw new IllegalArgumentException(
                "The value of the k parameter cannot be greater than n, the size of the originalSet.");
    }

    // The end result will be equal to n! / (k! * ((n-k)!))

    // start by doing some up front evaluation of the denominator
    int maxDenomArg;
    int minDenomArg;
    if ((n - k) > k) {
        maxDenomArg = (n - k);
        minDenomArg = k;
    } else {
        maxDenomArg = k;
        minDenomArg = (n - k);
    }

    // First, do an efficient calculation of n! / maxDenomArg!
    BigInteger partialCalculation = BigInteger.ONE;
    for (int i = maxDenomArg + 1; i <= n; i++) {
        partialCalculation = partialCalculation.multiply(BigInteger.valueOf(i));
    }

    // Lastly, produce the final solution by calculating partialCalculation / minDenomArg!
    return partialCalculation.divide(MathUtil.factorial(minDenomArg));
}

From source file:org.ossie.properties.AnyUtils.java

/**
 * Attempts to convert the string value to the appropriate Java type.
 * /*from  w w  w .  j a  va 2  s .c o m*/
 * @param stringValue the string form of the value
 * @param type the string form of the TypeCode
 * @return A Java object of theString corresponding to the typecode
 */
public static Object convertString(final String stringValue, final String type) {
    if (stringValue == null) {
        return null;
    }
    if (type.equals("string")) {
        return stringValue;
    } else if (type.equals("wstring")) {
        return stringValue;
    } else if (type.equals("boolean")) {
        if ("true".equalsIgnoreCase(stringValue) || "false".equalsIgnoreCase(stringValue)) {
            return Boolean.parseBoolean(stringValue);
        }
        throw new IllegalArgumentException(stringValue + " is not a valid boolean value");
    } else if (type.equals("char")) {
        if (stringValue.length() == 1) {
            return stringValue.charAt(0);
        }
        throw new IllegalArgumentException(stringValue + " is not a valid char value");
    } else if (type.equals("wchar")) {
        return stringValue.charAt(0);
    } else if (type.equals("double")) {
        return Double.parseDouble(stringValue);
    } else if (type.equals("float")) {
        return Float.parseFloat(stringValue);
    } else if (type.equals("short")) {
        return Short.decode(stringValue);
    } else if (type.equals("long")) {
        return Integer.decode(stringValue);
    } else if (type.equals("longlong")) {
        return Long.decode(stringValue);
    } else if (type.equals("ulong")) {
        final long MAX_UINT = 2L * Integer.MAX_VALUE + 1L;
        final Long retVal = Long.decode(stringValue);
        if (retVal < 0 || retVal > MAX_UINT) {
            throw new IllegalArgumentException(
                    "ulong value must be greater than '0' and less than " + MAX_UINT);
        }
        return retVal;
    } else if (type.equals("ushort")) {
        final int MAX_USHORT = 2 * Short.MAX_VALUE + 1;
        final Integer retVal = Integer.decode(stringValue);
        if (retVal < 0 || retVal > MAX_USHORT) {
            throw new IllegalArgumentException(
                    "ushort value must be greater than '0' and less than " + MAX_USHORT);
        }
        return retVal;
    } else if (type.equals("ulonglong")) {
        final BigInteger MAX_ULONG_LONG = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2))
                .add(BigInteger.ONE);
        final BigInteger retVal = bigIntegerDecode(stringValue);
        if (retVal.compareTo(BigInteger.ZERO) < 0 || retVal.compareTo(MAX_ULONG_LONG) > 0) {
            throw new IllegalArgumentException(
                    "ulonglong value must be greater than '0' and less than " + MAX_ULONG_LONG.toString());
        }
        return retVal;
    } else if (type.equals("objref")) {
        List<String> objrefPrefix = Arrays.asList("IOR:", "corbaname:", "corbaloc:");
        for (String prefix : objrefPrefix) {
            if (stringValue.startsWith(prefix)) {
                return stringValue;
            }
        }
        throw new IllegalArgumentException(stringValue + " is not a valid objref value");
    } else if (type.equals("octet")) {
        final short MIN_OCTET = 0;
        final short MAX_OCTET = 0xFF;
        short val = Short.valueOf(stringValue);
        if (val <= MAX_OCTET && val >= MIN_OCTET) {
            return Short.valueOf(val).byteValue();
        }
        throw new IllegalArgumentException(stringValue + " is not a valid octet value");
    } else {
        throw new IllegalArgumentException("Unknown CORBA Type: " + type);
    }
}

From source file:de.document.controller.UmlsController.java

@RequestMapping(value = "/queryId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)

public ResponseEntity<Collection<Umls>> getDef() {

    Map<BigInteger, Umls> greetingMap = null;
    RetrieveCui RC = new RetrieveCui(Cui);
    Umls u = new Umls();
    u = RC.RetCui(Cui);/*from   w ww  . ja v  a  2  s .co  m*/

    if (greetingMap == null) {
        greetingMap = new HashMap<BigInteger, Umls>();
        nextId = BigInteger.ONE;
    }

    nextId = nextId.add(BigInteger.ONE);
    greetingMap.put(nextId, u);

    Collection<Umls> greetings = null;
    greetings = greetingMap.values();
    System.out.println("55555555555555555555555555555555");
    System.out.println(Cui);
    System.out.println(greetings.toArray()[0]);
    System.out.println(u);

    return new ResponseEntity<Collection<Umls>>(greetings, HttpStatus.OK);
}

From source file:ubic.basecode.math.Wilcoxon.java

/**
 * Direct port from catmap code. Exact computation of the number of ways n items can be drawn from a total of N
 * items with a rank sum of R or better (lower).
 * /*from w w  w . j a v a  2 s . c o  m*/
 * @param N0
 * @param n0
 * @param R0 rank sum, 1-based (best rank is 1)
 * @return
 */
private static BigInteger computeA__(int N0, int n0, int R0) {
    if (R0 < N0)
        N0 = R0;

    if (cacheContains(N0, n0, R0)) {
        return getFromCache(N0, n0, R0);
    }

    if (N0 == 0 && n0 == 0)
        return BigInteger.ONE;

    for (int N = 1; N <= N0; N++) {
        if (N > 2)
            removeFromCache(N - 2);

        /* n has to be less than N */
        int min_n = Math.max(0, n0 + N - N0);
        int max_n = Math.min(n0, N);

        assert min_n >= 0;
        assert max_n >= min_n;

        for (int n = min_n; n <= max_n; n++) {

            /* The rank sum is in the interval n(n+1)/2 to n(2N-n+1)/2. Other values need not be looked at. */
            int bestPossibleRankSum = n * (n + 1) / 2;
            int worstPossibleRankSum = n * (2 * N - n + 1) / 2;

            /* Ensure value looked at is valid for the original set of parameters. */
            int min_r = Math.max(R0 - (N0 + N + 1) * (N0 - N) / 2, bestPossibleRankSum);
            int max_r = Math.min(worstPossibleRankSum, R0);

            assert min_r >= 0;
            assert max_r >= min_r;

            /* R greater than this, have already computed it in parts */
            int foo = n * (2 * N - n - 1) / 2;

            /* R less than this, we have already computed it in parts */
            int bar = N + (n - 1) * n / 2;

            for (int r = min_r; r <= max_r; r++) {

                if (n == 0 || n == N || r == bestPossibleRankSum) {
                    addToCache(N, n, r, BigInteger.ONE);

                } else if (r > foo) {
                    addToCache(N, n, r, getFromCache(N - 1, n, foo).add(getFromCache(N - 1, n - 1, r - N)));

                } else if (r < bar) {
                    addToCache(N, n, r, getFromCache(N - 1, n, r));

                } else {
                    addToCache(N, n, r, getFromCache(N - 1, n, r).add(getFromCache(N - 1, n - 1, r - N)));
                }
            }
        }
    }
    // if ( log.isErrorEnabled() ) {
    // printCache();
    // }
    return getFromCache(N0, n0, R0);
}

From source file:PalidromeArray.java

public BigInteger get(BigInteger position) {
    /**//from   w  w  w  . j a  va 2 s .co m
     * {1,4,6,4,1} would have {1,4,6} in our array
     * 0: return 1
     * 1: return 4
     * 2: return 6
     * 3: return 4
     * 4: return 1
     * totalLength = 5
     * halfLength = 3
     * get(0) returns #0
     * get(1) returns #1
     * get(2) returns #2
     * get(3) returns #1
     * get(4) returns #0
     *
     * {1,3,3,1} would have {1,3} in our array
     * array.length = 2
     * 0: return 1
     * 1: return 3
     * 2: return 3
     * 3: return 1
     * totalLength = 4
     * halfLength = 2
     * get(0) returns #0
     * get(1) returns #1
     * get(2) returns #1
     * get(3) returns #0
     */
    if (position.subtract(halfLength).signum() < 0)
        return array.get(position);

    BigInteger mid = halfLength.subtract(BigInteger.ONE);

    if (isEven)
        return array.get(mid.subtract(position.subtract(halfLength)));

    return array.get(mid.subtract(position.subtract(mid)));
}

From source file:org.codice.ddf.spatial.ogc.wps.process.endpoint.Validator.java

/**
 * @param inputs//from   w w w.  j a v  a 2  s.c o m
 * @param inputDescription
 * @throws WpsException
 */
public static void validateProcessInputsMinMaxOccurs(List<Data> inputs, DataDescription inputDescription) {

    if (CollectionUtils.isEmpty(inputs)) {
        if (BigInteger.ZERO.equals(inputDescription.getMinOccurs())) {
            return;
        } else {
            throw new WpsException("Too few input items have been specified.", "TooFewInputs",
                    inputDescription.getId());
        }
    }

    BigInteger maxOccurs = inputDescription.getMaxOccurs() == null ? BigInteger.ONE
            : inputDescription.getMaxOccurs();

    if (inputs.size() > maxOccurs.intValue()) {
        throw new WpsException("Too many input items have been specified.", "TooManyInputs",
                inputDescription.getId());
    }
    BigInteger minOccurs = inputDescription.getMinOccurs() == null ? BigInteger.ONE
            : inputDescription.getMinOccurs();
    if (inputs.size() < minOccurs.intValue()) {
        throw new WpsException("Too few input items have been specified.", "TooFewInputs",
                inputDescription.getId());
    }
    inputs.forEach(input -> validateProcessInputData(input, inputDescription));
}