List of usage examples for java.math BigInteger valueOf
private static BigInteger valueOf(int val[])
From source file:ch.bfh.evoting.verifier.Verifier.java
/** * Recompute the result with the values contained in the XML file, and compare the obtained result * with the result described in the XML file *///w w w .java2 s.co m private static void computeResult() { Element product1 = G_q.getElement(BigInteger.valueOf(1)); for (int j = 0; j < poll.getParticipants().size(); j++) { if (b[j] == null) continue; if (recoveryNeeded) { if (hHatPowX[j] == null) { //this was an excluded participant so we don't care about his values in the tally continue; } product1 = product1.apply(b[j]); product1 = product1.apply(hHatPowX[j]); } else { product1 = product1.apply(b[j]); } } Element sumVote = Z_q.getElement(BigInteger.valueOf(0)); for (int j = 0; j < poll.getOptions().size(); j++) { sumVote = sumVote.apply(representations[j].selfApply(poll.getOptions().get(j).getVotes())); } Element product2 = generator.selfApply(sumVote); if (G_q.areEquivalent(product1, product2)) { System.out.print("\t\t\t\t\t\t\t\t\t\t\t\tCORRECT\n"); System.out.println("\tQuestion was: " + poll.getQuestion()); System.out.println("\tResult was:"); for (XMLOption op : poll.getOptions()) { String votesText = " votes"; if (op.getVotes() == 1) { votesText = " vote"; } System.out.println("\t\t" + op.getText() + ": " + op.getVotes() + votesText); } } else { System.out.print("\t\t\t\t\t\t\t\t\t\t\t\tWRONG\n"); } }
From source file:org.alfresco.jive.cmis.dao.AlfrescoNavigationDAOImpl.java
/** * {@inheritDoc}/*from w w w. j a v a 2 s . c om*/ */ @Override public Document createDocument(RemoteContainer container, String fileName, String contentType, long size, InputStream data) throws CmisConstraintException { Document document = null; Session session = getSession(); try { Folder folder = (Folder) session.getObject(container); // Properties Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, ObjectType.DOCUMENT_BASETYPE_ID + ",P:jive:socialized"); //properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); properties.put(PropertyIds.NAME, fileName); // Content ContentStream cs = new ContentStreamImpl(fileName, BigInteger.valueOf(size), contentType, data); document = folder.createDocument(properties, cs, VersioningState.MAJOR); } finally { try { data.close(); } catch (IOException ex) { // Do nothing } } return document; }
From source file:it.cnr.icar.eric.server.query.QueryManagerImpl.java
@SuppressWarnings("unchecked") private AdhocQueryResponse processForSpecialQueryResults(ServerRequestContext context) throws RegistryException { AdhocQueryResponse ebAdhocQueryResponse = null; try {/*from w ww . j av a 2 s.c o m*/ // Must have been Optimization for a special query like // "urn:oasis:names:tc:ebxml-regrep:query:FindObjectByIdAndType" RegistryObjectListType ebRegistryObjectListType = BindingUtility.getInstance().rimFac .createRegistryObjectListType(); ebRegistryObjectListType.getIdentifiable().addAll((context).getSpecialQueryResults()); (context).setSpecialQueryResults(null); ebAdhocQueryResponse = BindingUtility.getInstance().queryFac.createAdhocQueryResponse(); ebAdhocQueryResponse.setRegistryObjectList(ebRegistryObjectListType); ebAdhocQueryResponse.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success); ebAdhocQueryResponse.setStartIndex(BigInteger.valueOf(0)); ebAdhocQueryResponse.setTotalResultCount(BigInteger.valueOf((context).getQueryResults().size())); } catch (Throwable t) { throw new RegistryException(t); } return ebAdhocQueryResponse; }
From source file:com.sourcesense.opencmis.server.HstCmisRepository.java
/** * CMIS getChildren.// w ww. j a v a2 s . c om */ public ObjectInFolderList getChildren(CallContext context, String folderId, String filter, Boolean includeAllowableActions, Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ObjectInfoHandler objectInfos, HttpServletRequest servletRequest) throws ObjectBeanManagerException, RepositoryException { debug("getChildren"); boolean userReadOnly = checkUser(context, false); // split filter Set<String> filterCollection = splitFilter(filter); // set defaults if values not set boolean iaa = (includeAllowableActions == null ? false : includeAllowableActions.booleanValue()); boolean ips = (includePathSegment == null ? false : includePathSegment.booleanValue()); // skip and max int skip = (skipCount == null ? 0 : skipCount.intValue()); if (skip < 0) { skip = 0; } int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue()); if (max < 0) { max = Integer.MAX_VALUE; } HstRequestContext requestContext = getRequestContext(servletRequest); ObjectBeanPersistenceManager contentPersistenceManager = getContentPersistenceManager(requestContext); // get the folder HippoFolderBean folder = (HippoFolderBean) contentPersistenceManager.getObjectByUuid(folderId); // set object info of the the folder if (context.isObjectInfoRequired()) { compileObjectType(context, folder, null, false, false, userReadOnly, objectInfos); } // prepare result ObjectInFolderListImpl result = new ObjectInFolderListImpl(); result.setObjects(new ArrayList<ObjectInFolderData>()); result.setHasMoreItems(false); int count = 0; // iterate through children List children = folder.getFolders(); children.addAll(folder.getDocuments()); while (children.iterator().hasNext()) { HippoBean child = (HippoBean) children.iterator().next(); count++; if (skip > 0) { skip--; continue; } if (result.getObjects().size() >= max) { result.setHasMoreItems(true); continue; } // build and add child object ObjectInFolderDataImpl objectInFolder = new ObjectInFolderDataImpl(); objectInFolder.setObject( compileObjectType(context, child, filterCollection, iaa, false, userReadOnly, objectInfos)); if (ips) { objectInFolder.setPathSegment(child.getName()); } result.getObjects().add(objectInFolder); } result.setNumItems(BigInteger.valueOf(count)); return result; }
From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java
private BigInteger step3ComputeLowerBound(final BigInteger s, final BigInteger modulus, final BigInteger lowerIntervalBound) { BigInteger lowerBound = lowerIntervalBound.multiply(s); lowerBound = lowerBound.subtract(BigInteger.valueOf(3).multiply(this.bigB)); lowerBound = lowerBound.add(BigInteger.ONE); lowerBound = lowerBound.divide(modulus); return lowerBound; }
From source file:com.ephesoft.dcma.tablefinder.share.TableRowFinderUtility.java
/** * Gets sorted list of spans of the page. * /*from w ww .j a v a 2 s . co m*/ * @param spans {@link Spans} * @return {@link List}<{@link Span}> */ private static List<Span> getSortedSpanList(final Spans spans) { final List<Span> spanList = spans.getSpan(); final Set<Span> set = new TreeSet<Span>(new Comparator<Span>() { public int compare(final Span firstSpan, final Span secSpan) { BigInteger s1Y0 = firstSpan.getCoordinates().getY0(); BigInteger s1Y1 = firstSpan.getCoordinates().getY1(); final BigInteger s2Y0 = secSpan.getCoordinates().getY0(); final BigInteger s2Y1 = secSpan.getCoordinates().getY1(); int halfOfSecSpan = (s2Y1.intValue() - s2Y0.intValue()) / 2; int y1 = s2Y1.intValue() + halfOfSecSpan; int y0 = s2Y0.intValue() - halfOfSecSpan; // following if else code is to handle abnormal(out of synch) value y0 or y1 coordinate of new span. if (isApproxEqual(s1Y0.intValue(), s2Y0.intValue()) && s1Y1.intValue() > y1) { s1Y1 = BigInteger.valueOf(y1); firstSpan.getCoordinates().setY1(s1Y1); } else if (isApproxEqual(s1Y1.intValue(), s2Y1.intValue()) && s1Y0.intValue() < y0) { s1Y0 = BigInteger.valueOf(y0); firstSpan.getCoordinates().setY0(s1Y0); } final BigInteger s1Y = s1Y1.add(s1Y0); final BigInteger s2Y = s2Y1.add(s2Y0); // calculating middle of old span. final int oldSpanMid = s2Y.intValue() / 2; int returnValue = 0; // if old span's y coordinate's middle lies within range of new span's y coordinates or not. if true, the two spans // belong to same line compare them further on their x coordinates, else they belong to two different lines. if (oldSpanMid >= s1Y0.intValue() && oldSpanMid <= s1Y1.intValue()) { final BigInteger s1X1 = firstSpan.getCoordinates().getX1(); final BigInteger s2X1 = secSpan.getCoordinates().getX1(); returnValue = s1X1.compareTo(s2X1); } else { returnValue = s1Y.compareTo(s2Y); } return returnValue; } }); set.addAll(spanList); final List<Span> linkedList = new LinkedList<Span>(); linkedList.addAll(set); // TODO add the clear method to remove all elements of set since it not required after adding it to linked list. // set.clear(); return linkedList; }
From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java
public BigInteger setEncryptedPasswd(String encryptedPasswd) throws MgmtException { HashMap map = new HashMap(); try {//from w w w.jav a2s .com map.put(ConfigPropertyNames.PROP_ADMIN_PASSWD, decode(encryptedPasswd)); } catch (DecoderException e) { logger.log(Level.SEVERE, "failed to decode string " + encryptedPasswd); // // Internationalize here // throw new MgmtException("Internal error, failed to decode password."); } setCellProperties(map); return BigInteger.valueOf(0); }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransactionTest.java
@Test public void testTransactionAtomicity() throws Exception { // This test runs multiple transactions in parallel, with KeyValueService.put calls throwing // a RuntimeException from time to time and hanging other times. which effectively kills the // thread. We ensure that every transaction either adds 5 rows to the table or adds 0 rows // by checking at the end that the number of rows is a multiple of 5. final String tableName = "table"; Random random = new Random(1); final UnstableKeyValueService unstableKvs = new UnstableKeyValueService(keyValueService, random); final TestTransactionManager unstableTransactionManager = new TestTransactionManagerImpl(unstableKvs, timestampService, lockClient, lockService, transactionService, conflictDetectionManager, sweepStrategyManager);/* w ww . j a v a 2 s . co m*/ ScheduledExecutorService service = PTExecutors.newScheduledThreadPool(20); for (int i = 0; i < 30; i++) { final int threadNumber = i; service.schedule(new Callable<Void>() { @Override public Void call() throws Exception { if (threadNumber == 10) { unstableKvs.setRandomlyThrow(true); } if (threadNumber == 20) { unstableKvs.setRandomlyHang(true); } Transaction transaction = unstableTransactionManager.createNewTransaction(); BatchingVisitable<RowResult<byte[]>> results = transaction.getRange(tableName, RangeRequest.builder().build()); final MutableInt nextIndex = new MutableInt(0); results.batchAccept(1, AbortingVisitors.batching(new AbortingVisitor<RowResult<byte[]>, Exception>() { @Override public boolean visit(RowResult<byte[]> row) throws Exception { byte[] dataBytes = row.getColumns().get("data".getBytes()); BigInteger dataValue = new BigInteger(dataBytes); nextIndex.setValue(Math.max(nextIndex.toInteger(), dataValue.intValue() + 1)); return true; } })); // nextIndex now contains the least row number not already in the table. Add 5 more // rows to the table. for (int j = 0; j < 5; j++) { int rowNumber = nextIndex.toInteger() + j; Cell cell = Cell.create(("row" + rowNumber).getBytes(), "data".getBytes()); transaction.put(tableName, ImmutableMap.of(cell, BigInteger.valueOf(rowNumber).toByteArray())); Thread.yield(); } transaction.commit(); return null; } }, i * 20, TimeUnit.MILLISECONDS); } service.shutdown(); service.awaitTermination(1, TimeUnit.SECONDS); // Verify each table has a number of rows that's a multiple of 5 Transaction verifyTransaction = txManager.createNewTransaction(); BatchingVisitable<RowResult<byte[]>> results = verifyTransaction.getRange(tableName, RangeRequest.builder().build()); final MutableInt numRows = new MutableInt(0); results.batchAccept(1, AbortingVisitors.batching(new AbortingVisitor<RowResult<byte[]>, Exception>() { @Override public boolean visit(RowResult<byte[]> row) throws Exception { numRows.increment(); return true; } })); Assert.assertEquals(0, numRows.toInteger() % 5); }
From source file:edu.harvard.i2b2.fhir.FhirUtil.java
public static Bundle getResourceBundle(List<Resource> s, String basePath, String url) { Bundle b = new Bundle(); for (Resource r : s) { if (r.getMeta() == null) { r.setMeta(FhirUtil.createMeta()); }//from w ww . j a v a 2 s . c o m BundleEntry be = FhirUtil.newBundleEntryForResource(r); b.getEntry().add(be); } BundleType value = new BundleType(); value.setValue(BundleTypeList.SEARCHSET); b.setType(value); UnsignedInt total = new UnsignedInt(); total.setValue(BigInteger.valueOf(s.size())); b.setTotal(total); Uri u = new Uri(); u.setValue(basePath); FhirUtil.setId(b, Long.toHexString(new Random().nextLong())); b.setMeta(FhirUtil.createMeta()); // b.setBase(u); return b; }
From source file:edu.unc.lib.dl.fedora.ManagementClient.java
public List<PID> getNextPID(int number, String namespace) throws FedoraException { List<PID> result = new ArrayList<PID>(); GetNextPID req = new GetNextPID(); req.setNumPIDs(BigInteger.valueOf(number)); if (namespace != null) { req.setPidNamespace(namespace);// w w w .j a va 2s . c om } GetNextPIDResponse resp = (GetNextPIDResponse) this.callService(req, Action.getNextPID); List<String> pids = resp.getPid(); for (String pid : pids) { result.add(new PID(pid)); } return result; }