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:geogebra.kernel.AlgoBinomial.java
private double BinomBig(double n, double r) { if (r > n / 2) r = n - r;/*from w w w . j av a2s. co m*/ BigInteger ncr = BigInteger.ONE, dd = BigInteger.ONE, nn, rr; // nn=BigInteger.valueOf((long)n); // rr=BigInteger.valueOf((long)r); // need a long-winded conversion in case n>10^18 Double nnn = new Double(n); Double rrr = new Double(r); nn = (new BigDecimal(nnn.toString())).toBigInteger(); rr = (new BigDecimal(rrr.toString())).toBigInteger(); while (dd.compareTo(rr) <= 0) { ncr = ncr.multiply(nn); ncr = ncr.divide(dd); // dd is guaranteed to divide exactly into ncr here nn = nn.subtract(BigInteger.ONE); dd = dd.add(BigInteger.ONE); } return ncr.doubleValue(); }
From source file:com.dulion.astatium.mesh.shredder.ContextManager.java
public ContextManager(ContextLoader contextLoader, ContextBuilder contextBuilder) { this.contextLoader = contextLoader; this.contextBuilder = contextBuilder; Range range = new RationalRange(BigInteger.valueOf(2), BigInteger.ONE); ContextData context = ContextData.builder().contextId(0).namespace("urn:com:expedia:fcts:booking") .name("Base").type(ContextType.BASE).build(); root = new ContextBase(context, range); }
From source file:com.redhat.lightblue.metadata.types.StringTypeTest.java
@Test public void testCompareNotEqual() { assertEquals(stringType.compare((Object) BigInteger.ZERO, (Object) BigInteger.ONE), -1); }
From source file:nl.minvenj.pef.pseudo.IPPseudonymizer.java
private byte[] pseudonymize(final byte[] ipAddress, final int bitCount, final int mask, final int changeBitCount) { final BigInteger ipBigInt = new BigInteger(1, ipAddress); final String ipString = ipBigInt.toString(RADIX); final BigInteger bigIntMask = BigInteger.ONE.shiftLeft(bitCount - mask).subtract(BigInteger.ONE); final String bitStringToEncrypt = ipBigInt.and(bigIntMask).toString(RADIX); final String bitStringToEncryptPadded = Util.padZeroLeft(bitStringToEncrypt, changeBitCount - bitStringToEncrypt.length()); final String encrypted = _encrypter.encrypt(TWEAK, bitStringToEncryptPadded); final int keptBitCount = ipString.length() - changeBitCount; // keptBitCount is how many (string) bits to keep there are left in the original string // this is not necessarily equal to the mask, due to the conversion from BigInteger // since it will get converted to a number, take those left and concat, or if none, just use encrypted final String rebuiltBitString = keptBitCount > 0 ? ipString.substring(0, keptBitCount).concat(encrypted) : encrypted;/*from ww w. j a v a2 s .c o m*/ return toIPAddressOfSize(new BigInteger(rebuiltBitString, RADIX), ipAddress.length); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestingRMAppSecurityActions.java
@Override public void init() throws MalformedURLException, GeneralSecurityException { Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator kpg = KeyPairGenerator.getInstance(KEY_ALGORITHM, "BC"); kpg.initialize(KEY_SIZE);/*from w w w .j av a 2 s. co m*/ caKeyPair = kpg.genKeyPair(); X500NameBuilder subjectBuilder = new X500NameBuilder(BCStyle.INSTANCE); subjectBuilder.addRDN(BCStyle.CN, "RootCA"); try { sigGen = new JcaContentSignerBuilder(SIGNATURE_ALGORITHM).setProvider("BC") .build(caKeyPair.getPrivate()); X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(subjectBuilder.build(), BigInteger.ONE, new Date(), new Date(System.currentTimeMillis() + 600000), subjectBuilder.build(), caKeyPair.getPublic()); caCert = new JcaX509CertificateConverter().setProvider("BC").getCertificate(certGen.build(sigGen)); caCert.checkValidity(); caCert.verify(caKeyPair.getPublic()); caCert.verify(caCert.getPublicKey()); } catch (OperatorCreationException ex) { throw new GeneralSecurityException(ex); } }
From source file:org.openestate.io.examples.FilemakerWritingExample.java
/** * Create a {@link MetaDataType} with some example data. * * @return// w w w . j a va2s. co m * created example object */ protected static MetaDataType createMetaData() { MetaDataType metadata = FACTORY.createMetaDataType(); MetaDataType.FIELD field; field = FACTORY.createMetaDataTypeFIELD(); field.setNAME("number of rooms"); field.setEMPTYOK(true); field.setMAXREPEAT(BigInteger.ONE); field.setTYPE(FieldType.NUMBER); metadata.getFIELD().add(field); field = FACTORY.createMetaDataTypeFIELD(); field.setNAME("price"); field.setEMPTYOK(false); field.setMAXREPEAT(BigInteger.ONE); field.setTYPE(FieldType.NUMBER); metadata.getFIELD().add(field); field = FACTORY.createMetaDataTypeFIELD(); field.setNAME("description"); field.setEMPTYOK(true); field.setMAXREPEAT(BigInteger.ONE); field.setTYPE(FieldType.TEXT); metadata.getFIELD().add(field); return metadata; }
From source file:org.candlepin.util.CrlFileUtil.java
/** * Initializes a new CRL at the specified location * * @param file//from w w w . j a v a 2 s. c o m * The file to initialize * * @throws IOException * If an IO error occurs while initializing the CRL file */ public void initializeCRLFile(File file, Collection<BigInteger> revoke) throws IOException { FileOutputStream output = null; List<X509CRLEntryWrapper> entries = new LinkedList<X509CRLEntryWrapper>(); for (BigInteger serial : revoke) { entries.add(new X509CRLEntryWrapper(serial, new Date())); } X509CRL crl = this.pkiUtility.createX509CRL(entries, BigInteger.ONE); try { output = new FileOutputStream(file); this.pkiUtility.writePemEncoded(crl, output); } finally { IOUtils.closeQuietly(output); } }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsUserWriterTest.java
@Test public void test() throws Exception { final Operation op = sequenceOf( insertInto("mantis_project_table").columns("id", "name").values(1, "project_1").build(), insertInto("mantis_user_table").columns("id", "name").values(1, "old_user_1").build(), insertInto("mantis_project_user_list_table").columns("user_id", "project_id").values(1, 1).build()); lauchOperation(op);// w w w .jav a 2 s .c om projectUsersWriter.write(buildItems()); final List<AccountData> results = getJdbcTemplate() .query("SELECT usr.id, usr.name" + " FROM mantis_user_table usr" + " INNER JOIN mantis_project_user_list_table pul ON pul.user_id = usr.id" + " WHERE pul.project_id = 1", new BeanPropertyRowMapper<AccountData>(AccountData.class)); assertEquals(2, results.size()); for (final AccountData item : results) { if (item.getId() == BigInteger.ONE) { assertEquals("new_user_1", item.getName()); } else { assertEquals(BigInteger.valueOf(2), item.getId()); assertEquals("new_user_2", item.getName()); } } }
From source file:org.apache.flink.graph.library.clustering.undirected.TriadicCensus.java
@Override public Result getResult() { // vertex metrics BigInteger bigVertexCount = BigInteger.valueOf(vertexMetrics.getResult().getNumberOfVertices()); BigInteger bigEdgeCount = BigInteger.valueOf(vertexMetrics.getResult().getNumberOfEdges()); BigInteger bigTripletCount = BigInteger.valueOf(vertexMetrics.getResult().getNumberOfTriplets()); // triangle count BigInteger bigTriangleCount = BigInteger.valueOf(triangleCount.getResult()); BigInteger one = BigInteger.ONE; BigInteger two = BigInteger.valueOf(2); BigInteger three = BigInteger.valueOf(3); BigInteger six = BigInteger.valueOf(6); // counts as ordered in TriadicCensus.Result BigInteger[] counts = new BigInteger[4]; // triads with three connecting edges = closed triplet = triangle counts[3] = bigTriangleCount;//w w w . j a v a 2 s . c o m // triads with two connecting edges = open triplet; // deduct each triplet having been counted three times per triangle counts[2] = bigTripletCount.subtract(bigTriangleCount.multiply(three)); // triads with one connecting edge; each edge pairs with `vertex count - 2` vertices // then deduct twice for each open triplet and three times for each triangle counts[1] = bigEdgeCount.multiply(bigVertexCount.subtract(two)).subtract(counts[2].multiply(two)) .subtract(counts[3].multiply(three)); // triads with zero connecting edges; // (vertex count choose 3) minus earlier counts counts[0] = bigVertexCount.multiply(bigVertexCount.subtract(one)).multiply(bigVertexCount.subtract(two)) .divide(six).subtract(counts[1]).subtract(counts[2]).subtract(counts[3]); return new Result(counts); }
From source file:org.apache.flink.graph.library.clustering.directed.TriadicCensus.java
@Override public Result getResult() { BigInteger one = BigInteger.ONE; BigInteger two = BigInteger.valueOf(2); BigInteger three = BigInteger.valueOf(3); BigInteger six = BigInteger.valueOf(6); BigInteger vertexCount = BigInteger.valueOf((Long) vertexDegreesHelper.getAccumulator(env, "vc")); BigInteger unidirectionalEdgeCount = BigInteger .valueOf((Long) vertexDegreesHelper.getAccumulator(env, "uec") / 2); BigInteger bidirectionalEdgeCount = BigInteger .valueOf((Long) vertexDegreesHelper.getAccumulator(env, "bec") / 2); BigInteger triplet021dCount = BigInteger.valueOf((Long) vertexDegreesHelper.getAccumulator(env, "021d")); BigInteger triplet021uCount = BigInteger.valueOf((Long) vertexDegreesHelper.getAccumulator(env, "021u")); BigInteger triplet021cCount = BigInteger.valueOf((Long) vertexDegreesHelper.getAccumulator(env, "021c")); BigInteger triplet111dCount = BigInteger.valueOf((Long) vertexDegreesHelper.getAccumulator(env, "111d")); BigInteger triplet111uCount = BigInteger.valueOf((Long) vertexDegreesHelper.getAccumulator(env, "111u")); BigInteger triplet201Count = BigInteger.valueOf((Long) vertexDegreesHelper.getAccumulator(env, "201")); // triads with three connecting edges = closed triplet = triangle BigInteger triangle030tCount = BigInteger.valueOf((Long) triangleListingHelper.getAccumulator(env, "030t")); BigInteger triangle030cCount = BigInteger.valueOf((Long) triangleListingHelper.getAccumulator(env, "030c")); BigInteger triangle120dCount = BigInteger.valueOf((Long) triangleListingHelper.getAccumulator(env, "120d")); BigInteger triangle120uCount = BigInteger.valueOf((Long) triangleListingHelper.getAccumulator(env, "120u")); BigInteger triangle120cCount = BigInteger.valueOf((Long) triangleListingHelper.getAccumulator(env, "120c")); BigInteger triangle210Count = BigInteger.valueOf((Long) triangleListingHelper.getAccumulator(env, "210")); BigInteger triangle300Count = BigInteger.valueOf((Long) triangleListingHelper.getAccumulator(env, "300")); // triads with two connecting edges = open triplet; // each triangle deducts the count of three triplets triplet201Count = triplet201Count.subtract(triangle300Count.multiply(three)); triplet201Count = triplet201Count.subtract(triangle210Count); triplet111dCount = triplet111dCount.subtract(triangle210Count); triplet111uCount = triplet111uCount.subtract(triangle210Count); triplet111dCount = triplet111dCount.subtract(triangle120cCount); triplet111uCount = triplet111uCount.subtract(triangle120cCount); triplet021cCount = triplet021cCount.subtract(triangle120cCount); triplet111uCount = triplet111uCount.subtract(triangle120uCount.multiply(two)); triplet021uCount = triplet021uCount.subtract(triangle120uCount); triplet111dCount = triplet111dCount.subtract(triangle120dCount.multiply(two)); triplet021dCount = triplet021dCount.subtract(triangle120dCount); triplet021cCount = triplet021cCount.subtract(triangle030cCount.multiply(three)); triplet021cCount = triplet021cCount.subtract(triangle030tCount); triplet021uCount = triplet021uCount.subtract(triangle030tCount); triplet021dCount = triplet021dCount.subtract(triangle030tCount); // triads with one connecting edge; each edge pairs with `vertex count - 2` vertices; // each triangle deducts from three and each open triplet from two edges BigInteger edge102 = bidirectionalEdgeCount.multiply(vertexCount.subtract(two)).subtract(triplet111dCount) .subtract(triplet111uCount).subtract(triplet201Count.multiply(two)).subtract(triangle120dCount) .subtract(triangle120uCount).subtract(triangle120cCount).subtract(triangle210Count.multiply(two)) .subtract(triangle300Count.multiply(three)); BigInteger edge012 = unidirectionalEdgeCount.multiply(vertexCount.subtract(two)) .subtract(triplet021dCount.multiply(two)).subtract(triplet021uCount.multiply(two)) .subtract(triplet021cCount.multiply(two)).subtract(triplet111dCount).subtract(triplet111uCount) .subtract(triangle030tCount.multiply(three)).subtract(triangle030cCount.multiply(three)) .subtract(triangle120dCount.multiply(two)).subtract(triangle120uCount.multiply(two)) .subtract(triangle120cCount.multiply(two)).subtract(triangle210Count); // triads with zero connecting edges; // (vertex count choose 3) minus earlier counts BigInteger triad003 = vertexCount.multiply(vertexCount.subtract(one)).multiply(vertexCount.subtract(two)) .divide(six).subtract(edge012).subtract(edge102).subtract(triplet021dCount) .subtract(triplet021uCount).subtract(triplet021cCount).subtract(triplet111dCount) .subtract(triplet111uCount).subtract(triangle030tCount).subtract(triangle030cCount) .subtract(triplet201Count).subtract(triangle120dCount).subtract(triangle120uCount) .subtract(triangle120cCount).subtract(triangle210Count).subtract(triangle300Count); return new Result(triad003, edge012, edge102, triplet021dCount, triplet021uCount, triplet021cCount, triplet111dCount, triplet111uCount, triangle030tCount, triangle030cCount, triplet201Count, triangle120dCount, triangle120uCount, triangle120cCount, triangle210Count, triangle300Count); }