List of usage examples for java.util SortedMap keySet
Set<K> keySet();
From source file:com.romeikat.datamessie.core.base.util.CollectionUtil.java
public SortedMap<String, Double> getFirstItems(final SortedMap<String, Double> map, final int numberOfItems) { if (numberOfItems <= 0) { return Collections.emptySortedMap(); }/*from w ww .j a va 2 s .c om*/ // Limit to first N terms String lastTerm = null; int i = 0; for (final String term : map.keySet()) { if (i == numberOfItems) { break; } lastTerm = term; i++; } return map.headMap(lastTerm); }
From source file:org.eclipse.skalli.core.persistence.XStreamPersistence.java
void postProcessXML(Document newDoc, Document oldDoc, Map<String, Class<?>> aliases, String userId, int modelVersion) throws MigrationException { Element newDocElement = newDoc.getDocumentElement(); Element oldDocElement = oldDoc != null ? oldDoc.getDocumentElement() : null; boolean identical = XMLDiff.identical(newDocElement, oldDocElement); setLastModifiedAttributes(newDocElement, identical ? oldDocElement : null, userId); SortedMap<String, Element> newExts = getExtensionsByAlias(newDoc, aliases); SortedMap<String, Element> oldExts = oldDoc != null ? getExtensionsByAlias(oldDoc, aliases) : null; for (String alias : newExts.keySet()) { Element newExt = newExts.get(alias); Element oldExt = oldExts != null ? oldExts.get(alias) : null; setLastModifiedAttributes(newExt, (identical || XMLDiff.identical(newExt, oldExt)) ? oldExt : null, userId);/*ww w. j av a2 s. c o m*/ } setVersionAttribute(newDoc, modelVersion); }
From source file:knowledgeMiner.mining.SentenceParserHeuristic.java
/** * Cleans the indices off the end of strings. * //ww w .j a v a 2 s.co m * @param str * A string with indices on the end of each word. * @param anchors * The anchor map to apply. * @return A string without index suffixes. */ private String reAnchorString(String str, SortedMap<String, String> anchors) { if (anchors == null) return str; String result = str.replaceAll("(\\S+)-\\d+(?= |$)", "$1"); for (String anchor : anchors.keySet()) { if (anchors.get(anchor) != null) result = WikiParser.replaceAll(result, anchor, anchors.get(anchor)); } return result; }
From source file:org.shept.util.FtpFileCopy.java
/** * Compare the source path and the destination path for filenames with the filePattern * e.g. *.bak, *tmp and copy these files to the destination dir if they are not present at the * destination or if they have changed (by modifactionDate). * Copying is done through a retrieve operation. * /*from w w w . java 2 s. c om*/ * @param ftpSource * @param localDestPat * @param filePattern * @return the number of files being copied * @throws IOException */ public Integer syncPull(FTPClient ftpSource, String localDestPat, String filePattern) throws IOException { // check for new files since the last check which need to be copied Integer number = 0; SortedMap<FileNameDate, File> destMap = FileUtils.fileMapByNameAndDate(localDestPat, filePattern); SortedMap<FileNameDate, FTPFile> sourceMap = fileMapByNameAndDate(ftpSource, filePattern); // identify the list of source files different from their destinations for (FileNameDate fk : destMap.keySet()) { sourceMap.remove(fk); } // copy the list of files from source to destination for (FTPFile file : sourceMap.values()) { logger.debug("Copying file " + file.getName() + ": " + file.getTimestamp()); File copy = new File(localDestPat, file.getName()); try { if (!copy.exists()) { // copy to tmp file first to avoid clashes during lengthy copy action File tmp = File.createTempFile("vrs", ".tmp", copy.getParentFile()); FileOutputStream writeStream = new FileOutputStream(tmp); boolean rc = ftpSource.retrieveFile(file.getName(), writeStream); writeStream.close(); if (rc) { rc = tmp.renameTo(copy); number++; } if (!rc) { tmp.delete(); // cleanup if we fail } } } catch (IOException ex) { logger.error("Ftp FileCopy did not succeed (using " + file.getName() + ")" + " FTP reported error " + ftpSource.getReplyString(), ex); } } return number; }
From source file:org.shept.util.FtpFileCopy.java
/** * Compare the source path and the destination path for filenames with the filePattern * e.g. *.bak, *tmp and copy these files to the destination dir if they are not present at the * destination or if they have changed (by modifactionDate). * Copying is done from local directory into remote ftp destination directory. * /*from w ww. ja v a 2 s . c o m*/ * @param destPath * @param localSourcePath * @param filePattern * @return the number of files being copied * @throws IOException */ public Integer syncPush(String localSourcePath, FTPClient ftpDest, String filePattern) throws IOException { // check for new files since the last check which need to be copied Integer number = 0; SortedMap<FileNameDate, FTPFile> destMap = fileMapByNameAndDate(ftpDest, filePattern); SortedMap<FileNameDate, File> sourceMap = FileUtils.fileMapByNameAndDate(localSourcePath, filePattern); // identify the list of source files different from their destinations for (FileNameDate fk : destMap.keySet()) { sourceMap.remove(fk); } // copy the list of files from source to destination for (File file : sourceMap.values()) { logger.debug(file.getName() + ": " + new Date(file.lastModified())); try { // only copy file that don't exist yet if (ftpDest.listNames(file.getName()).length == 0) { FileInputStream fin = new FileInputStream(file); String tmpName = "tempFile"; boolean rc = ftpDest.storeFile(tmpName, fin); fin.close(); if (rc) { rc = ftpDest.rename(tmpName, file.getName()); number++; } if (!rc) { ftpDest.deleteFile(tmpName); } } } catch (Exception ex) { logger.error("Ftp FileCopy did not succeed (using " + file.getName() + ")" + " FTP reported error " + ftpDest.getReplyString()); } } return number; }
From source file:org.apache.james.mailbox.maildir.mail.MaildirMessageMapper.java
/** * @see org.apache.james.mailbox.store.mail.MessageMapper#findRecentMessageUidsInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox) */// ww w.ja va2s. c o m @Override public List<Long> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException { MaildirFolder folder = maildirStore.createMaildirFolder(mailbox); SortedMap<Long, MaildirMessageName> recentMessageNames = folder.getRecentMessages(mailboxSession); return new ArrayList<Long>(recentMessageNames.keySet()); }
From source file:org.kuali.kra.budget.external.budget.impl.BudgetAdjustmentServiceHelperImpl.java
/** * This method returns the personnel salary cost. * @return//from ww w . j a v a 2s. c o m * @throws Exception */ public SortedMap<String, ScaleTwoDecimal> getPersonnelSalaryCost(Budget currentBudget, AwardBudgetExt previousBudget) throws Exception { SortedMap<String, List<ScaleTwoDecimal>> currentSalaryTotals = currentBudget .getObjectCodePersonnelSalaryTotals(); SortedMap<String, ScaleTwoDecimal> netSalary = new TreeMap<String, ScaleTwoDecimal>(); int period = currentBudget.getBudgetPeriods().size() - 1; for (String person : currentSalaryTotals.keySet()) { String key = person; if (person.contains(",")) { String[] objectCode = getElements(key); key = objectCode[0]; } ScaleTwoDecimal currentSalary = currentSalaryTotals.get(person).get(period); netSalary.put(key, currentSalary); } return netSalary; }
From source file:kmi.taa.core.PredicateObjectRetriever.java
public void execute(String input, String output, String proxy) throws IOException { BufferedReader br = null;//w w w . j a va2 s.c om String line = ""; StringBuilder builder = new StringBuilder(); try { br = new BufferedReader(new FileReader(input)); System.out.println(System.currentTimeMillis() + ": retrieving predicate links and objects ..."); Map<Integer, String> originalLines = new LinkedHashMap<>(); int lineId = 1; while ((line = br.readLine()) != null) { originalLines.put(lineId++, line); } System.out.println(System.currentTimeMillis() + ": starting multithreaded retrieving predicates and objects on all slinks ..."); SortedMap<Integer, String> results = retrieveAll(originalLines, proxy); for (Integer id : results.keySet()) { String result = results.get(id); if (!result.equals("")) { String[] pairs = result.split(System.getProperty("line.separator")); for (String po : pairs) { builder.append(originalLines.get(id) + "\t" + po); builder.append(System.lineSeparator()); } } else { builder.append(originalLines.get(id)); builder.append(System.lineSeparator()); } } } finally { if (br != null) { br.close(); } } FileHelper.writeFile(builder.toString(), output, false); System.out.println(System.currentTimeMillis() + ": po retrieving completed"); }
From source file:org.jasig.schedassist.model.VisibleSchedule.java
/** * Returns the set of {@link AvailableBlock} objects within this instance * that conflict with the argument./* w ww .j a va2s. c om*/ * * A conflict is defined as any overlap of 1 minute or more. * * @param conflict * @return a set of conflicting blocks within this instance that conflict with the block argument */ protected Set<AvailableBlock> locateConflicting(final AvailableBlock conflict) { Set<AvailableBlock> conflictingKeys = new HashSet<AvailableBlock>(); Date conflictDayStart = DateUtils.truncate(conflict.getStartTime(), java.util.Calendar.DATE); Date conflictDayEnd = DateUtils.addDays(DateUtils.truncate(conflict.getEndTime(), java.util.Calendar.DATE), 1); conflictDayEnd = DateUtils.addMinutes(conflictDayEnd, -1); AvailableBlock rangeStart = AvailableBlockBuilder.createPreferredMinimumDurationBlock(conflictDayStart, meetingDurations); LOG.debug("rangeStart: " + rangeStart); AvailableBlock rangeEnd = AvailableBlockBuilder.createBlockEndsAt(conflictDayEnd, meetingDurations.getMinLength()); LOG.debug("rangeEnd: " + rangeStart); SortedMap<AvailableBlock, AvailableStatus> subMap = blockMap.subMap(rangeStart, rangeEnd); LOG.debug("subset of blockMap size: " + subMap.size()); for (AvailableBlock mapKey : subMap.keySet()) { // all the AvailableBlock keys in the map have start/endtimes truncated to the minute // shift the key slightly forward (10 seconds) so that conflicts that start or end on the // same minute as a key does don't result in false positives Date minuteWithinBlock = DateUtils.addSeconds(mapKey.getStartTime(), 10); boolean shortCircuit = true; while (shortCircuit && CommonDateOperations.equalsOrBefore(minuteWithinBlock, mapKey.getEndTime())) { if (minuteWithinBlock.before(conflict.getEndTime()) && minuteWithinBlock.after(conflict.getStartTime())) { conflictingKeys.add(mapKey); shortCircuit = false; } minuteWithinBlock = DateUtils.addMinutes(minuteWithinBlock, 1); } } return conflictingKeys; }
From source file:org.kuali.kra.external.Cfda.service.impl.CfdaServiceImpl.java
/** * This method updates the CFDA table with the values received from the * gov site./*ww w .j a v a 2 s .c o m*/ * @see org.kuali.kra.external.Cfda.CfdaService#updateCfda() */ public CfdaUpdateResults updateCfda() { CfdaUpdateResults updateResults = new CfdaUpdateResults(); StringBuilder message = new StringBuilder(); Map<String, CFDA> govCfdaMap; try { govCfdaMap = retrieveGovCodes(); } catch (IOException ioe) { message.append("Problem encountered while retrieving cfda numbers, " + "the database was not updated." + ioe.getMessage()); updateResults.setMessage(message.toString()); return updateResults; } SortedMap<String, CFDA> kcMap = getCfdaValuesInDatabase(); updateResults.setNumberOfRecordsInKcDatabase(kcMap.size()); updateResults.setNumberOfRecordsRetrievedFromWebSite(govCfdaMap.size()); for (String key : kcMap.keySet()) { CFDA kcCfda = kcMap.get(key); CFDA govCfda = govCfdaMap.get(key); if (kcCfda.getCfdaMaintenanceTypeId().equalsIgnoreCase(Constants.CFDA_MAINT_TYP_ID_MANUAL)) { // Leave it alone. It's maintained manually. updateResults.setNumberOfRecordsNotUpdatedBecauseManual( 1 + updateResults.getNumberOfRecordsNotUpdatedBecauseManual()); } else if (kcCfda.getCfdaMaintenanceTypeId().equalsIgnoreCase(Constants.CFDA_MAINT_TYP_ID_AUTOMATIC)) { if (govCfda == null) { if (kcCfda.getActive()) { kcCfda.setActive(false); businessObjectService.save(kcCfda); updateResults.setNumberOfRecordsDeactivatedBecauseNoLongerOnWebSite( updateResults.getNumberOfRecordsDeactivatedBecauseNoLongerOnWebSite() + 1); } else { // Leave it alone for historical purposes updateResults.setNumberOfRecordsNotUpdatedForHistoricalPurposes( updateResults.getNumberOfRecordsNotUpdatedForHistoricalPurposes() + 1); } } else { if (kcCfda.getActive()) { /*if (!kcCfda.getCfdaProgramTitleName().equalsIgnoreCase(govCfda.getCfdaProgramTitleName())) { message.append("The program title for CFDA " + kcCfda.getCfdaNumber() + " changed from " + kcCfda.getCfdaProgramTitleName() + " to " + govCfda.getCfdaProgramTitleName() + ".<BR>"); }*/ updateResults.setNumberOfRecordsUpdatedBecauseAutomatic( updateResults.getNumberOfRecordsUpdatedBecauseAutomatic() + 1); } else { kcCfda.setActive(true); updateResults .setNumberOfRecordsReActivated(updateResults.getNumberOfRecordsReActivated() + 1); } kcCfda.setCfdaProgramTitleName(govCfda.getCfdaProgramTitleName()); businessObjectService.save(kcCfda); } } // Remove it from the govMap so the remaining codes are new govCfdaMap.remove(key); } // New CFDA number from govt, added to the db updateResults.setMessage(message.toString()); addNew(govCfdaMap); updateResults.setNumberOfRecordsNewlyAddedFromWebSite(govCfdaMap.size() + 1); return updateResults; }