List of usage examples for java.math BigInteger toString
public String toString()
From source file:com.exilant.eGov.src.common.EGovernCommon.java
/** * * @param vouType Eg - U/DBP/CGVN// w ww . j a va2 s .c om * @param fiscialPeriod * @param conn * @return * @throws TaskFailedException,Exception */ public String getEg_Voucher(final String vouType, final String fiscalPeriodIdStr) throws TaskFailedException, Exception { if (LOGGER.isDebugEnabled()) LOGGER.debug(" In EGovernCommon :getEg_Voucher method "); final CFiscalPeriod fiscalPeriod = (CFiscalPeriod) persistenceService.find("from CFiscalPeriod where id=?", Long.parseLong(fiscalPeriodIdStr)); BigInteger cgvn = null; String sequenceName = ""; // Sequence name will be SQ_U_DBP_CGVN_FP7 for vouType U/DBP/CGVN and fiscalPeriodIdStr 7 try { sequenceName = VoucherHelper.sequenceNameFor(vouType, fiscalPeriod.getName()); cgvn = (BigInteger) databaseSequenceProvider.getNextSequence(sequenceName); if (LOGGER.isDebugEnabled()) LOGGER.debug("----- CGVN : " + cgvn); } catch (final SQLGrammarException e) { databaseSequenceCreator.createSequence(sequenceName); cgvn = (BigInteger) databaseSequenceProvider.getNextSequence(sequenceName); LOGGER.error("Error in generating CGVN" + e); throw new ValidationException(Arrays.asList(new ValidationError(e.getMessage(), e.getMessage()))); } catch (final Exception e) { LOGGER.error("Error in generating CGVN" + e); throw new ValidationException(Arrays.asList(new ValidationError(e.getMessage(), e.getMessage()))); } return cgvn.toString(); }
From source file:org.ethereum.rpc.Web3Impl.java
public BlockResult getBlockResult(Block b, boolean fullTx) { if (b == null) return null; byte[] mergeHeader = b.getBitcoinMergedMiningHeader(); boolean isPending = (mergeHeader == null || mergeHeader.length == 0) && !b.isGenesis(); BlockResult br = new BlockResult(); br.number = isPending ? null : TypeConverter.toJsonHex(b.getNumber()); br.hash = isPending ? null : TypeConverter.toJsonHex(b.getHash()); br.parentHash = TypeConverter.toJsonHex(b.getParentHash()); br.sha3Uncles = TypeConverter.toJsonHex(b.getUnclesHash()); br.logsBloom = isPending ? null : TypeConverter.toJsonHex(b.getLogBloom()); br.transactionsRoot = TypeConverter.toJsonHex(b.getTxTrieRoot()); br.stateRoot = TypeConverter.toJsonHex(b.getStateRoot()); br.receiptsRoot = TypeConverter.toJsonHex(b.getReceiptsRoot()); br.miner = isPending ? null : TypeConverter.toJsonHex(b.getCoinbase()); br.difficulty = TypeConverter.toJsonHex(b.getDifficulty()); br.totalDifficulty = TypeConverter.toJsonHex(worldManager.getBlockchain().getTotalDifficulty()); br.extraData = TypeConverter.toJsonHex(b.getExtraData()); br.size = TypeConverter.toJsonHex(b.getEncoded().length); br.gasLimit = TypeConverter.toJsonHex(b.getGasLimit()); BigInteger mgp = b.getMinGasPriceAsInteger(); br.minimumGasPrice = mgp != null ? mgp.toString() : ""; br.gasUsed = TypeConverter.toJsonHex(b.getGasUsed()); br.timestamp = TypeConverter.toJsonHex(b.getTimestamp()); List<Object> txes = new ArrayList<>(); if (fullTx) { for (int i = 0; i < b.getTransactionsList().size(); i++) { txes.add(new TransactionResultDTO(b, i, b.getTransactionsList().get(i))); }/*from w w w . ja v a 2 s . com*/ } else { for (Transaction tx : b.getTransactionsList()) { txes.add(toJsonHex(tx.getHash())); } } br.transactions = txes.toArray(); List<String> ul = new ArrayList<>(); for (BlockHeader header : b.getUncleList()) { ul.add(toJsonHex(header.getHash())); } br.uncles = ul.toArray(new String[ul.size()]); return br; }
From source file:com.spotify.reaper.cassandra.JmxProxy.java
/** * Triggers a repair of range (beginToken, endToken] for given keyspace and column family. * The repair is triggered by {@link org.apache.cassandra.service.StorageServiceMBean#forceRepairRangeAsync} * For time being, we don't allow local nor snapshot repairs. * * @return Repair command number, or 0 if nothing to repair * @throws ReaperException /*from www. j av a 2s . com*/ */ public int triggerRepair(BigInteger beginToken, BigInteger endToken, String keyspace, RepairParallelism repairParallelism, Collection<String> columnFamilies, boolean fullRepair) throws ReaperException { checkNotNull(ssProxy, "Looks like the proxy is not connected"); String cassandraVersion = getCassandraVersion(); boolean canUseDatacenterAware = false; try { canUseDatacenterAware = versionCompare(cassandraVersion, "2.0.12") >= 0; } catch (ReaperException e) { LOG.warn("failed on version comparison, not using dc aware repairs by default", e); } String msg = String.format( "Triggering repair of range (%s,%s] for keyspace \"%s\" on " + "host %s, with repair parallelism %s, in cluster with Cassandra " + "version '%s' (can use DATACENTER_AWARE '%s'), " + "for column families: %s", beginToken.toString(), endToken.toString(), keyspace, this.host, repairParallelism, cassandraVersion, canUseDatacenterAware, columnFamilies); LOG.info(msg); if (repairParallelism.equals(RepairParallelism.DATACENTER_AWARE) && !canUseDatacenterAware) { LOG.info("Cannot use DATACENTER_AWARE repair policy for Cassandra cluster with version {}," + " falling back to SEQUENTIAL repair.", cassandraVersion); repairParallelism = RepairParallelism.SEQUENTIAL; } try { if (cassandraVersion.startsWith("2.0") || cassandraVersion.startsWith("1.")) { return triggerRepairPre2dot1(repairParallelism, keyspace, columnFamilies, beginToken, endToken); } else if (cassandraVersion.startsWith("2.1")) { return triggerRepair2dot1(fullRepair, repairParallelism, keyspace, columnFamilies, beginToken, endToken, cassandraVersion); } else { return triggerRepairPost2dot2(fullRepair, repairParallelism, keyspace, columnFamilies, beginToken, endToken, cassandraVersion); } } catch (Exception e) { LOG.error("Segment repair failed", e); throw new ReaperException(e); } }
From source file:net.pms.util.Rational.java
/** * Used internally to generate a rational string representation from two * {@link BigInteger}s.//from w w w .j av a 2 s .c o m * * @param numerator the numerator. * @param denominator the denominator. * @return The rational string representation. */ @Nonnull protected static String generateRationalString(@Nonnull BigInteger numerator, @Nonnull BigInteger denominator) { if (denominator.signum() == 0) { if (numerator.signum() == 0) { return "NaN"; } return numerator.signum() > 0 ? "\u221e" : "-\u221e"; } if (BigInteger.ONE.equals(denominator)) { return numerator.toString(); } return numerator.toString() + "/" + denominator.toString(); }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
@Override public String findUsernameByIssuerDnAndSerialNumber(String issuerDn, BigInteger serialNumber) { return CertificateData.findUsernameByIssuerDnAndSerialNumber(entityManager, issuerDn, serialNumber.toString()); }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
@Override public CertificateInfo findFirstCertificateInfo(final String issuerDN, final BigInteger serno) { return CertificateData.findFirstCertificateInfo(entityManager, CertTools.stringToBCDNString(issuerDN), serno.toString()); }
From source file:net.pms.util.Rational.java
/** * Used internally to generate a decimal string representation from two * {@link BigInteger}s. The decimal representation is limited to 20 * decimals.// www.ja va 2s .co m * * @param numerator the numerator. * @param denominator the denominator. * @param decimalFormat the {@link DecimalFormat} instance to use for * formatting. * @return The string representation. */ protected static String generateDecimalString(@Nonnull BigInteger numerator, @Nonnull BigInteger denominator, @Nonnull DecimalFormat decimalFormat) { if (denominator.signum() == 0) { if (numerator.signum() == 0) { return "NaN"; } return numerator.signum() > 0 ? "\u221e" : "-\u221e"; } if (BigInteger.ONE.equals(denominator)) { return numerator.toString(); } BigDecimal decimalValue = new BigDecimal(numerator).divide(new BigDecimal(denominator), 20, RoundingMode.HALF_EVEN); return decimalFormat.format(decimalValue); }
From source file:org.apache.manifoldcf.crawler.connectors.cmis.CmisRepositoryConnector.java
/** Process a set of documents. * This is the method that should cause each document to be fetched, processed, and the results either added * to the queue of documents for the current job, and/or entered into the incremental ingestion manager. * The document specification allows this class to filter what is done based on the job. * The connector will be connected before this method can be called. *@param documentIdentifiers is the set of document identifiers to process. *@param statuses are the currently-stored document versions for each document in the set of document identifiers * passed in above.// w ww. j av a 2 s . c o m *@param activities is the interface this method should use to queue up new document references * and ingest documents. *@param jobMode is an integer describing how the job is being run, whether continuous or once-only. *@param usesDefaultAuthority will be true only if the authority in use for these documents is the default one. */ @Override public void processDocuments(String[] documentIdentifiers, IExistingVersions statuses, Specification spec, IProcessActivity activities, int jobMode, boolean usesDefaultAuthority) throws ManifoldCFException, ServiceInterruption { // Extract what we need from the spec String cmisQuery = StringUtils.EMPTY; for (int i = 0; i < spec.getChildCount(); i++) { SpecificationNode sn = spec.getChild(i); if (sn.getType().equals(JOB_STARTPOINT_NODE_TYPE)) { cmisQuery = sn.getAttributeValue(CmisConfig.CMIS_QUERY_PARAM); break; } } for (String documentIdentifier : documentIdentifiers) { if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("CMIS: Processing document identifier '" + documentIdentifier + "'"); getSession(); // Load the object. If this fails, it has been deleted. CmisObject cmisObject; try { cmisObject = session.getObject(documentIdentifier); } catch (CmisObjectNotFoundException e) { cmisObject = null; } if (cmisObject == null) { //System.out.println(" doesn't exist"); activities.deleteDocument(documentIdentifier); continue; } String versionString; if (cmisObject.getBaseType().getId().equals(CMIS_DOCUMENT_BASE_TYPE)) { Document document = (Document) cmisObject; // Since documents that are not current have different node id's, we can return a constant version, // EXCEPT when the document is not the current one (in which case we delete) boolean isCurrentVersion; try { Document d = document.getObjectOfLatestVersion(false); isCurrentVersion = d.getId().equals(documentIdentifier); } catch (CmisObjectNotFoundException e) { isCurrentVersion = false; } if (isCurrentVersion) { //System.out.println(" is latest version"); versionString = documentIdentifier + ":" + cmisQuery; } else { //System.out.println(" is NOT latest vrersion"); activities.deleteDocument(documentIdentifier); continue; } } else { //a CMIS folder will always be processed //System.out.println(" is folder"); versionString = StringUtils.EMPTY; } if (versionString.length() == 0 || activities.checkDocumentNeedsReindexing(documentIdentifier, versionString)) { // Index this document String errorCode = null; String errorDesc = null; Long fileLengthLong = null; long startTime = System.currentTimeMillis(); try { String baseTypeId = cmisObject.getBaseType().getId(); if (baseTypeId.equals(CMIS_FOLDER_BASE_TYPE)) { // adding all the children for a folder Folder folder = (Folder) cmisObject; ItemIterable<CmisObject> children = folder.getChildren(); for (CmisObject child : children) { activities.addDocumentReference(child.getId(), documentIdentifier, RELATIONSHIP_CHILD); } } else if (baseTypeId.equals(CMIS_DOCUMENT_BASE_TYPE)) { // content ingestion Document document = (Document) cmisObject; Date createdDate = document.getCreationDate().getTime(); Date modifiedDate = document.getLastModificationDate().getTime(); long fileLength = document.getContentStreamLength(); String fileName = document.getContentStreamFileName(); String mimeType = document.getContentStreamMimeType(); //documentURI String documentURI = CmisRepositoryConnectorUtils.getDocumentURL(document, session); // Do any filtering (which will save us work) if (!activities.checkURLIndexable(documentURI)) { activities.noDocument(documentIdentifier, versionString); errorCode = activities.EXCLUDED_URL; errorDesc = "Excluding due to URL ('" + documentURI + "')"; continue; } if (!activities.checkMimeTypeIndexable(mimeType)) { activities.noDocument(documentIdentifier, versionString); errorCode = activities.EXCLUDED_MIMETYPE; errorDesc = "Excluding due to mime type (" + mimeType + ")"; continue; } if (!activities.checkLengthIndexable(fileLength)) { activities.noDocument(documentIdentifier, versionString); errorCode = activities.EXCLUDED_LENGTH; errorDesc = "Excluding due to length (" + fileLength + ")"; continue; } if (!activities.checkDateIndexable(modifiedDate)) { activities.noDocument(documentIdentifier, versionString); errorCode = activities.EXCLUDED_DATE; errorDesc = "Excluding due to date (" + modifiedDate + ")"; continue; } RepositoryDocument rd = new RepositoryDocument(); rd.setFileName(fileName); rd.setMimeType(mimeType); rd.setCreatedDate(createdDate); rd.setModifiedDate(modifiedDate); InputStream is; try { if (fileLength > 0) is = document.getContentStream().getStream(); else is = null; } catch (CmisObjectNotFoundException e) { // Document gone activities.deleteDocument(documentIdentifier); continue; } try { //binary if (is != null) { rd.setBinary(is, fileLength); } else { rd.setBinary(new NullInputStream(0), 0); } //properties List<Property<?>> properties = document.getProperties(); String id = StringUtils.EMPTY; for (Property<?> property : properties) { String propertyId = property.getId(); if (CmisRepositoryConnectorUtils.existsInSelectClause(cmisQuery, propertyId)) { if (propertyId.endsWith(Constants.PARAM_OBJECT_ID)) { id = (String) property.getValue(); if (property.getValue() != null || property.getValues() != null) { PropertyType propertyType = property.getType(); switch (propertyType) { case STRING: case ID: case URI: case HTML: if (property.isMultiValued()) { List<String> htmlPropertyValues = (List<String>) property .getValues(); for (String htmlPropertyValue : htmlPropertyValues) { rd.addField(propertyId, htmlPropertyValue); } } else { String stringValue = (String) property.getValue(); if (StringUtils.isNotEmpty(stringValue)) { rd.addField(propertyId, stringValue); } } break; case BOOLEAN: if (property.isMultiValued()) { List<Boolean> booleanPropertyValues = (List<Boolean>) property .getValues(); for (Boolean booleanPropertyValue : booleanPropertyValues) { rd.addField(propertyId, booleanPropertyValue.toString()); } } else { Boolean booleanValue = (Boolean) property.getValue(); if (booleanValue != null) { rd.addField(propertyId, booleanValue.toString()); } } break; case INTEGER: if (property.isMultiValued()) { List<BigInteger> integerPropertyValues = (List<BigInteger>) property .getValues(); for (BigInteger integerPropertyValue : integerPropertyValues) { rd.addField(propertyId, integerPropertyValue.toString()); } } else { BigInteger integerValue = (BigInteger) property.getValue(); if (integerValue != null) { rd.addField(propertyId, integerValue.toString()); } } break; case DECIMAL: if (property.isMultiValued()) { List<BigDecimal> decimalPropertyValues = (List<BigDecimal>) property .getValues(); for (BigDecimal decimalPropertyValue : decimalPropertyValues) { rd.addField(propertyId, decimalPropertyValue.toString()); } } else { BigDecimal decimalValue = (BigDecimal) property.getValue(); if (decimalValue != null) { rd.addField(propertyId, decimalValue.toString()); } } break; case DATETIME: if (property.isMultiValued()) { List<GregorianCalendar> datePropertyValues = (List<GregorianCalendar>) property .getValues(); for (GregorianCalendar datePropertyValue : datePropertyValues) { rd.addField(propertyId, ISO8601_DATE_FORMATTER .format(datePropertyValue.getTime())); } } else { GregorianCalendar dateValue = (GregorianCalendar) property .getValue(); if (dateValue != null) { rd.addField(propertyId, ISO8601_DATE_FORMATTER.format(dateValue.getTime())); } } break; default: break; } } } } } //ingestion try { activities.ingestDocumentWithException(documentIdentifier, versionString, documentURI, rd); fileLengthLong = new Long(fileLength); errorCode = "OK"; } catch (IOException e) { errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT); errorDesc = e.getMessage(); handleIOException(e, "reading file input stream"); } } finally { try { if (is != null) { is.close(); } } catch (IOException e) { errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT); errorDesc = e.getMessage(); handleIOException(e, "closing file input stream"); } } } else { // Unrecognized document type activities.noDocument(documentIdentifier, versionString); errorCode = "UNKNOWNTYPE"; errorDesc = "Document type is unrecognized: '" + baseTypeId + "'"; } } catch (ManifoldCFException e) { if (e.getErrorCode() == ManifoldCFException.INTERRUPTED) errorCode = null; throw e; } finally { if (errorCode != null) activities.recordActivity(new Long(startTime), ACTIVITY_READ, fileLengthLong, documentIdentifier, errorCode, errorDesc, null); } } } }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
/** @return a limited CertificateData object based on the information we have */ private CertificateData createLimitedCertificateData(final AuthenticationToken admin, final String limitedFingerprint, final String issuerDn, final BigInteger serialNumber, final Date revocationDate, final int reasonCode, final String caFingerprint) { CertificateData certificateData = new CertificateData(); certificateData.setFingerprint(limitedFingerprint); certificateData.setSerialNumber(serialNumber.toString()); certificateData.setIssuer(issuerDn); // The idea is to set SubjectDN to an empty string. However, since Oracle treats an empty String as NULL, // and since CertificateData.SubjectDN has a constraint that it should not be NULL, we are setting it to // "CN=limited" instead of an empty string certificateData.setSubjectDN("CN=limited"); certificateData.setCertificateProfileId(new Integer(CertificateProfileConstants.CERTPROFILE_NO_PROFILE)); certificateData.setStatus(CertificateConstants.CERT_REVOKED); certificateData.setRevocationReason(reasonCode); certificateData.setRevocationDate(revocationDate); certificateData.setUpdateTime(new Long(new Date().getTime())); certificateData.setCaFingerprint(caFingerprint); return certificateData; }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
@Override public Collection<Certificate> findCertificatesBySerno(BigInteger serno) { if (log.isTraceEnabled()) { log.trace(">findCertificatesBySerno(), serno=" + serno); }/*from ww w. j a v a 2s. co m*/ ArrayList<Certificate> ret = new ArrayList<Certificate>(); Collection<CertificateData> coll = CertificateData.findBySerialNumber(entityManager, serno.toString()); Iterator<CertificateData> iter = coll.iterator(); while (iter.hasNext()) { ret.add(iter.next().getCertificate(this.entityManager)); } if (log.isTraceEnabled()) { log.trace("<findCertificatesBySerno(), serno=" + serno); } return ret; }