List of usage examples for org.joda.time LocalDateTime compareTo
public int compareTo(ReadablePartial partial)
From source file:com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.java
License:Open Source License
private void setLatestResourceValues(Map<String, Object> rowMap, List<String> tagHeaders, AwsResourceDetailDto resourceDetail) { LocalDateTime usageStartTimeFromCsv = (LocalDateTime) rowMap.get(DetailedCsvHeaders.USAGE_START_DATE); LocalDateTime existingUsageStartTime = null; if (resourceDetail.usageStartTime != null) { existingUsageStartTime = new LocalDateTime(resourceDetail.usageStartTime); }//from w w w . j a v a 2s . co m if (existingUsageStartTime == null || existingUsageStartTime.compareTo(usageStartTimeFromCsv) <= 0) { resourceDetail.itemDescription = getStringFieldValue(rowMap, DetailedCsvHeaders.ITEM_DESCRIPTION); resourceDetail.usageStartTime = usageStartTimeFromCsv.toDate().getTime(); resourceDetail.tags = getTagsForResources(rowMap, tagHeaders); boolean isRowMarkedAsReserved = convertReservedInstance( getStringFieldValue(rowMap, DetailedCsvHeaders.IS_RESERVED_INSTANCE)); boolean isResourceReservedForThisHour; Long millisForBillDay = getMillisForHour(usageStartTimeFromCsv); if (existingUsageStartTime != null && existingUsageStartTime.isEqual(usageStartTimeFromCsv)) { isResourceReservedForThisHour = resourceDetail.isReservedInstance || isRowMarkedAsReserved; if (isRowMarkedAsReserved && !resourceDetail.isReservedInstance) { resourceDetail.addToHoursAsReservedPerDay(millisForBillDay, 1.0); } } else { isResourceReservedForThisHour = isRowMarkedAsReserved; if (isResourceReservedForThisHour) { resourceDetail.addToHoursAsReservedPerDay(millisForBillDay, 1.0); } } resourceDetail.isReservedInstance = isResourceReservedForThisHour; } }
From source file:de.appsolve.padelcampus.utils.BookingUtil.java
public OfferDurationPrice getOfferDurationPrice(List<CalendarConfig> configs, List<Booking> confirmedBookings, LocalDate selectedDate, LocalTime selectedTime, Offer selectedOffer) throws CalendarConfigException { List<TimeSlot> timeSlotsForDate = getTimeSlotsForDate(selectedDate, configs, confirmedBookings, Boolean.TRUE, Boolean.TRUE); boolean validStartTime = false; for (TimeSlot timeSlot : timeSlotsForDate) { if (timeSlot.getStartTime().equals(selectedTime)) { validStartTime = true;//from w w w . j a v a 2 s .c om break; } } OfferDurationPrice offerDurationPrices = null; if (validStartTime) { //convert to required data structure Map<Offer, List<CalendarConfig>> offerConfigMap = new HashMap<>(); for (CalendarConfig config : configs) { for (Offer offer : config.getOffers()) { if (offer.equals(selectedOffer)) { List<CalendarConfig> list = offerConfigMap.get(offer); if (list == null) { list = new ArrayList<>(); } list.add(config); //sort by start time Collections.sort(list); offerConfigMap.put(offer, list); } } } Iterator<Map.Entry<Offer, List<CalendarConfig>>> iterator = offerConfigMap.entrySet().iterator(); //for every offer while (iterator.hasNext()) { Map.Entry<Offer, List<CalendarConfig>> entry = iterator.next(); Offer offer = entry.getKey(); List<CalendarConfig> configsForOffer = entry.getValue(); //make sure the first configuration starts before the requested booking time if (selectedTime.compareTo(configsForOffer.get(0).getStartTime()) < 0) { continue; } LocalDateTime endTime = null; Integer duration = configsForOffer.get(0).getMinDuration(); BigDecimal pricePerMinute; BigDecimal price = null; CalendarConfig previousConfig = null; Map<Integer, BigDecimal> durationPriceMap = new TreeMap<>(); Boolean isContiguous = true; for (CalendarConfig config : configsForOffer) { //make sure there is no gap between calendar configurations if (endTime == null) { //first run endTime = getLocalDateTime(selectedDate, selectedTime).plusMinutes(config.getMinDuration()); } else { //break if there are durations available and calendar configs are not contiguous if (!durationPriceMap.isEmpty()) { //we substract min interval before the comparison as it has been added during the last iteration LocalDateTime configStartDateTime = getLocalDateTime(selectedDate, config.getStartTime()); if (!endTime.minusMinutes(config.getMinInterval()).equals(configStartDateTime)) { break; } } } Integer interval = config.getMinInterval(); pricePerMinute = getPricePerMinute(config); //as long as the endTime is before the end time configured in the calendar LocalDateTime configEndDateTime = getLocalDateTime(selectedDate, config.getEndTime()); while (endTime.compareTo(configEndDateTime) <= 0) { TimeSlot timeSlot = new TimeSlot(); timeSlot.setDate(selectedDate); timeSlot.setStartTime(selectedTime); timeSlot.setEndTime(endTime.toLocalTime()); timeSlot.setConfig(config); Long bookingSlotsLeft = getBookingSlotsLeft(timeSlot, offer, confirmedBookings); //we only allow contiguous bookings for any given offer if (bookingSlotsLeft < 1) { isContiguous = false; break; } if (price == null) { //see if previousConfig endTime - minInterval matches the selected time. if so, take half of the previous config price as a basis if (previousConfig != null && previousConfig.getEndTime() .minusMinutes(previousConfig.getMinInterval()).equals(selectedTime)) { BigDecimal previousConfigPricePerMinute = getPricePerMinute(previousConfig); price = previousConfigPricePerMinute.multiply( new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128); price = price.add(pricePerMinute.multiply( new BigDecimal(duration - previousConfig.getMinInterval()), MathContext.DECIMAL128)); } else { price = pricePerMinute.multiply(new BigDecimal(duration.toString()), MathContext.DECIMAL128); } } else { //add price for additional interval price = price.add(pricePerMinute.multiply(new BigDecimal(interval.toString()), MathContext.DECIMAL128)); } price = price.setScale(2, RoundingMode.HALF_EVEN); durationPriceMap.put(duration, price); //increase the duration by the configured minimum interval and determine the new end time for the next iteration duration += interval; endTime = endTime.plusMinutes(interval); } if (!durationPriceMap.isEmpty()) { OfferDurationPrice odp = new OfferDurationPrice(); odp.setOffer(offer); odp.setDurationPriceMap(durationPriceMap); odp.setConfig(config); offerDurationPrices = odp; } if (!isContiguous) { //we only allow coniguous bookings for one offer. process next offer break; } previousConfig = config; } } } return offerDurationPrices; }
From source file:org.multibit.viewsystem.swing.WalletAssetSummaryTableModel.java
License:MIT License
@Override public Object getValueAt(int row, int column) { WalletAssetTableData rowObj = null;/* ww w .j a v a 2 s .com*/ if (row >= 0 && row < walletAssetData.size()) { rowObj = walletAssetData.get(row); } if (rowObj == null) { return null; } CSBitcoinAssetTableData btcObj = null; boolean isBitcoin = (rowObj instanceof CSBitcoinAssetTableData); if (isBitcoin) { btcObj = (CSBitcoinAssetTableData) rowObj; } CSAsset asset = rowObj.getAsset(); CSAsset.CSAssetState assetState = CSAsset.CSAssetState.INVALID; if (asset != null) { assetState = asset.getAssetState(); } //boolean noDetailsFlag = assetState. // NOTE: If asset is null, this should be the Bitcoin object. /* Get the balance and spendable balance of the asset. */ boolean showAssetSpendableFlag = false; boolean showAssetUpdatingNowFlag = false; Wallet wallet = bitcoinController.getModel().getActiveWallet(); Wallet.CoinSpark.AssetBalance assetBalance = null; if (asset != null) { int id = asset.getAssetID(); assetBalance = wallet.CS.getAssetBalance(id); showAssetSpendableFlag = (assetBalance.total.compareTo(assetBalance.spendable) != 0); showAssetUpdatingNowFlag = assetBalance.updatingNow; } int threshold = NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD; String sendAssetWithJustOneConfirmation = controller.getModel() .getUserPreference("sendAssetWithJustOneConfirmation"); if (Boolean.TRUE.toString().equals(sendAssetWithJustOneConfirmation)) { threshold = 1; } int lastHeight = 0; if (wallet != null) lastHeight = wallet.getLastBlockSeenHeight(); int numConfirms = 0; CoinSparkAssetRef assetRef = null; if (asset != null) assetRef = asset.getAssetReference(); if (assetRef != null) { int blockIndex = (int) assetRef.getBlockNum(); numConfirms = lastHeight - blockIndex + 1; // 0 means no confirmation, 1 is yes for sa } int numConfirmsStillRequired = threshold - numConfirms; // Switch on string, makes it easier for us to re-order columns without // having to reorganize the case statements. // http://stackoverflow.com/questions/338206/switch-statement-with-strings-in-java switch (COLUMN_HEADER_KEYS[column]) { case COLUMN_DESCRIPTION: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } // is the symbol industry group wants to use in 2014. // If there is no tooltip, no description, than dont show icon. String s = asset.getDescription(); if (s != null && !"".equals(s)) { String units = asset.getUnits(); // mandatory field but we are getting null sometimes if (units != null) { s = s + "<br><br>1 unit = " + units; } ImageIcon icon = ImageLoader.fatCow16(ImageLoader.FATCOW.information); map.put("icon", icon); map.put("tooltip", s); } ; return map; } case COLUMN_ISSUER: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } String issuerName = asset.getIssuer(); if (issuerName != null) { ImageIcon icon = ImageLoader.fatCow16(ImageLoader.FATCOW.ceo); map.put("icon", icon); String tip = "Asset issued by " + asset.getIssuer(); map.put("tooltip", tip); } return map; } case COLUMN_SPENDABLE: { HashMap<String, Object> map = new HashMap<>(); String s = ""; if (isBitcoin) { s = btcObj.syncText; if (s == null) { s = btcObj.spendableText; } else { if (btcObj.syncPercentText != null) { s = s + " " + btcObj.syncPercentText; } } //if (btcObj.syncPercentToolTipText) if (s == null) { s = ""; } } else if (asset != null && showAssetSpendableFlag) { s = "(" + CSMiscUtils.getFormattedDisplayStringForRawUnits(asset, assetBalance.spendable) + " spendable)"; } // Replace asset spendable flag if new asset needs more confirmaions // and this asset is almost ready to be sent i.e. has name, quantity. // Does not make sense to show this if asset files need to be uploaded. if (!isBitcoin && numConfirmsStillRequired > 0 && asset != null && asset.getName() != null) { int n = numConfirmsStillRequired; // we dont want to show high number if wallet is resyncing from start. if (n > NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD) { n = NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD; } s = "(Waiting for " + n + " confirmation" + ((n > 1) ? "s)" : ")"); } map.put("label", s); return map; } case COLUMN_EXPIRY: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } String tip = null; Date issueDate = asset.getIssueDate(); if (issueDate != null) { LocalDateTime issueDateTime = new DateTime(issueDate).toLocalDateTime(); tip = "Issued on " + issueDateTime.toString("d MMM y, HH:mm:ss") + "."; } else { tip = "No issue date given."; } Date d = asset.getExpiryDate(); ImageIcon icon = null; String s = null; if (d != null) { LocalDateTime expiryDateTime = new DateTime(d).toLocalDateTime(); tip = tip + " Expires on " + expiryDateTime.toString("d MMM y, HH:mm:ss") + "."; LocalDateTime now = LocalDateTime.now(); //For testing, plusDays and minusDays. //expiryDateTime = now.minusDays(600); Days daysDifference = Days.daysBetween(expiryDateTime, now); //, expiryDateTime); int daysBetween = daysDifference.getDays(); int weeksBetween = daysDifference.toStandardWeeks().getWeeks(); daysBetween = Math.abs(daysBetween); weeksBetween = Math.abs(weeksBetween); String diff = null; if (daysBetween <= 13) { diff = daysBetween + " days"; } else if (weeksBetween <= 12) { diff = weeksBetween + " weeks"; } else { diff = Math.abs(weeksBetween / 4) + " months"; } if (now.compareTo(expiryDateTime) > 0) { s = "Expired " + diff + " ago"; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.skull_old); if (daysBetween <= 7) { s = s + " (" + expiryDateTime.toString("d MMM y h:mm a z") + ")"; } else { s = s + " (" + expiryDateTime.toString("d MMM y") + ")"; } } else { s = "Expires on " + expiryDateTime.toString("d MMM y"); //expiryDateTime.toString("d MMM y, HH:mm:ss") + "."; if (daysBetween <= 30) { // s = "Expires in " + diff; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.fire); // s = s + " (" + expiryDateTime.toString("d MMM, h:mm a z") + ")"; } else { // s = "Expires in " + diff; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.clock); // s = s + " (" + expiryDateTime.toString("d MMM y") + ")"; } } } else { // No expiry date info. icon = null; s = null; tip = null; // If also no issue date info, that means we have not loaded the asset page yet if (issueDate != null) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.thumb_up); s = "Does not expire"; } } // Expired!!! skull icon? thumbs down. map.put("icon", icon); map.put("text", s); map.put("tooltip", tip); return map; } case COLUMN_REFRESH: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } ImageIcon icon = null; String tip = null; if (assetState == CSAsset.CSAssetState.REFRESH) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.hourglass); tip = "Refreshing..."; } else { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.arrow_refresh_small); tip = "Click to manually refresh the status of the asset"; } map.put("tooltip", tip); map.put("icon", icon); return map; } case COLUMN_QUANTITY: { if (isBitcoin) { String s = btcObj.balanceText; if (s == null) { s = ""; } return s; } if (asset.getName() == null) { return ""; // TODO: Change to webPageJSON==null } String displayString = CSMiscUtils.getFormattedDisplayStringForRawUnits(asset, assetBalance.total); if (showAssetUpdatingNowFlag) { if (assetBalance.total.equals(BigInteger.ZERO) == true) { displayString = "..."; } else { displayString += " + ..."; } } // For debugging, round-trip to see if values match. // BigInteger y = CSMiscUtils.getRawUnitsFromDisplayString(asset, displayString); // System.out.println("DISPLAY: " + displayString + " ----> RAW: " + y); return displayString; } case COLUMN_NAME: { HashMap map = new HashMap<>(); if (isBitcoin) { String s = btcObj.dataChangedText; if (s != null) { // Show important warning that wallet was changed by another process map.put("text", s); StyleRange style = new StyleRange(0, -1, Font.BOLD, Color.RED); map.put("style", style); map.put("tooltip", btcObj.dataChangedToolTipText); } else { map.put("text", "Bitcoin"); //map.put("text2", "(bitcoin.org)"); Font defaultFont = FontSizer.INSTANCE.getAdjustedDefaultFont(); map.put("style", new StyleRange(0, -1, defaultFont.getStyle())); } map.put("noaction", true); // disable action return map; } String name = asset.getNameShort(); // Short name is upto 16 chars, better for small table column. String domain = CSMiscUtils.getDomainHost(asset.getDomainURL()); boolean uploadFiles = false; if (name != null) { map.put("text", name); map.put("text2", "(" + domain + ")"); } else { String s; if (asset.getAssetSource() == CSAsset.CSAssetSource.GENESIS) { s = "Upload files to " + asset.getAssetWebPageURL(); uploadFiles = true; } else { if (domain == null) { s = "Locating new asset.."; } else { s = "Loading new asset from " + domain + "..."; } } map.put("text", s); StyleRange style = new StyleRange(0, -1, Font.PLAIN, Color.RED); map.put("style", style); map.put("noaction", true); // disable action } map.put("tooltip", "Click to visit the asset web page or the home page of the asset issuer."); if (uploadFiles) map.put("tooltip", map.get("text")); // for upload, it's long so show url. return map; } case COLUMN_CONFIRMATION: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } ImageIcon icon = null; String tip = null; //CoinSparkAssetRef assetRef = asset.getAssetReference(); PeerGroup pg = this.bitcoinController.getMultiBitService().getPeerGroup(); //Wallet wallet = this.bitcoinController.getModel().getActiveWallet(); //int lastHeight = wallet.getLastBlockSeenHeight(); // FIXME: when resyncing, last seen height will be less than genesis block. // Do we have another source of latest block height of testnet3 or production? // txid could be null if user manually adds a bogus asset reference. String txid = asset.getGenTxID(); Transaction tx = null; if (txid != null) { tx = wallet.getTransaction(new Sha256Hash(txid)); } // System.out.println("New? --- asset ref = " + asset.getAssetReference()); // System.out.println(" --- name = " + asset.getName()); // System.out.println(" --- transaction = " + tx); // System.out.println(" --- CSAsset has txid = " + txid); // System.out.println(" --- CSAsset has genesis = " + asset.getGenesis()); // tx can be null. // trying to find block, not found, // A regular CoinSpark transaction, where the wallet does not have the blockheader // for genesis transaction, must get the block, and get the transaction at the // index mentioned in asset ref. if (assetRef != null && tx == null) { final int blockIndex = (int) assetRef.getBlockNum(); final PeerGroup peerGroup = pg; final WalletAssetSummaryTableModel thisModel = this; Block block = blockCache.get(blockIndex); if (block == null) { //System.out.println("FAILED, NEED TO GET BLOCK"); executorService.execute(new Runnable() { @Override public void run() { Block block = peerGroup.getBlock(blockIndex); if (block != null) { blockCache.put(blockIndex, block); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // System.out.println("GOT THE BLOCK SO NOW INFORMING TABLE MODEL OF CHANGE"); thisModel.fireTableDataChanged(); } }); } if (block == null) { /* In a situation where the .spvchain and .fbhchain were deleted, and they need to be recreated, we can get, the following error: ERROR o.coinspark.core.CSBlockHeaderStore - Cannot read block hash, header file too small: block 266131, file size 3840032 */ } //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } //System.out.println("getBlock() for asset ref height " + n + " , returned: " + block); if (block != null) { tx = block.getTransactionByOffset((int) assetRef.getTxOffset()); if (tx == null) { // FIXME: We have an asset ref, but cannot get a valid transaction using the asset-ref and checking the genesis block header datda, so this is most likely an invalid asset. // System.out.println("Asset: Cannot find transaction with offset " + (int) assetRef.getTxnOffset() + " in block " + block.getHashAsString()); } } } int txHeight = 0; int numConfirmations = 0; int numBroadcasts = 0; String newAssetString = null; if (tx != null && assetRef != null) { TransactionConfidence confidence = tx.getConfidence(); numBroadcasts = confidence.getBroadcastByCount(); // System.out.println("confidence.getDepthInBlocks() = " + confidence.getDepthInBlocks()); if (confidence.getConfidenceType() == ConfidenceType.BUILDING) { txHeight = confidence.getAppearedAtChainHeight(); } else { // Note: assetRef could be NULL causing exception. txHeight = (int) assetRef.getBlockNum(); } numConfirmations = lastHeight - txHeight + 1; // 0 means no confirmation, 1 is yes for same block. String issueString = null; Date issueDate = asset.getIssueDate(); String sinceString = null; if (issueDate != null) { LocalDateTime issueDateTime = new DateTime(issueDate).toLocalDateTime(); issueString = "Date of issue was " + issueDateTime.toString("d MMM y, HH:mm:ss z"); // Compute the 'minutes/hours/days/weeks ago' string. LocalDateTime now = LocalDateTime.now(); Minutes theDiff = Minutes.minutesBetween(issueDateTime, now); //Days daysDifference = Days.daysBetween(issueDateTime, now); int minutesBetween = theDiff.getMinutes(); int hoursBetween = theDiff.toStandardHours().getHours(); int daysBetween = theDiff.toStandardDays().getDays(); int weeksBetween = theDiff.toStandardWeeks().getWeeks(); minutesBetween = Math.abs(minutesBetween); hoursBetween = Math.abs(hoursBetween); daysBetween = Math.abs(daysBetween); weeksBetween = Math.abs(weeksBetween); if (minutesBetween <= 120) { sinceString = minutesBetween + " minutes"; } else if (hoursBetween <= 48) { sinceString = hoursBetween + " hours"; } else if (daysBetween <= 14) { sinceString = daysBetween + " days"; } else { sinceString = weeksBetween + " weeks"; } } else { // TODO: Find a new issue date, or date of first insert into blockchain? // Transaction.getUpdateTime() first seen // tx.getUpdateTime() issueString = "No issue date given"; } // issue date is null when tx is null, getUpdateTime returning junk. tip = String.format("Issued %s ago, at block height %d, number of confirmations %d (%s)", sinceString, txHeight, numConfirmations, issueString); newAssetString = String.format( "Asset issued only %s ago, caution recommended.<br>Issued at block height %d, number of confirmations %d (%s)", sinceString, txHeight, numConfirmations, issueString); } if (assetRef == null) { // Fix for... GDG Issue 8: If an asset does not yet have an asset ref, the reason can only be that it's a genesis that has not yet been confirmed. icon = ImageLoader.fatCow16(ImageLoader.FATCOW.warning); tip = "Awaiting new asset confirmation..."; } else if (asset.getName() != null && numConfirmations < 0) { // <= icon = ImageLoader.fatCow16(ImageLoader.FATCOW.warning); // If the computer is not online, that should be the message StatusEnum state = this.multiBitFrame.getOnlineStatus(); if (state != StatusEnum.ONLINE) { tip = "Waiting to connect to network"; } else { int n = NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD; if (numConfirmsStillRequired < n) n = numConfirmsStillRequired; tip = "Waiting for wallet to sync blocks, need " + n + " more confirmations"; // tip is usually null now. : " + tip; } } else if (tx == null) { // Example: manually add an asset-ref which is bogus. tip = "Searching for the asset's genesis transaction"; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.find); // if (asset.getAssetSource() == CSAsset.CSAssetSource.GENESIS) { // } } else if (assetState == CSAsset.CSAssetState.ASSET_SPECS_NOT_FOUND || assetState == CSAsset.CSAssetState.ASSET_SPECS_NOT_PARSED || assetState == CSAsset.CSAssetState.ASSET_WEB_PAGE_NOT_FOUND || assetState == CSAsset.CSAssetState.REQUIRED_FIELD_MISSING) { tip = "Waiting for asset files to be uploaded."; if (asset.getAssetState() == CSAsset.CSAssetState.REQUIRED_FIELD_MISSING) { tip = "Asset files are missing required data."; } icon = ImageLoader.fatCow16(ImageLoader.FATCOW.server_error); } else if (assetState == CSAsset.CSAssetState.HASH_MISMATCH) { tip = "Caution: asset details do not match what was encoded by issuer.<br><br>" + tip; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.warning); } else if (assetState == CSAsset.CSAssetState.REFRESH) { tip = null; icon = null; // tip = "Refreshing..."; // icon = ImageLoader.fatCow16(ImageLoader.FATCOW.hourglass); } else if (tx != null && asset.getName() != null && numConfirmations >= 1 && numConfirmations < 1008) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.new_new); tip = newAssetString; } else if (tx != null && numConfirmations >= 1008) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.tick_shield); } map.put("tooltip", tip); map.put("icon", icon); return map; } case COLUMN_CONTRACT: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } ImageIcon icon = null; //null; // TODO: Change to webPageJSON==null String tip = null; if (assetState != CSAsset.CSAssetState.VALID && asset.getContractPath() != null) { //(asset.getName() == null && icon = ImageLoader.fatCow16(ImageLoader.FATCOW.page_white_error); tip = "Click to read the cached copy of the contract"; } else if (assetState == CSAsset.CSAssetState.VALID) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.page_white_text); tip = "Click to read the contract at the web site of the issuer"; } if (tip != null && icon != null) { map.put("tooltip", tip); map.put("icon", icon); } return map; } // case "walletAssetTableColumn.issuer": // return asset.getIssuer(); // case "walletAssetTableColumn.issueDate": // return asset.getIssueDate(); // case "walletAssetTableColumn.contractUrl": // return asset.getContractUrl(); default: return null; // return rowObj.getDescription(); // case 3: // // Amount in BTC // BigInteger debitAmount = rowObj.getDebit(); // if (debitAmount != null && debitAmount.compareTo(BigInteger.ZERO) > 0) { // return controller.getLocaliser().bitcoinValueToString(debitAmount.negate(), false, true); // } // // BigInteger creditAmount = rowObj.getCredit(); // if (creditAmount != null) { // return controller.getLocaliser().bitcoinValueToString(creditAmount, false, true); // } // // return null; // case 4: // // Amount in fiat // if (rowObj.getDebit() != null && rowObj.getDebit().compareTo(BigInteger.ZERO) > 0) { // Money debitAmountFiat = CurrencyConverter.INSTANCE.convertFromBTCToFiat(rowObj.getDebit()); // if (debitAmountFiat != null) { // return CurrencyConverter.INSTANCE.getFiatAsLocalisedString(debitAmountFiat.negated(), false, false); // } // } // // Money creditAmountFiat = CurrencyConverter.INSTANCE.convertFromBTCToFiat(rowObj.getCredit()); // if (creditAmountFiat != null) { // return CurrencyConverter.INSTANCE.getFiatAsLocalisedString(creditAmountFiat, false, false); // } // // return ""; } }
From source file:org.owasp.dependencytrack.tasks.NistDataMirrorUpdater.java
License:Open Source License
/** * Updates the NIST data directory./* www . j a va 2 s . c o m*/ * @param endYear * @param now */ public void doUpdates(int endYear, LocalDateTime now) { try { int previousEndYear = END_YEAR; boolean newYearAdded = false; END_YEAR = endYear; if (END_YEAR != previousEndYear) { newYearAdded = true; downloadURLS.add(new URL(fillInYearValue(CVE_12_BASE_URL, END_YEAR))); downloadURLS.add(new URL(fillInYearValue(CVE_20_BASE_URL, END_YEAR))); } if ((newYearAdded) || (lastDownload == null) || (now.compareTo(lastDownload.plusHours(2)) > 1)) { for (URL url : downloadURLS) { doDownload(url); } } } catch (IOException e) { LOGGER.warn("An error occurred during the NIST data mirror update process: " + e.getMessage()); } }
From source file:propel.core.utils.StringUtils.java
License:Open Source License
/** * Parses a DateTime from a string. Uses common ISO formats as well as some locale-specific formats. See * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html ISO format examples: * <ul>// ww w. jav a2 s. c o m * <li>yyyyMMdd'T'HHmmssZ</li> * <li>yyyyMMdd'T'HHmmss.SSSZ</li> * <li>yyyy-MM-dd</li> * <li>yyyy-MM-dd'T'HH:mm:ss.SSS</li> * <li>yyyy-MM-dd'T'HH:mm:ssZZ</li> * <li>yyyy-MM-dd'T'HH:mm:ss.SSSZZ</li> * <li>yyyy-MM-dd HH:mm:ss</li> * <li>yyyy-MM-dd HH:mm:ss.SSSSSSS</li> * <li>yyyy-MM-dd'T'HH:mm:ss</li> * <li>yyyy-MM-dd'T'HH:mm:ss.SSSSSSS</li> * </ul> * <p/> * Also supports non-ISO formats such as yyyy/MM/dd. Furthermore attempts to parse using locale-specific parsers. * * @throws NullPointerException An argument is null. * @throws NumberFormatException Parsed value is outside of configured range, or not of correct type. */ @Validate public static LocalDateTime parseDateTime(@NotNull final String value) { LocalDateTime result = null; // attempt ISO standard parsing try { result = STANDARD_FORMATTERS.parseDateTime(value).toLocalDateTime(); } catch (Throwable e) { // continues parsing attempts } if (result == null) // first try locale-specific date/time parsing for (int dateStyle = DateFormat.FULL; dateStyle <= DateFormat.SHORT; dateStyle++) for (int timeStyle = DateFormat.FULL; timeStyle <= DateFormat.SHORT; timeStyle++) if (result == null) try { // Parse with a default format Date date = DateFormat.getDateTimeInstance(dateStyle, timeStyle, CURRENT_LOCALE) .parse(value); result = new LocalDateTime(date); break; } catch (ParseException e) { continue; } if (result == null) // now try locale-specific date parsing for (int dateStyle = DateFormat.FULL; dateStyle <= DateFormat.SHORT; dateStyle++) try { // Parse with a default format Date date = DateFormat.getDateInstance(dateStyle, CURRENT_LOCALE).parse(value); result = new LocalDateTime(date); break; } catch (ParseException e) { continue; } if (result == null) // lastly try locale-specific time parsing for (int timeStyle = DateFormat.FULL; timeStyle <= DateFormat.SHORT; timeStyle++) try { // Parse with a default format Date date = DateFormat.getTimeInstance(timeStyle, CURRENT_LOCALE).parse(value); result = new LocalDateTime(date); break; } catch (ParseException e) { continue; } if (result == null) throw new NumberFormatException("The specified date/time is not in an identifiable format: " + value); // sanity check if (result.compareTo(MIN_DATETIME) < 0) throw new NumberFormatException( "Value (" + result + ") was less than allowed minimum (" + MIN_DATETIME + ")."); if (result.compareTo(MAX_DATETIME) > 0) throw new NumberFormatException( "Value (" + result + ") was more than allowed maximum (" + MAX_DATETIME + ")."); return result; }
From source file:propel.core.utils.StringUtils.java
License:Open Source License
/** * Parses a DateTime from a string/*from w w w .ja v a 2 s . co m*/ * * @throws NullPointerException An argument is null. * @throws NumberFormatException Parsed value is outside of configured range, or not of correct type. */ @Validate public static LocalDateTime parseDateTime(@NotNull final String value, @NotNull final LocalDateTime minValue, @NotNull final LocalDateTime maxValue, @NotNull final DateTimeFormatter formatter) { // parse LocalDateTime result = formatter.parseDateTime(value).toLocalDateTime(); // sanity check if (result.compareTo(minValue) < 0) throw new NumberFormatException( "Value (" + result + ") was less than allowed minimum (" + minValue + ")."); if (result.compareTo(maxValue) > 0) throw new NumberFormatException( "Value (" + result + ") was more than allowed maximum (" + maxValue + ")."); return result; }
From source file:propel.core.validation.propertyMetadata.LocalDateTimePropertyMetadata.java
License:Open Source License
protected void checkBounds(LocalDateTime value) throws ValidationException { // check conditions if (value.compareTo(getMaxValue()) > 0) throw new ValidationException( String.format(BoundedValueTypePropertyMetadata.SHOULD_NOT_BE_GREATER_THAN, getName()) + getMaxValue()); if (value.compareTo(getMinValue()) < 0) throw new ValidationException( String.format(BoundedValueTypePropertyMetadata.SHOULD_NOT_BE_LESS_THAN, getName()) + getMinValue()); }