final DERDecoder decoder = new DERDecoder(encoded); final CertificateFactory certificateFactory = CertificateFactory.getInstance(X_509); final int count = decoder.decodeInteger().intValueExact(); final X509Certificate[] array = new X509Certificate[count]; decoder.startSequence();
private Period fromBigInteger(BigInteger period) { BigInteger[] monthsAndDays = period.divideAndRemainder(THIRTY_ONE); BigInteger[] yearsAndMonths = monthsAndDays[0].divideAndRemainder(TWELVE); return Period.of( yearsAndMonths[0].intValueExact(), yearsAndMonths[1].intValueExact(), monthsAndDays[1].intValueExact()); } }
/** * Returns the next prime number that is greater than the given target. There will be * no prime numbers less than the returned prime number that are greater than the given target. * @param target the starting value to begin the search for the next prime * @return the next prime number that is greater than the given target. */ static int nextPrime(final int target) { return BigInteger.valueOf(target).nextProbablePrime().intValueExact(); }
@Override public int intValueExact() throws ArithmeticException { return value.intValueExact(); }
private static int digitSum(final BigInteger someInteger) { int ret = 0; BigInteger b = someInteger; BigInteger[] modResult; while (b.compareTo(BigInteger.ZERO) > 0) { modResult = b.divideAndRemainter(BigInteger.TEN); ret += modResult[1].intValueExact(); b = modResult[0]; } return ret; }
public static int getIntFromInput(String inputString) { //sanity checks if (inputString == null || inputString.trim().length() == 0) { throw new IllegalArgumentException("empty or null string passed"); } try { return new BigInteger(inputString, 10).intValueExact(); } catch (Exception ignored) { throw new IllegalArgumentException(String.format("input string is not a valid integer number: '%s'", inputString)); } }
public static int myRandom(int min, int max, Random r){ if (max <= min) throw new RuntimeException("max value must be greater than min value: max="+max +", min="+min); BigInteger maxB = BigInteger.valueOf(max); BigInteger minB = BigInteger.valueOf(min); BigInteger range = maxB.subtract(minB); do{ BigInteger result = new BigInteger(range.bitLength(), r); if (result.compareTo(range)<=0) return result.add(minB).intValueExact(); }while(true); }
@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { if (integerValue.compareTo(BigInteger.ZERO) >= 0) { return Optional.of(vf.createLiteral(String.valueOf(integerValue.intValueExact()), XMLSchema.UNSIGNED_INT)); } return Optional.empty(); }
@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { return Optional.of(vf.createLiteral(integerValue.intValueExact())); }
@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { if (integerValue.compareTo(BigInteger.ZERO) >= 0) { return Optional.of(vf.createLiteral(String.valueOf(integerValue.intValueExact()), XMLSchema.UNSIGNED_INT)); } return Optional.empty(); }
private Period fromBigInteger(BigInteger period) { BigInteger[] monthsAndDays = period.divideAndRemainder(THIRTY_ONE); BigInteger[] yearsAndMonths = monthsAndDays[0].divideAndRemainder(TWELVE); return Period.of( yearsAndMonths[0].intValueExact(), yearsAndMonths[1].intValueExact(), monthsAndDays[1].intValueExact()); } }
/** * Returns the next prime number that is greater than the given target. There will be * no prime numbers less than the returned prime number that are greater than the given target. * @param target the starting value to begin the search for the next prime * @return the next prime number that is greater than the given target. */ static int nextPrime(final int target) { return BigInteger.valueOf(target).nextProbablePrime().intValueExact(); }
@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { return Optional.of(vf.createLiteral(integerValue.intValueExact())); }
@Override public int[] unrank() { int[] product = new int[dimensions.length]; BigInteger dividend = currentIndex; for(int k = dimensions.length - 1; k >= 0; k--) { BigInteger[] quotientAndRemainder = dividend.divideAndRemainder(BigInteger.valueOf(dimensions[k])); product[k] = quotientAndRemainder[1].intValueExact(); dividend = quotientAndRemainder[0]; } return product; } }
public void setV(Object v) { if (v instanceof String) { this.v = Numeric.toBigInt((String) v).intValueExact(); } else { this.v = ((Integer) v); } }
@Override public Optional<T> get( BigInteger idx ) { if( idx.signum() < 0 || idx.compareTo( size ) >= 0 ) { return Optional.empty(); } InternalValues.Intern first = new InternalValues.Intern(); calcInternal( first, idx ); return Optional.of( firstMap.get( first.fist ). get( first.second.intValueExact() )); }
@Override public Object parseValue(Object input) { if (input instanceof Number || input instanceof String) { try { return new IntNode(new BigInteger(input.toString()).intValueExact()); } catch (ArithmeticException e) { throw new CoercingParseValueException(input + " does not fit into an int without a loss of precision"); } } if (input instanceof IntNode) { return input; } throw valueParsingException(input, Number.class, String.class, IntNode.class); }
public static IntToken shr(IntToken term1, IntToken term2, TermContext context) { try { return IntToken.of(term1.bigIntegerValue().shiftRight(term2.bigIntegerValue().intValueExact())); } catch (ArithmeticException e) { if (term1.bigIntegerValue().compareTo(BigInteger.ZERO) >= 0) { return IntToken.of(0); } else { return IntToken.of(-1); } } }
@Override public Object parseLiteral(Object input) { if (input instanceof IntValue) { try { return new IntNode(((IntValue) input).getValue().intValueExact()); } catch (ArithmeticException e) { throw new CoercingParseLiteralException(input + " does not fit into an int without a loss of precision"); } } else { throw new CoercingParseLiteralException(errorMessage(input, IntValue.class)); } } });
@Example void withFilter() { Shrinkable<BigInteger> shrinkable = createShrinkableBigInteger(100000, Range.of(0L, 1000000L)); Falsifier<BigInteger> falsifier = aBigInteger -> aBigInteger.intValueExact() < 99; Falsifier<BigInteger> filteredFalsifier = falsifier.withFilter(aBigInteger -> aBigInteger.intValueExact() % 2 == 0); ShrinkingSequence<BigInteger> sequence = shrinkable.shrink(filteredFalsifier); while (sequence.next(count, reporter)); assertThat(sequence.current().value()).isEqualTo(100); assertThat(counter.get()).isEqualTo(8); }