List of usage examples for java.math BigInteger ZERO
BigInteger ZERO
To view the source code for java.math BigInteger ZERO.
Click Source Link
From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.graph.EntityGraphJGraphT.java
/** * Computes the depth of the graph, i.e. the maximum path length starting with the root node (if * a single root exists)// w ww .j a va2 s .co m * * @return The depth of the hierarchy. * @throws UnsupportedOperationException * @throws LexicalSemanticResourceException */ private double computeDepth() throws LexicalSemanticResourceException { List<Entity> roots = new Stack<Entity>(); roots.addAll(getRoots()); if (roots.size() == 0) { logger.error("There is no root for this lexical semantic resource."); return Double.NaN; } else if (roots.size() > 1) { logger.warn("There are " + roots.size() + " roots for this lexical semantic resource."); logger.info("Trying to get root from underlying lexical semantic resource."); Entity root = lexSemRes.getRoot(); if (root == null) { EntityGraph lcc = getLargestConnectedComponent(); int nrOfLccNodes = lcc.getNumberOfNodes(); int nrOfGraphNodes = this.getNumberOfNodes(); double ratio = (double) nrOfLccNodes / (double) nrOfGraphNodes; logger.info("Falling back to the depth of the LCC."); if (ratio < 0.7) { logger.warn("The largest connected component contains only " + ratio * 100 + "% of all nodes. Depth might not be meaningful."); } return lcc.getDepth(); } else { roots.clear(); // we know the real root, so remove the others roots.add(root); } } Entity root = roots.get(0); BigInteger bigMaxPathLength = BigInteger.valueOf(0); BigInteger[] returnValues = computeShortestPathLengths(root, BigInteger.ZERO, bigMaxPathLength, new HashSet<Entity>()); bigMaxPathLength = returnValues[1]; return bigMaxPathLength.doubleValue(); }
From source file:net.sf.json.TestJSONArray.java
public void testToArray_BigInteger() { BigInteger[] expected = new BigInteger[] { BigInteger.ZERO, BigInteger.ONE }; JSONArray jsonArray = JSONArray.fromObject(expected); Object actual = JSONArray.toArray(jsonArray); Assertions.assertEquals(expected, actual); }
From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java
/** * Update the service tag data associated with a single cell. This routine * must be called on ever cell in order to keep the silo_info.xml * up to date.// w w w. j a v a2 s . c o m * <P> * On the master cell this routine will clear the service tag registry * and attempt to repopulate it with the new service tag registry * information. * @param evt the callback handle * @param tagData the service tag data to update * @param updateRegistry boolean to indicate whether the registry * file should be rebuilt. If the callee already knows the * service tag data is invalid they will call this value with a * value of 0. In this case this api is getting used to clear the * registry and the instanceURNs * @return BigInteger, 0 for SUCCESS, -1 for failure. * Currently always returns 0 * @throws com.sun.honeycomb.mgmt.common.MgmtException */ public BigInteger updateAllServiceTagData(EventSender evt, HCServiceTags tagData, BigInteger updateRegistry) throws MgmtException { boolean updateRegistryFile = updateRegistry.intValue() == 1; MultiCellLib multiCell = MultiCellLib.getInstance(); boolean isStandAlone = multiCell.isCellStandalone(); StringBuffer buf = new StringBuffer(); buf.append(" service tag data for cell"); if (isStandAlone == false) { buf.append(" ").append(getCellId()); } buf.append("."); Reassure reassureThread = null; try { reassureThread = new Reassure(evt); reassureThread.start(); boolean isSupported = ServiceTagsRegistry.isSupported(); boolean isMaster = multiCell.isCellMaster(); if (isSupported && isMaster) { // If we modify an service tag data the service tag registry // is considered out of date. As such we clear the registry // of all ST5800 service tags. clearRegistry(); } List<HCServiceTagCellData> list = tagData.getData(); HCServiceTagCellData[] hCellData = (HCServiceTagCellData[]) list .toArray(new HCServiceTagCellData[list.size()]); ServiceTagCellData[] cellData = new ServiceTagCellData[hCellData.length]; for (int i = 0; i < hCellData.length; i++) { ServiceTagData data = new ServiceTagData(hCellData[i].getProductNumber(), hCellData[i].getProductSerialNumber(), hCellData[i].getMarketingNumber(), hCellData[i].getInstanceURN()); ServiceTagCellData cell = new ServiceTagCellData(hCellData[i].getCellId(), data); cellData[i] = cell; } multiCell.updateServiceTagData(cellData); buf.insert(0, "Successfully updated"); logger.log(Level.INFO, buf.toString()); //evt.sendAsynchronousEvent(buf.toString()); if (updateRegistryFile && isMaster) { // Reset the buf to new action in case of exception buf = new StringBuffer(" service tag registry."); if (isSupported == false) { evt.sendAsynchronousEvent(SERVICE_TAG_REGISTRY_IS_NOT_AVAILABLE_MSG); return BigInteger.valueOf(CliConstants.FAILURE); } // The silo_info.xml has been updated. // Now update the service tag registry ServiceTagsGenerator generator = new ServiceTagsGenerator(cellData); if (generator.isValid() == false) { // This should technically never happen is everything is // done via the cli since the validation check on the cli // side should of failed and prevented this call from // ever occurring buf = new StringBuffer(); buf.append("Failed to update service tag registry due to a "); buf.append("validation error.\nSee logs for further details."); // Validation errors found via ServiceTagsGenerator are // logged by default evt.sendAsynchronousEvent(buf.toString()); return BigInteger.valueOf(CliConstants.SERVICE_TAG_REGISTRY_VALIDATION_FAILURE); } else { ServiceTagsRegistry.update(generator.getServiceTags()); buf.insert(0, "Successfully updated"); logger.log(Level.INFO, buf.toString()); } } return BigInteger.ZERO; } catch (MultiCellLibError mcle) { buf.insert(0, "Failed to update"); logger.log(Level.SEVERE, buf.toString(), mcle); buf.append(" Reason: "); buf.append(mcle.getMessage()); buf.append(".\n"); buf.append("Ensure that the servicetag entries are all valid by invoking the command,\n"); buf.append("'servicetags --refresh'."); evt.sendAsynchronousEvent(buf.toString()); return BigInteger.valueOf(CliConstants.FAILURE); } catch (Exception ex) { buf.insert(0, "Failed to update"); logger.log(Level.SEVERE, buf.toString(), ex); buf.append(" Reason: "); buf.append(ex.getMessage()); buf.append(".\n"); buf.append("Ensure that the servicetag entries are all valid by invoking the command,\n"); buf.append("'servicetags --refresh'"); evt.sendAsynchronousEvent(buf.toString()); return BigInteger.valueOf(CliConstants.FAILURE); } finally { if (reassureThread != null) reassureThread.safeStop(); } }
From source file:edu.cudenver.bios.power.GLMMPowerCalculator.java
/** * Calculate power by integrating over all possible values of the * non-centrality parameter. Best used for designs with a * baseline covariate//from ww w .j a v a2s .com * * @param params GLMM input parameters * @return unconditional power * @throws PowerException */ private double getUnconditionalPower(GLMMTest glmmTest, NonCentralityDistribution nonCentralityDist, double alpha) throws PowerException { // get the approximate critical F value (central F) under the null hypothesis double Fcrit = glmmTest.getCriticalF(GLMMTest.DistributionType.POWER_NULL, alpha); // get the distribution of the noncentrality parameter double ndf = glmmTest.getNumeratorDF(GLMMTest.DistributionType.POWER_ALTERNATIVE); double ddf = glmmTest.getDenominatorDF(GLMMTest.DistributionType.POWER_ALTERNATIVE); debug("Fcrit = " + Fcrit + ", ndf = " + ndf + ", ddf = " + ddf); double h1 = nonCentralityDist.getH1(); double h0 = nonCentralityDist.getH0(); debug("h0 = " + h0 + ", h1 = " + h1); try { if (h1 < h0) { throw new IllegalArgumentException("Integration bounds are " + h0 + " and " + h1 + "."); } double integralResult; numberOfEvaluations = BigInteger.ZERO; if (h1 > h0) { // integrate over all values of non-centrality parameter from h0 to h1 SimpsonIntegrator integrator = new SimpsonIntegrator(); UnconditionalPowerIntegrand integrand = new UnconditionalPowerIntegrand(nonCentralityDist, Fcrit, ndf, ddf); integralResult = integrator.integrate(MAX_EVALUATIONS, integrand, h0, h1); } else { integralResult = 0; } final double I = integralResult; debug(new Supplier<Object>() { @Override public Object get() { return "done with integration: " + "result = " + I + ", " + "number of evaluations = " + numberOfEvaluations + ", " + "log = " + (int) (Math.log(numberOfEvaluations.longValue() - 3) / LOG2 + 0.5); } }); // create a noncentral F dist with non-centrality of H1 NonCentralFDistribution fdist = new NonCentralFDistribution(ndf, ddf, h1); return (1 - fdist.cdf(Fcrit) - 0.5 * integralResult); } catch (RuntimeException e) { LOGGER.warn("exiting getUnconditionalPower abnormally", e); throw new PowerException(e.getMessage(), PowerErrorEnum.INTEGRATION_OVER_DISTRIBUTION_NONCENTRALITY_PARAMETER_FAILED); } }
From source file:org.limewire.mojito.Context.java
public synchronized BigInteger size() { if (!isRunning()) { return BigInteger.ZERO; }/*from w w w. ja va2s .c o m*/ return estimator.getEstimatedSize(getRouteTable()); }
From source file:cz.cas.lib.proarc.common.export.mets.structure.MetsElementVisitor.java
/** * Generates the premis for amdSec/*from www . j a v a2 s.co m*/ * * @param metsElement * @param datastream * @param md5Info * @param created * @param formatVersion * @return * @throws MetsExportException */ private Node getPremisFile(IMetsElement metsElement, String datastream, FileMD5Info md5Info) throws MetsExportException { PremisComplexType premis = new PremisComplexType(); ObjectFactory factory = new ObjectFactory(); JAXBElement<PremisComplexType> jaxbPremix = factory.createPremis(premis); cz.cas.lib.proarc.premis.File file = factory.createFile(); premis.getObject().add(file); ObjectIdentifierComplexType objectIdentifier = new ObjectIdentifierComplexType(); objectIdentifier.setObjectIdentifierType("ProArc_URI"); objectIdentifier.setObjectIdentifierValue( Const.FEDORAPREFIX + metsElement.getOriginalPid() + "/" + Const.dataStreamToModel.get(datastream)); file.getObjectIdentifier().add(objectIdentifier); PreservationLevelComplexType preservation = new PreservationLevelComplexType(); if ("RAW".equals(datastream)) { preservation.setPreservationLevelValue("deleted"); } else { preservation.setPreservationLevelValue("preservation"); } file.getPreservationLevel().add(preservation); ObjectCharacteristicsComplexType characteristics = new ObjectCharacteristicsComplexType(); characteristics.setCompositionLevel(BigInteger.ZERO); file.getObjectCharacteristics().add(characteristics); FixityComplexType fixity = new FixityComplexType(); fixity.setMessageDigest(md5Info.getMd5()); fixity.setMessageDigestAlgorithm("MD5"); fixity.setMessageDigestOriginator("ProArc"); characteristics.getFixity().add(fixity); characteristics.setSize(md5Info.getSize()); FormatComplexType format = new FormatComplexType(); characteristics.getFormat().add(format); FormatDesignationComplexType formatDesignation = new FormatDesignationComplexType(); formatDesignation.setFormatName(md5Info.getMimeType()); formatDesignation.setFormatVersion(md5Info.getFormatVersion()); JAXBElement<FormatDesignationComplexType> jaxbDesignation = factory .createFormatDesignation(formatDesignation); format.getContent().add(jaxbDesignation); FormatRegistryComplexType formatRegistry = new FormatRegistryComplexType(); formatRegistry.setFormatRegistryName("PRONOM"); formatRegistry.setFormatRegistryKey(Const.mimeToFmtMap.get(md5Info.getMimeType())); JAXBElement<FormatRegistryComplexType> jaxbRegistry = factory.createFormatRegistry(formatRegistry); format.getContent().add(jaxbRegistry); CreatingApplicationComplexType creatingApplication = new CreatingApplicationComplexType(); characteristics.getCreatingApplication().add(creatingApplication); creatingApplication.getContent().add(factory.createCreatingApplicationName("ProArc")); creatingApplication.getContent() .add(factory.createCreatingApplicationVersion(metsElement.getMetsContext().getProarcVersion())); creatingApplication.getContent() .add(factory.createDateCreatedByApplication(MetsUtils.getCurrentDate().toXMLFormat())); RelationshipComplexType relationShip = new RelationshipComplexType(); if (!("RAW").equals(datastream)) { relationShip.setRelationshipType("derivation"); relationShip.setRelationshipSubType("created from"); RelatedObjectIdentificationComplexType relatedObject = new RelatedObjectIdentificationComplexType(); relationShip.getRelatedObjectIdentification().add(relatedObject); relatedObject.setRelatedObjectIdentifierType("ProArc_URI"); relatedObject.setRelatedObjectIdentifierValue( Const.FEDORAPREFIX + metsElement.getOriginalPid() + "/" + Const.dataStreamToModel.get("RAW")); RelatedEventIdentificationComplexType eventObject = new RelatedEventIdentificationComplexType(); relationShip.getRelatedEventIdentification().add(eventObject); eventObject.setRelatedEventIdentifierType("ProArc_EventID"); eventObject.setRelatedEventIdentifierValue(Const.dataStreamToEvent.get(datastream)); eventObject.setRelatedEventSequence(BigInteger.ONE); file.getRelationship().add(relationShip); } else { relationShip.setRelationshipType("creation"); relationShip.setRelationshipSubType("created from"); LinkingEventIdentifierComplexType eventIdentifier = new LinkingEventIdentifierComplexType(); file.getLinkingEventIdentifier().add(eventIdentifier); eventIdentifier.setLinkingEventIdentifierType("ProArc_EventID"); eventIdentifier.setLinkingEventIdentifierValue(Const.dataStreamToEvent.get(datastream)); } String originalFile = MetsUtils.xPathEvaluateString(metsElement.getRelsExt(), "*[local-name()='RDF']/*[local-name()='Description']/*[local-name()='importFile']"); OriginalNameComplexType originalName = factory.createOriginalNameComplexType(); originalName.setValue(originalFile); file.setOriginalName(originalName); JAXBContext jc; try { jc = JAXBContext.newInstance(PremisComplexType.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.newDocument(); // Marshal the Object to a Document Marshaller marshaller = jc.createMarshaller(); marshaller.marshal(jaxbPremix, document); XPath xpath = XPathFactory.newInstance().newXPath(); Node premisNode = (Node) xpath.compile("*[local-name()='premis']/*[local-name()='object']") .evaluate(document, XPathConstants.NODE); return premisNode; } catch (Exception e) { throw new MetsExportException(metsElement.getOriginalPid(), "Error while generating premis data", false, e); } }
From source file:piuk.blockchain.android.MyRemoteWallet.java
public Pair<Transaction, Long> makeTransaction(boolean isSimpleSend, List<MyTransactionOutPoint> unspent, HashMap<String, BigInteger> receivingAddresses, BigInteger fee, final String changeAddress) throws Exception { long priority = 0; if (unspent == null || unspent.size() == 0) throw new InsufficientFundsException("No free outputs to spend."); if (fee == null) fee = BigInteger.ZERO; //Construct a new transaction Transaction tx = new Transaction(getParams()); BigInteger outputValueSum = BigInteger.ZERO; for (Iterator<Entry<String, BigInteger>> iterator = receivingAddresses.entrySet().iterator(); iterator .hasNext();) {/* w w w.j a v a 2s. c om*/ Map.Entry<String, BigInteger> mapEntry = iterator.next(); String toAddress = mapEntry.getKey(); BigInteger amount = mapEntry.getValue(); if (amount == null || amount.compareTo(BigInteger.ZERO) <= 0) throw new Exception("You must provide an amount"); outputValueSum = outputValueSum.add(amount); //Add the output BitcoinScript toOutputScript = BitcoinScript.createSimpleOutBitoinScript(new BitcoinAddress(toAddress)); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransaction toAddress: " + toAddress + "amount: " + amount); TransactionOutput output = new TransactionOutput(getParams(), null, amount, toOutputScript.getProgram()); tx.addOutput(output); } //Now select the appropriate inputs BigInteger valueSelected = BigInteger.ZERO; BigInteger valueNeeded = outputValueSum.add(fee); BigInteger minFreeOutputSize = BigInteger.valueOf(1000000); MyTransactionOutPoint changeOutPoint = null; for (MyTransactionOutPoint outPoint : unspent) { BitcoinScript script = new BitcoinScript(outPoint.getScriptBytes()); if (script.getOutType() == BitcoinScript.ScriptOutTypeStrange) continue; BitcoinScript inputScript = new BitcoinScript(outPoint.getConnectedPubKeyScript()); String address = inputScript.getAddress().toString(); //if isSimpleSend don't use address as input if is output if (isSimpleSend && receivingAddresses.get(address) != null) continue; MyTransactionInput input = new MyTransactionInput(getParams(), null, new byte[0], outPoint); input.outpoint = outPoint; // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransaction fromAddress: " + address + "amount: " + outPoint.value); tx.addInput(input); valueSelected = valueSelected.add(outPoint.value); priority += outPoint.value.longValue() * outPoint.confirmations; if (changeAddress == null) changeOutPoint = outPoint; if (valueSelected.compareTo(valueNeeded) == 0 || valueSelected.compareTo(valueNeeded.add(minFreeOutputSize)) >= 0) break; } //Check the amount we have selected is greater than the amount we need if (valueSelected.compareTo(valueNeeded) < 0) { throw new InsufficientFundsException("Insufficient Funds"); } BigInteger change = valueSelected.subtract(outputValueSum).subtract(fee); //Now add the change if there is any if (change.compareTo(BigInteger.ZERO) > 0) { BitcoinScript change_script; if (changeAddress != null) { change_script = BitcoinScript.createSimpleOutBitoinScript(new BitcoinAddress(changeAddress)); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransaction changeAddress != null: " + changeAddress + "change: " + change); } else if (changeOutPoint != null) { BitcoinScript inputScript = new BitcoinScript(changeOutPoint.getConnectedPubKeyScript()); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransaction changeAddress == null: " + inputScript.getAddress() + "change: " + change); //Return change to the first address change_script = BitcoinScript.createSimpleOutBitoinScript(inputScript.getAddress()); } else { throw new Exception("Invalid transaction attempt"); } TransactionOutput change_output = new TransactionOutput(getParams(), null, change, change_script.getProgram()); tx.addOutput(change_output); } long estimatedSize = tx.bitcoinSerialize().length + (114 * tx.getInputs().size()); priority /= estimatedSize; return new Pair<Transaction, Long>(tx, priority); }
From source file:com.workday.autoparse.json.parser.JsonParserUtils.java
public static BigInteger nextBigInteger(JsonReader reader, String name) throws IOException { if (handleNull(reader)) { return BigInteger.ZERO; }/*from w w w .j av a 2 s . c o m*/ assertType(reader, name, JsonToken.NUMBER, JsonToken.STRING); return new BigInteger(reader.nextString()); }
From source file:com.facebook.infrastructure.service.StorageService.java
public String getToken(EndPoint ep) { EndPoint ep2 = new EndPoint(ep.getHost(), DatabaseDescriptor.getStoragePort()); BigInteger token = tokenMetadata_.getToken(ep2); return (token == null) ? BigInteger.ZERO.toString() : token.toString(); }
From source file:org.egov.ptis.service.utils.PropertyTaxCommonUtils.java
public BigInteger getModuleIdByName() { BigInteger id = BigInteger.ZERO; String selectQuery = " select id from eg_modules where name =:name "; final Query qry = getSession().createSQLQuery(selectQuery).setString("name", PropertyTaxConstants.FILESTORE_MODULE_NAME); List<Object> list = qry.list(); if (!list.isEmpty()) id = (BigInteger) list.get(0); return id;/*from w ww .ja v a 2 s. co m*/ }