List of usage examples for java.math BigInteger ONE
BigInteger ONE
To view the source code for java.math BigInteger ONE.
Click Source Link
From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java
/** * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertResolutionIfNotExists(biz.futureware.mantis.rpc.soap.client.ObjectRef)}. *//*from w w w .j a v a 2 s . co m*/ @Test public void testInsertResolutionIfNotExists() { final ObjectRef item = new ObjectRef(BigInteger.ONE, "item"); final boolean result = dao.insertResolutionIfNotExists(item); assertTrue(result); final List<ObjectRef> list = getJdbcTemplate().query("SELECT id, name FROM mantis_enum_resolutions", new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class)); assertEquals(1, list.size()); assertEquals(item, list.get(0)); final boolean result2 = dao.insertResolutionIfNotExists(item); assertTrue(result2); }
From source file:net.pms.util.Rational.java
/** * Returns an instance that represents the value of {@code value}. * * @param value the value.//w w w. j a v a 2 s. c o m * @return An instance that represents the value of {@code value}. */ @Nullable public static Rational valueOf(@Nullable BigDecimal value) { if (value == null) { return null; } BigInteger numerator; BigInteger denominator; if (value.signum() == 0) { return ZERO; } if (BigDecimal.ONE.equals(value)) { return ONE; } if (value.scale() > 0) { BigInteger unscaled = value.unscaledValue(); BigInteger tmpDenominator = BigInteger.TEN.pow(value.scale()); BigInteger tmpGreatestCommonDivisor = unscaled.gcd(tmpDenominator); numerator = unscaled.divide(tmpGreatestCommonDivisor); denominator = tmpDenominator.divide(tmpGreatestCommonDivisor); } else { numerator = value.toBigIntegerExact(); denominator = BigInteger.ONE; } return new Rational(numerator, denominator, BigInteger.ONE, numerator, denominator); }
From source file:info.savestate.saveybot.JSONFileManipulator.java
public String lowestSlot() { BigInteger lowest = BigInteger.ZERO; JSONArray json = getJSON();//from w w w .ja v a2 s. co m boolean passed = false; while (!passed) { passed = true; for (int i = 0; i < json.length(); i++) { JSONObject o = json.getJSONObject(i); BigInteger current = o.getBigInteger("slot"); if (current.compareTo(lowest) == 0) { lowest = lowest.add(BigInteger.ONE); passed = false; break; } } } return lowest.toString(); }
From source file:net.ripe.rpki.validator.commands.TopDownWalkerTest.java
static X509ResourceCertificate createManifestEECertificate() { X509ResourceCertificateBuilder builder = new X509ResourceCertificateBuilder(); builder.withCa(false).withSubjectDN(ROOT_CERTIFICATE_NAME).withIssuerDN(ROOT_CERTIFICATE_NAME) .withSerial(BigInteger.ONE); builder.withPublicKey(ROOT_KEY_PAIR.getPublic()); builder.withSigningKeyPair(ROOT_KEY_PAIR); builder.withInheritedResourceTypes(EnumSet.allOf(IpResourceType.class)); builder.withValidityPeriod(new ValidityPeriod(THIS_UPDATE_TIME, NEXT_UPDATE_TIME)); return builder.build(); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java
@SuppressWarnings("unchecked") @Test/*from w w w. ja v a 2s . c o m*/ public void testPostGetRecordsDistributedSearchSetToOne() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); DistributedSearchType distributedSearch = new DistributedSearchType(); distributedSearch.setHopCount(BigInteger.ONE); grr.setDistributedSearch(distributedSearch); QueryRequest queryRequest = queryFactory.getQuery(grr); assertThat(queryRequest.isEnterprise(), is(false)); assertThat(queryRequest.getSourceIds(), anyOf(nullValue(), empty())); }
From source file:org.opennms.netmgt.config.WmiPeerFactory.java
/** * Combine specific and range elements so that WMIPeerFactory has to spend * less time iterating all these elements. * TODO This really should be pulled up into PeerFactory somehow, but I'm not sure how (given that "Definition" is different for both * SNMP and WMI. Maybe some sort of visitor methodology would work. The basic logic should be fine as it's all IP address manipulation * * @throws UnknownHostException/*w ww. ja v a 2 s .c om*/ */ static void optimize() throws UnknownHostException { // First pass: Remove empty definition elements for (Iterator<Definition> definitionsIterator = m_config.getDefinitionCollection() .iterator(); definitionsIterator.hasNext();) { Definition definition = definitionsIterator.next(); if (definition.getSpecificCount() == 0 && definition.getRangeCount() == 0) { LOG.debug("optimize: Removing empty definition element"); definitionsIterator.remove(); } } // Second pass: Replace single IP range elements with specific elements for (Definition definition : m_config.getDefinitionCollection()) { synchronized (definition) { for (Iterator<Range> rangesIterator = definition.getRangeCollection().iterator(); rangesIterator .hasNext();) { Range range = rangesIterator.next(); if (range.getBegin().equals(range.getEnd())) { definition.addSpecific(range.getBegin()); rangesIterator.remove(); } } } } // Third pass: Sort specific and range elements for improved XML // readability and then combine them into fewer elements where possible for (Iterator<Definition> defIterator = m_config.getDefinitionCollection().iterator(); defIterator .hasNext();) { Definition definition = defIterator.next(); // Sort specifics final TreeMap<InetAddress, String> specificsMap = new TreeMap<InetAddress, String>( new InetAddressComparator()); for (String specific : definition.getSpecificCollection()) { specificsMap.put(InetAddressUtils.getInetAddress(specific), specific.trim()); } // Sort ranges final TreeMap<InetAddress, Range> rangesMap = new TreeMap<InetAddress, Range>( new InetAddressComparator()); for (Range range : definition.getRangeCollection()) { rangesMap.put(InetAddressUtils.getInetAddress(range.getBegin()), range); } // Combine consecutive specifics into ranges InetAddress priorSpecific = null; Range addedRange = null; for (final InetAddress specific : specificsMap.keySet()) { if (priorSpecific == null) { priorSpecific = specific; continue; } if (BigInteger.ONE.equals(InetAddressUtils.difference(specific, priorSpecific)) && InetAddressUtils.inSameScope(specific, priorSpecific)) { if (addedRange == null) { addedRange = new Range(); addedRange.setBegin(InetAddressUtils.toIpAddrString(priorSpecific)); rangesMap.put(priorSpecific, addedRange); specificsMap.remove(priorSpecific); } addedRange.setEnd(InetAddressUtils.toIpAddrString(specific)); specificsMap.remove(specific); } else { addedRange = null; } priorSpecific = specific; } // Move specifics to ranges for (final InetAddress specific : new ArrayList<InetAddress>(specificsMap.keySet())) { for (final InetAddress begin : new ArrayList<InetAddress>(rangesMap.keySet())) { if (!InetAddressUtils.inSameScope(begin, specific)) { continue; } if (InetAddressUtils.toInteger(begin).subtract(BigInteger.ONE) .compareTo(InetAddressUtils.toInteger(specific)) > 0) { continue; } Range range = rangesMap.get(begin); final InetAddress end = InetAddressUtils.getInetAddress(range.getEnd()); if (InetAddressUtils.toInteger(end).add(BigInteger.ONE) .compareTo(InetAddressUtils.toInteger(specific)) < 0) { continue; } if (InetAddressUtils.toInteger(specific).compareTo(InetAddressUtils.toInteger(begin)) >= 0 && InetAddressUtils.toInteger(specific) .compareTo(InetAddressUtils.toInteger(end)) <= 0) { specificsMap.remove(specific); break; } if (InetAddressUtils.toInteger(begin).subtract(BigInteger.ONE) .equals(InetAddressUtils.toInteger(specific))) { rangesMap.remove(begin); rangesMap.put(specific, range); range.setBegin(InetAddressUtils.toIpAddrString(specific)); specificsMap.remove(specific); break; } if (InetAddressUtils.toInteger(end).add(BigInteger.ONE) .equals(InetAddressUtils.toInteger(specific))) { range.setEnd(InetAddressUtils.toIpAddrString(specific)); specificsMap.remove(specific); break; } } } // Combine consecutive ranges Range priorRange = null; InetAddress priorBegin = null; InetAddress priorEnd = null; for (final Iterator<InetAddress> rangesIterator = rangesMap.keySet().iterator(); rangesIterator .hasNext();) { final InetAddress beginAddress = rangesIterator.next(); final Range range = rangesMap.get(beginAddress); final InetAddress endAddress = InetAddressUtils.getInetAddress(range.getEnd()); if (priorRange != null) { if (InetAddressUtils.inSameScope(beginAddress, priorEnd) && InetAddressUtils.difference(beginAddress, priorEnd).compareTo(BigInteger.ONE) <= 0) { priorBegin = new InetAddressComparator().compare(priorBegin, beginAddress) < 0 ? priorBegin : beginAddress; priorRange.setBegin(InetAddressUtils.toIpAddrString(priorBegin)); priorEnd = new InetAddressComparator().compare(priorEnd, endAddress) > 0 ? priorEnd : endAddress; priorRange.setEnd(InetAddressUtils.toIpAddrString(priorEnd)); rangesIterator.remove(); continue; } } priorRange = range; priorBegin = beginAddress; priorEnd = endAddress; } // Update changes made to sorted maps definition.setSpecific(specificsMap.values().toArray(new String[0])); definition.setRange(rangesMap.values().toArray(new Range[0])); } }
From source file:com.amazonaws.services.kinesis.clientlibrary.proxies.KinesisLocalFileProxy.java
/** * {@inheritDoc}// w w w . j a v a 2 s.c o m */ @Override public String getIterator(String shardId, String iteratorEnum, String sequenceNumber) throws ResourceNotFoundException, InvalidArgumentException { /* * If we don't have records in this shard, any iterator will return the empty list. Using a * sequence number of 1 on an empty shard will give this behavior. */ List<Record> shardRecords = shardedDataRecords.get(shardId); if (shardRecords == null) { throw new ResourceNotFoundException(shardId + " does not exist"); } if (shardRecords.isEmpty()) { return serializeIterator(shardId, "1"); } if (ShardIteratorType.LATEST.toString().equals(iteratorEnum)) { /* * If we do have records, LATEST should return an iterator that can be used to read the * last record. Our iterators are inclusive for convenience. */ Record last = shardRecords.get(shardRecords.size() - 1); return serializeIterator(shardId, last.getSequenceNumber()); } else if (ShardIteratorType.TRIM_HORIZON.toString().equals(iteratorEnum)) { return serializeIterator(shardId, shardRecords.get(0).getSequenceNumber()); } else if (ShardIteratorType.AT_SEQUENCE_NUMBER.toString().equals(iteratorEnum)) { return serializeIterator(shardId, sequenceNumber); } else if (ShardIteratorType.AFTER_SEQUENCE_NUMBER.toString().equals(iteratorEnum)) { BigInteger num = new BigInteger(sequenceNumber); num = num.add(BigInteger.ONE); return serializeIterator(shardId, num.toString()); } else { throw new IllegalArgumentException("IteratorEnum value was invalid: " + iteratorEnum); } }
From source file:org.opendaylight.neutron.spi.NeutronSubnet.java
@Override public void initDefaults() { if (enableDHCP == null) { enableDHCP = true;/*from ww w. ja v a 2 s. c o m*/ } if (ipVersion == null) { ipVersion = IPV4_VERSION; } if (dnsNameservers == null) { dnsNameservers = new ArrayList<String>(); } if (hostRoutes == null) { hostRoutes = new ArrayList<NeutronRoute>(); } if (allocationPools == null) { allocationPools = new ArrayList<NeutronSubnetIpAllocationPool>(); if (ipVersion == IPV4_VERSION) { try { SubnetUtils util = new SubnetUtils(cidr); SubnetInfo info = util.getInfo(); if (gatewayIp == null || ("").equals(gatewayIp)) { gatewayIp = info.getLowAddress(); } if (allocationPools.size() < 1) { NeutronSubnetIpAllocationPool source = new NeutronSubnetIpAllocationPool( info.getLowAddress(), info.getHighAddress()); allocationPools = source.splitPool(gatewayIp); } } catch (IllegalArgumentException e) { LOGGER.warn("Failure in initDefault()", e); return; } } if (ipVersion == IPV6_VERSION) { String[] parts = cidr.split("/"); if (parts.length != 2) { return; } int length = Integer.parseInt(parts[1]); BigInteger lowAddressBi = NeutronSubnetIpAllocationPool.convertV6(parts[0]); String lowAddress = NeutronSubnetIpAllocationPool.bigIntegerToIp(lowAddressBi.add(BigInteger.ONE)); BigInteger mask = BigInteger.ONE.shiftLeft(length).subtract(BigInteger.ONE); String highAddress = NeutronSubnetIpAllocationPool .bigIntegerToIp(lowAddressBi.add(mask).subtract(BigInteger.ONE)); if (gatewayIp == null || ("").equals(gatewayIp)) { gatewayIp = lowAddress; } if (allocationPools.size() < 1) { NeutronSubnetIpAllocationPool source = new NeutronSubnetIpAllocationPool(lowAddress, highAddress); allocationPools = source.splitPoolV6(gatewayIp); } } } }
From source file:test.unit.be.e_contract.dssp.client.DigitalSignatureServiceTestPort.java
@Override public ResponseBaseType verify(VerifyRequest verifyRequest) { ResponseBaseType response = this.objectFactory.createResponseBaseType(); response.setProfile(DigitalSignatureServiceConstants.PROFILE); Result result = this.objectFactory.createResult(); response.setResult(result);//w w w .ja v a2 s .co m result.setResultMajor(DigitalSignatureServiceConstants.SUCCESS_RESULT_MAJOR); AnyType optionalOutputs = this.objectFactory.createAnyType(); response.setOptionalOutputs(optionalOutputs); VerificationReportType verificationReport = this.vrObjectFactory.createVerificationReportType(); optionalOutputs.getAny().add(this.vrObjectFactory.createVerificationReport(verificationReport)); DeadlineType timeStampRenewalDeadline = this.dsspObjectFactory.createDeadlineType(); GregorianCalendar beforeGregorianCalendar = new GregorianCalendar(); beforeGregorianCalendar.setTime(new Date()); beforeGregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); XMLGregorianCalendar beforeXMLGregorianCalendar = this.datatypeFactory .newXMLGregorianCalendar(beforeGregorianCalendar); timeStampRenewalDeadline.setBefore(beforeXMLGregorianCalendar); optionalOutputs.getAny().add(this.dsspObjectFactory.createTimeStampRenewal(timeStampRenewalDeadline)); IndividualReportType individualReport = this.vrObjectFactory.createIndividualReportType(); verificationReport.getIndividualReport().add(individualReport); individualReport.setResult(result); SignedObjectIdentifierType signedObjectIdentifier = this.vrObjectFactory.createSignedObjectIdentifierType(); individualReport.setSignedObjectIdentifier(signedObjectIdentifier); SignedPropertiesType signedProperties = this.vrObjectFactory.createSignedPropertiesType(); signedObjectIdentifier.setSignedProperties(signedProperties); SignedSignaturePropertiesType signedSignatureProperties = this.vrObjectFactory .createSignedSignaturePropertiesType(); signedProperties.setSignedSignatureProperties(signedSignatureProperties); GregorianCalendar signingTimeGregorianCalendar = new GregorianCalendar(); signingTimeGregorianCalendar.setTime(new Date()); signingTimeGregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); XMLGregorianCalendar signingTimeXMLGregorianCalendar = this.datatypeFactory .newXMLGregorianCalendar(signingTimeGregorianCalendar); signedSignatureProperties.setSigningTime(signingTimeXMLGregorianCalendar); AnyType details = this.objectFactory.createAnyType(); individualReport.setDetails(details); DetailedSignatureReportType detailedSignatureReport = this.vrObjectFactory .createDetailedSignatureReportType(); details.getAny().add(this.vrObjectFactory.createDetailedSignatureReport(detailedSignatureReport)); VerificationResultType formatOKVerificationResult = this.vrObjectFactory.createVerificationResultType(); formatOKVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); detailedSignatureReport.setFormatOK(formatOKVerificationResult); SignatureValidityType signatureOkSignatureValidity = this.vrObjectFactory.createSignatureValidityType(); detailedSignatureReport.setSignatureOK(signatureOkSignatureValidity); VerificationResultType sigMathOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); signatureOkSignatureValidity.setSigMathOK(sigMathOkVerificationResult); sigMathOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); CertificatePathValidityType certificatePathValidity = this.vrObjectFactory .createCertificatePathValidityType(); detailedSignatureReport.setCertificatePathValidity(certificatePathValidity); VerificationResultType certPathVerificationResult = this.vrObjectFactory.createVerificationResultType(); certPathVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); certificatePathValidity.setPathValiditySummary(certPathVerificationResult); X509IssuerSerialType certificateIdentifier = this.xmldsigObjectFactory.createX509IssuerSerialType(); certificatePathValidity.setCertificateIdentifier(certificateIdentifier); certificateIdentifier.setX509IssuerName("CN=Issuer"); certificateIdentifier.setX509SerialNumber(BigInteger.ONE); CertificatePathValidityVerificationDetailType certificatePathValidityVerificationDetail = this.vrObjectFactory .createCertificatePathValidityVerificationDetailType(); certificatePathValidity.setPathValidityDetail(certificatePathValidityVerificationDetail); CertificateValidityType certificateValidity = this.vrObjectFactory.createCertificateValidityType(); certificatePathValidityVerificationDetail.getCertificateValidity().add(certificateValidity); certificateValidity.setCertificateIdentifier(certificateIdentifier); certificateValidity.setSubject("CN=Subject"); VerificationResultType chainingOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); certificateValidity.setChainingOK(chainingOkVerificationResult); chainingOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); VerificationResultType validityPeriodOkVerificationResult = this.vrObjectFactory .createVerificationResultType(); certificateValidity.setValidityPeriodOK(validityPeriodOkVerificationResult); validityPeriodOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); VerificationResultType extensionsOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); certificateValidity.setExtensionsOK(extensionsOkVerificationResult); extensionsOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); byte[] encodedCertificate; try { encodedCertificate = IOUtils .toByteArray(DigitalSignatureServiceTestPort.class.getResource("/fcorneli.der")); } catch (IOException e) { throw new RuntimeException(e); } certificateValidity.setCertificateValue(encodedCertificate); certificateValidity.setSignatureOK(signatureOkSignatureValidity); CertificateStatusType certificateStatus = this.vrObjectFactory.createCertificateStatusType(); certificateValidity.setCertificateStatus(certificateStatus); VerificationResultType certStatusOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); certificateStatus.setCertStatusOK(certStatusOkVerificationResult); certStatusOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); return response; }
From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java
private void stepTwoB() throws Exception { byte[] send;/*from w w w . j a v a 2 s . c om*/ IHttpRequestResponse response; byte[] request; loggerInstance.log(getClass(), "Step 2b: Searching with more than" + " one interval left", Logger.LogLevel.INFO); do { // Check if user has cancelled the worker if (isCancelled()) { loggerInstance.log(getClass(), "Decryption Attack Executor Worker cancelled by user", Logger.LogLevel.INFO); return; } this.si = this.si.add(BigInteger.ONE); send = prepareMsg(this.c0, this.si); request = this.requestResponse.getRequest(); String[] components = Decoder.getComponents(this.parameter.getJoseValue()); components[1] = Decoder.base64UrlEncode(send); String newComponentsConcatenated = Decoder.concatComponents(components); request = JoseParameter.updateRequest(request, this.parameter, helpers, newComponentsConcatenated); response = callbacks.makeHttpRequest(this.httpService, request); updateAmountRequest(); } while (oracle.getResult(response.getResponse()) != BleichenbacherPkcs1Oracle.Result.VALID); loggerInstance.log(getClass(), "Matching response: " + helpers.bytesToString(response.getResponse()), Logger.LogLevel.DEBUG); }