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:org.jembi.rhea.transformers.XDSRepositoryProvideAndRegisterDocumentResponse.java
protected String generateATNAMessage(String request, String patientId, String uniqueId, boolean outcome) throws JAXBException { AuditMessage res = new AuditMessage(); EventIdentificationType eid = new EventIdentificationType(); eid.setEventID(ATNAUtil.buildCodedValueType("DCM", "110106", "Export")); eid.setEventActionCode("R"); eid.setEventDateTime(ATNAUtil.newXMLGregorianCalendar()); eid.getEventTypeCode().add(/*w w w.j av a 2s . c o m*/ ATNAUtil.buildCodedValueType("IHE Transactions", "ITI-41", "Provide and Register Document Set-b")); eid.setEventOutcomeIndicator(outcome ? BigInteger.ZERO : new BigInteger("4")); res.setEventIdentification(eid); res.getActiveParticipant().add(ATNAUtil.buildActiveParticipant(ATNAUtil.WSA_REPLYTO_ANON, ATNAUtil.getProcessID(), true, ATNAUtil.getHostIP(), (short) 2, "DCM", "110153", "Source")); res.getActiveParticipant().add(ATNAUtil.buildActiveParticipant(xdsRepositoryHost, false, xdsRepositoryHost, (short) 1, "DCM", "110152", "Destination")); res.getAuditSourceIdentification().add(ATNAUtil.buildAuditSource("openhie-repository")); res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType( String.format("%s^^^&%s&ISO", patientId, requestedAssigningAuthority), (short) 1, (short) 1, "RFC-3881", "2", "PatientNumber", null)); res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType(uniqueId, (short) 2, (short) 20, "IHE XDS Metadata", "urn:uuid:a54d6aa5-d40d-43f9-88c5-b4633d873bdd", "submission set classificationNode", request)); return ATNAUtil.marshallATNAObject(res); }
From source file:org.ossie.properties.AnyUtils.java
/** * Attempts to convert the string value to the appropriate Java type. * //from ww w.j a va 2s . c o m * @param stringValue the string form of the value * @param type the string form of the TypeCode * @return A Java object of theString corresponding to the typecode */ public static Object convertString(final String stringValue, final String type) { if (stringValue == null) { return null; } if (type.equals("string")) { return stringValue; } else if (type.equals("wstring")) { return stringValue; } else if (type.equals("boolean")) { if ("true".equalsIgnoreCase(stringValue) || "false".equalsIgnoreCase(stringValue)) { return Boolean.parseBoolean(stringValue); } throw new IllegalArgumentException(stringValue + " is not a valid boolean value"); } else if (type.equals("char")) { if (stringValue.length() == 1) { return stringValue.charAt(0); } throw new IllegalArgumentException(stringValue + " is not a valid char value"); } else if (type.equals("wchar")) { return stringValue.charAt(0); } else if (type.equals("double")) { return Double.parseDouble(stringValue); } else if (type.equals("float")) { return Float.parseFloat(stringValue); } else if (type.equals("short")) { return Short.decode(stringValue); } else if (type.equals("long")) { return Integer.decode(stringValue); } else if (type.equals("longlong")) { return Long.decode(stringValue); } else if (type.equals("ulong")) { final long MAX_UINT = 2L * Integer.MAX_VALUE + 1L; final Long retVal = Long.decode(stringValue); if (retVal < 0 || retVal > MAX_UINT) { throw new IllegalArgumentException( "ulong value must be greater than '0' and less than " + MAX_UINT); } return retVal; } else if (type.equals("ushort")) { final int MAX_USHORT = 2 * Short.MAX_VALUE + 1; final Integer retVal = Integer.decode(stringValue); if (retVal < 0 || retVal > MAX_USHORT) { throw new IllegalArgumentException( "ushort value must be greater than '0' and less than " + MAX_USHORT); } return retVal; } else if (type.equals("ulonglong")) { final BigInteger MAX_ULONG_LONG = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)) .add(BigInteger.ONE); final BigInteger retVal = bigIntegerDecode(stringValue); if (retVal.compareTo(BigInteger.ZERO) < 0 || retVal.compareTo(MAX_ULONG_LONG) > 0) { throw new IllegalArgumentException( "ulonglong value must be greater than '0' and less than " + MAX_ULONG_LONG.toString()); } return retVal; } else if (type.equals("objref")) { List<String> objrefPrefix = Arrays.asList("IOR:", "corbaname:", "corbaloc:"); for (String prefix : objrefPrefix) { if (stringValue.startsWith(prefix)) { return stringValue; } } throw new IllegalArgumentException(stringValue + " is not a valid objref value"); } else if (type.equals("octet")) { final short MIN_OCTET = 0; final short MAX_OCTET = 0xFF; short val = Short.valueOf(stringValue); if (val <= MAX_OCTET && val >= MIN_OCTET) { return Short.valueOf(val).byteValue(); } throw new IllegalArgumentException(stringValue + " is not a valid octet value"); } else { throw new IllegalArgumentException("Unknown CORBA Type: " + type); } }
From source file:org.trnltk.numeral.DigitsToTextConverter.java
public String convert(String digits) { if (StringUtils.isBlank(digits)) return null; digits = digits.replaceAll(GROUPING_SEPARATOR_REGEX, StringUtils.EMPTY); if (!TURKISH_NUMBER_PATTERN.matcher(digits).matches()) throw new IllegalArgumentException("'" + digits + "' is not a valid Turkish number. Allowed pattern is : " + TURKISH_NUMBER_PATTERN.pattern()); String strIntegerPart, strFractionPart; if (digits.contains(FRACTION_SEPARATOR)) { strIntegerPart = digits.substring(0, digits.indexOf(FRACTION_SEPARATOR)); strFractionPart = digits.substring(digits.indexOf(FRACTION_SEPARATOR) + 1); } else {//from ww w . ja v a 2 s . co m strIntegerPart = digits; strFractionPart = null; } boolean isPositive = true; if (strIntegerPart.startsWith(POSITIVE_SIGN)) { isPositive = true; strIntegerPart = strIntegerPart.substring(1); } if (strIntegerPart.startsWith(NEGATIVE_SIGN)) { isPositive = false; strIntegerPart = strIntegerPart.substring(1); } BigInteger integerPart = new BigInteger(strIntegerPart); BigInteger fractionPart = StringUtils.isNotBlank(strFractionPart) ? new BigInteger(strFractionPart) : BigInteger.ZERO; if (!isPositive) integerPart = integerPart.negate(); String wordIntegerPart = this.convertNaturalNumberToWords(integerPart.abs()); String wordFractionPart = this.convertNaturalNumberToWords(fractionPart); wordIntegerPart = this.addTextForLeadingZeros(strIntegerPart, wordIntegerPart); wordFractionPart = StringUtils.isNotBlank(strFractionPart) ? this.addTextForLeadingZeros(strFractionPart, wordFractionPart) : wordFractionPart; if (integerPart.compareTo(ZERO) < 0) wordIntegerPart = MINUS_NAME + " " + wordIntegerPart; if (digits.contains(FRACTION_SEPARATOR)) return wordIntegerPart + " " + COMMA_NAME + " " + wordFractionPart; else return wordIntegerPart; }
From source file:org.openhim.mediator.denormalization.ATNAAuditingActor.java
protected String generateForPIXIdentityFeed(ATNAAudit audit) throws JAXBException { AuditMessage res = new AuditMessage(); EventIdentificationType eid = new EventIdentificationType(); eid.setEventID(ATNAUtil.buildCodedValueType("DCM", "110110", "Patient Record")); eid.setEventActionCode("C"); eid.setEventDateTime(ATNAUtil.newXMLGregorianCalendar()); eid.getEventTypeCode()// w w w.j av a 2 s .c om .add(ATNAUtil.buildCodedValueType("IHE Transactions", "ITI-8", "Patient Identity Feed")); eid.setEventOutcomeIndicator(audit.getOutcome() ? BigInteger.ZERO : new BigInteger("4")); res.setEventIdentification(eid); res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant( config.getProperty("pix.sendingFacility") + "|" + config.getProperty("pix.sendingApplication"), ATNAUtil.getProcessID(), true, ATNAUtil.getHostIP(), (short) 2, "DCM", "110153", "Source")); res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant( config.getProperty("pix.receivingFacility") + "|" + config.getProperty("pix.receivingApplication"), "2100", false, config.getProperty("pix.manager.host"), (short) 1, "DCM", "110152", "Destination")); res.getAuditSourceIdentification().add(ATNAUtil.buildAuditSource("openhim")); // Max of 1 patient is allowed Identifier id = audit.getParticipantIdentifiers().get(0); if (id != null) { res.getParticipantObjectIdentification().add(ATNAUtil.buildParticipantObjectIdentificationType( id.toCX(), (short) 1, (short) 1, "RFC-3881", "2", "PatientNumber", null)); } res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType(UUID.randomUUID().toString(), (short) 2, (short) 24, "IHE Transactions", "ITI-9", "PIX Query", audit.getMessage(), new ATNAUtil.ParticipantObjectDetail("MSH-10", audit.getUniqueId().getBytes()))); return ATNAUtil.marshallATNAObject(res); }
From source file:org.openhim.mediator.denormalisation.PIXQueryResponseTransformer.java
protected String generateATNAMessage(String request, String patientId, String msh10) throws JAXBException { AuditMessage res = new AuditMessage(); EventIdentificationType eid = new EventIdentificationType(); eid.setEventID(ATNAUtil.buildCodedValueType("DCM", "110112", "Query")); eid.setEventActionCode("E"); eid.setEventDateTime(ATNAUtil.newXMLGregorianCalendar()); eid.getEventTypeCode().add(ATNAUtil.buildCodedValueType("IHE Transactions", "ITI-9", "PIX Query")); eid.setEventOutcomeIndicator(patientId != null ? BigInteger.ZERO : new BigInteger("4")); res.setEventIdentification(eid);/*from w ww . ja v a 2 s .c o m*/ res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant(getPixSendingFacility() + "|" + getPixSendingApplication(), ATNAUtil.getProcessID(), true, ATNAUtil.getHostIP(), (short) 2, "DCM", "110153", "Source")); res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant(getPixReceivingFacility() + "|" + getPixReceivingApplication(), "2100", false, pixManagerHost, (short) 1, "DCM", "110152", "Destination")); res.getAuditSourceIdentification().add(ATNAUtil.buildAuditSource("openhim")); res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType( String.format("%s^^^&%s&ISO", patientId, requestedAssigningAuthority), (short) 1, (short) 1, "RFC-3881", "2", "PatientNumber", null)); res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType(UUID.randomUUID().toString(), (short) 2, (short) 24, "IHE Transactions", "ITI-9", "PIX Query", request, new ParticipantObjectDetail("MSH-10", msh10.getBytes()))); return ATNAUtil.marshallATNAObject(res); }
From source file:org.jembi.rhea.transformers.PIXQueryResponseTransformer.java
protected String generateATNAMessage(String request, String patientId, String msh10) throws JAXBException { AuditMessage res = new AuditMessage(); EventIdentificationType eid = new EventIdentificationType(); eid.setEventID(ATNAUtil.buildCodedValueType("DCM", "110112", "Query")); eid.setEventActionCode("E"); eid.setEventDateTime(ATNAUtil.newXMLGregorianCalendar()); eid.getEventTypeCode().add(ATNAUtil.buildCodedValueType("IHE Transactions", "ITI-9", "PIX Query")); eid.setEventOutcomeIndicator(patientId != null ? BigInteger.ZERO : new BigInteger("4")); res.setEventIdentification(eid);/*from w w w .j a v a2 s .com*/ res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant(getPixSendingFacility() + "|" + getPixSendingApplication(), ATNAUtil.getProcessID(), true, ATNAUtil.getHostIP(), (short) 2, "DCM", "110153", "Source")); res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant(getPixReceivingFacility() + "|" + getPixReceivingApplication(), "2100", false, pixManagerHost, (short) 1, "DCM", "110152", "Destination")); res.getAuditSourceIdentification().add(ATNAUtil.buildAuditSource("openhie-cr")); res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType( String.format("%s^^^&%s&ISO", patientId, requestedAssigningAuthority), (short) 1, (short) 1, "RFC-3881", "2", "PatientNumber", null)); res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType(UUID.randomUUID().toString(), (short) 2, (short) 24, "IHE Transactions", "ITI-9", "PIX Query", request, new ParticipantObjectDetail("MSH-10", msh10.getBytes()))); return ATNAUtil.marshallATNAObject(res); }
From source file:piuk.MyRemoteWallet.java
public synchronized BigInteger getBalance(String address) { if (this.multiAddrBalancesRoot != null && this.multiAddrBalancesRoot.containsKey(address)) { return BigInteger .valueOf(((Number) this.multiAddrBalancesRoot.get(address).get("final_balance")).longValue()); }// w w w . j a va2s . co m return BigInteger.ZERO; }
From source file:com.coinprism.model.APIClient.java
/** * Gets the list of recent transactions for a given address. * * @param address the address for which to query the recent transactions * @return a list of transactions/*from w w w. j a va 2 s .c o m*/ */ public List<SingleAssetTransaction> getTransactions(String address) throws IOException, JSONException, ParseException, APIException { String json = executeHttpGet(this.baseUrl + "/v1/addresses/" + address + "/transactions"); JSONArray transactions = new JSONArray(json); ArrayList<SingleAssetTransaction> assetBalances = new ArrayList<SingleAssetTransaction>(); for (int i = 0; i < transactions.length(); i++) { JSONObject transactionObject = (JSONObject) transactions.get(i); String transactionId = transactionObject.getString("hash"); Date date = null; if (!transactionObject.isNull("block_time")) date = parseDate(transactionObject.getString("block_time")); HashMap<String, BigInteger> quantities = new HashMap<String, BigInteger>(); BigInteger satoshiDelta = BigInteger.ZERO; JSONArray inputs = transactionObject.getJSONArray("inputs"); for (int j = 0; j < inputs.length(); j++) { JSONObject input = (JSONObject) inputs.get(j); if (isAddress(input, address)) { if (!input.isNull("asset_id")) addQuantity(quantities, input.getString("asset_id"), new BigInteger(input.getString("asset_quantity")).negate()); satoshiDelta = satoshiDelta.subtract(BigInteger.valueOf(input.getLong("value"))); } } JSONArray outputs = transactionObject.getJSONArray("outputs"); for (int j = 0; j < outputs.length(); j++) { JSONObject output = (JSONObject) outputs.get(j); if (isAddress(output, address)) { if (!output.isNull("asset_id")) addQuantity(quantities, output.getString("asset_id"), new BigInteger(output.getString("asset_quantity"))); satoshiDelta = satoshiDelta.add(BigInteger.valueOf(output.getLong("value"))); } } if (!satoshiDelta.equals(BigInteger.ZERO)) assetBalances.add(new SingleAssetTransaction(transactionId, date, null, satoshiDelta)); for (String key : quantities.keySet()) { assetBalances.add(new SingleAssetTransaction(transactionId, date, getAssetDefinition(key), quantities.get(key))); } } return assetBalances; }
From source file:org.geowebcache.diskquota.CacheCleaner.java
/** * This method is thread safe and will throw interrupted exception if the thread has been * interrupted or the {@link #destroy() shutdown hook} has been called to signal the calling * code of premature termination./*from w w w .ja v a 2 s . co m*/ * * @param layerNames * the layers to expire tile pages from * @param quotaResolver * live limit and used quota to monitor until it reaches its limit * @throws InterruptedException * @see {@link org.geowebcache.diskquota.ExpirationPolicy#expireByLayerNames} */ public void expireByLayerNames(final Set<String> layerNames, final QuotaResolver quotaResolver, final QuotaStore pageStore) throws InterruptedException { Quota limit; Quota used; Quota excess; while (true) { if (shutDown || Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } // get it everytime in case the admin changed it while we're processsing limit = quotaResolver.getLimit(); used = quotaResolver.getUsed(); excess = used.difference(limit); if (excess.getBytes().compareTo(BigInteger.ZERO) <= 0) { log.info("Reached back Quota: " + limit.toNiceString() + " (" + used.toNiceString() + ") for layers " + layerNames); return; } // same thing, check it every time ExpirationPolicy expirationPolicy = quotaResolver.getExpirationPolicy(); if (null == expirationPolicy) { log.warn("Aborting disk quota enforcement task, no expiration policy defined for layers " + layerNames); return; } TilePage tilePage = null; if (ExpirationPolicy.LFU.equals(expirationPolicy)) { tilePage = pageStore.getLeastFrequentlyUsedPage(layerNames); } else if (ExpirationPolicy.LRU.equals(expirationPolicy)) { tilePage = pageStore.getLeastRecentlyUsedPage(layerNames); } else { throw new IllegalStateException("Unrecognized expiration policy: " + expirationPolicy); } if (tilePage == null) { limit = quotaResolver.getLimit(); Quota usedQuota = quotaResolver.getUsed(); if (excess.getBytes().compareTo(BigInteger.ZERO) > 0) { log.warn("No more pages to expire, check if youd disk quota" + " database is out of date with your blob store. Quota: " + limit.toNiceString() + " used: " + usedQuota.toNiceString()); } return; } if (log.isDebugEnabled()) { log.debug("Expiring tile page " + tilePage + " based on the global " + expirationPolicy + " expiration policy"); } if (shutDown || Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } expirePage(pageStore, tilePage); } }
From source file:org.geowebcache.diskquota.CacheCleanerTask.java
private void innerRun() throws InterruptedException { // first, save the config to account for changes in used quotas final DiskQuotaConfig quotaConfig = monitor.getConfig(); if (!quotaConfig.isEnabled()) { log.trace("DiskQuota disabled, ignoring run..."); return;//from w ww. j av a 2s .c o m } quotaConfig.setLastCleanUpTime(new Date()); final Set<String> allLayerNames = monitor.getLayerNames(); final Set<String> configuredLayerNames = quotaConfig.layerNames(); final Set<String> globallyManagedLayerNames = new HashSet<String>(allLayerNames); globallyManagedLayerNames.removeAll(configuredLayerNames); for (String layerName : configuredLayerNames) { if (monitor.isCacheInfoBuilderRunning(layerName)) { if (log.isInfoEnabled()) { log.info("Cache information is still being gathered for layer '" + layerName + "'. Skipping quota enforcement task for this layer."); } continue; } Future<?> runningCleanup = perLayerRunningCleanUps.get(layerName); if (runningCleanup != null && !runningCleanup.isDone()) { if (log.isDebugEnabled()) { log.debug("Cache clean up task still running for layer '" + layerName + "'. Ignoring it for this run."); } continue; } final LayerQuota definedQuotaForLayer = quotaConfig.layerQuota(layerName); final ExpirationPolicy policy = definedQuotaForLayer.getExpirationPolicyName(); final Quota quota = definedQuotaForLayer.getQuota(); final Quota usedQuota = monitor.getUsedQuotaByLayerName(layerName); Quota excedent = usedQuota.difference(quota); if (excedent.getBytes().compareTo(BigInteger.ZERO) > 0) { if (log.isInfoEnabled()) { log.info("Layer '" + layerName + "' exceeds its quota of " + quota.toNiceString() + " by " + excedent.toNiceString() + ". Currently used: " + usedQuota.toNiceString() + ". Clean up task will be performed using expiration policy " + policy); } Set<String> layerNames = Collections.singleton(layerName); QuotaResolver quotaResolver; quotaResolver = monitor.newLayerQuotaResolver(layerName); LayerQuotaEnforcementTask task; task = new LayerQuotaEnforcementTask(layerNames, quotaResolver, monitor); Future<Object> future = this.cleanUpExecutorService.submit(task); perLayerRunningCleanUps.put(layerName, future); } } if (globallyManagedLayerNames.size() > 0) { ExpirationPolicy globalExpirationPolicy = quotaConfig.getGlobalExpirationPolicyName(); if (globalExpirationPolicy == null) { return; } final Quota globalQuota = quotaConfig.getGlobalQuota(); if (globalQuota == null) { log.info("There's not a global disk quota configured. The following layers " + "will not be checked for excess of disk usage: " + globallyManagedLayerNames); return; } if (globalCleanUpTask != null && !globalCleanUpTask.isDone()) { log.debug("Global cache quota enforcement task still running, avoiding issueing a new one..."); return; } Quota globalUsedQuota = monitor.getGloballyUsedQuota(); Quota excedent = globalUsedQuota.difference(globalQuota); if (excedent.getBytes().compareTo(BigInteger.ZERO) > 0) { log.debug("Submitting global cache quota enforcement task"); LayerQuotaEnforcementTask task; QuotaResolver quotaResolver = monitor.newGlobalQuotaResolver(); task = new LayerQuotaEnforcementTask(globallyManagedLayerNames, quotaResolver, monitor); this.globalCleanUpTask = this.cleanUpExecutorService.submit(task); } else { if (log.isTraceEnabled()) { log.trace("Won't launch global quota enforcement task, " + globalUsedQuota.toNiceString() + " used out of " + globalQuota.toNiceString() + " configured for the whole cache size."); } } } }