List of usage examples for java.util SortedSet isEmpty
boolean isEmpty();
From source file:com.aurel.track.admin.customize.category.report.execute.ReportBeansToXML.java
private Element createLinkElement(SortedSet<ReportBeanLink> linkSet, Map<Integer, ILinkType> linkTypeIDToLinkTypeMap, Locale locale, Document dom) { if (linkSet != null && !linkSet.isEmpty()) { Element links = dom.createElement("links"); Iterator<ReportBeanLink> iterator = linkSet.iterator(); while (iterator.hasNext()) { ReportBeanLink reportBeanLink = iterator.next(); Element linkElement = dom.createElement("link"); linkElement.appendChild(createDomElement("linkTypeName", reportBeanLink.getLinkTypeName(), dom)); if (reportBeanLink.getLinkDirection() != null) { linkElement.appendChild( createDomElement("linkDirection", reportBeanLink.getLinkDirection().toString(), dom)); }/*from w w w . j av a 2s.c om*/ if (reportBeanLink.getWorkItemID() != null) { linkElement.appendChild( createDomElement("issueNo", reportBeanLink.getWorkItemID().toString(), dom)); } Map<String, String> itemLinkSpecificMap = getLinkSpecificData(reportBeanLink, linkTypeIDToLinkTypeMap, locale); if (itemLinkSpecificMap != null) { for (Map.Entry<String, String> entry : itemLinkSpecificMap.entrySet()) { linkElement.appendChild(createDomElement(entry.getKey(), entry.getValue(), dom)); } } links.appendChild(linkElement); } return links; } return null; }
From source file:org.stockwatcher.data.cassandra.WatchListDAOImpl.java
@Override public void deleteWatchList(StatementOptions options, UUID id) { if (id == null) { throw new IllegalArgumentException("id argument is null"); }//from ww w. j a v a2 s. c o m try { // Get the stock symbols before we delete them from the watch list SortedSet<String> symbols = getWatchListStockSymbols(options, id); RegularStatement statement1 = delete().from("WatchListItem").where(eq("watchlist_id", id)); Batch batch = batch(statement1); RegularStatement statement2 = delete().from("WatchList").where(eq("watchlist_id", id)); batch.add(statement2); execute(batch, options); // Statements with counter column families cannot be executed in a batch if (!symbols.isEmpty()) { Statement statement3 = update("StockCount").with(decr("watch_count")) .where(in("stock_symbol", (Object[]) symbols.toArray())); execute(statement3, options); } } catch (DriverException e) { throw new DAOException(e); } }
From source file:org.apache.hadoop.hdfs.server.namenode.JournalSet.java
/** * Return a manifest of what finalized edit logs are available. All available * edit logs are returned starting from the transaction id passed. If * 'fromTxId' falls in the middle of a log, that log is returned as well. * /*from w w w.j a v a2 s .co m*/ * @param fromTxId Starting transaction id to read the logs. * @return RemoteEditLogManifest object. */ public synchronized RemoteEditLogManifest getEditLogManifest(long fromTxId) { // Collect RemoteEditLogs available from each FileJournalManager List<RemoteEditLog> allLogs = Lists.newArrayList(); for (JournalAndStream j : journals) { if (j.getManager() instanceof FileJournalManager) { FileJournalManager fjm = (FileJournalManager) j.getManager(); try { allLogs.addAll(fjm.getRemoteEditLogs(fromTxId, false)); } catch (Throwable t) { LOG.warn("Cannot list edit logs in " + fjm, t); } } } // Group logs by their starting txid ImmutableListMultimap<Long, RemoteEditLog> logsByStartTxId = Multimaps.index(allLogs, RemoteEditLog.GET_START_TXID); long curStartTxId = fromTxId; List<RemoteEditLog> logs = Lists.newArrayList(); while (true) { ImmutableList<RemoteEditLog> logGroup = logsByStartTxId.get(curStartTxId); if (logGroup.isEmpty()) { // we have a gap in logs - for example because we recovered some old // storage directory with ancient logs. Clear out any logs we've // accumulated so far, and then skip to the next segment of logs // after the gap. SortedSet<Long> startTxIds = Sets.newTreeSet(logsByStartTxId.keySet()); startTxIds = startTxIds.tailSet(curStartTxId); if (startTxIds.isEmpty()) { break; } else { if (LOG.isDebugEnabled()) { LOG.debug("Found gap in logs at " + curStartTxId + ": " + "not returning previous logs in manifest."); } logs.clear(); curStartTxId = startTxIds.first(); continue; } } // Find the one that extends the farthest forward RemoteEditLog bestLog = Collections.max(logGroup); logs.add(bestLog); // And then start looking from after that point curStartTxId = bestLog.getEndTxId() + 1; } RemoteEditLogManifest ret = new RemoteEditLogManifest(logs); if (LOG.isDebugEnabled()) { LOG.debug("Generated manifest for logs since " + fromTxId + ":" + ret); } return ret; }
From source file:uk.ac.ebi.fg.jobs.PubMedDataMinerJob.java
public void doExecute(JobExecutionContext jobExecutionContext) throws JobExecutionException, InterruptedException { JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap(); Set<String> pubMedNewIds = (Set<String>) dataMap.get("pubMedNewIds"); ConcurrentHashMap<String, SortedSet<PubMedId>> pubMedIdRelationMap = (ConcurrentHashMap<String, SortedSet<PubMedId>>) dataMap .get("pubMedIdRelationMap"); Configuration properties = (Configuration) dataMap.get("properties"); AtomicInteger pubMedCounter = (AtomicInteger) dataMap.get("pubMedCounter"); PubMedRetriever pubMedRetriever = (PubMedRetriever) dataMap.get("pubMedRetriever"); String entry = (String) dataMap.get("entry"); String pubMedURL = properties.getString("pub_med_url"); int maxPubMedDist = properties.getInt("max_pubmed_distance"); SortedSet<PubMedId> similarPublications = new TreeSet<PubMedId>(); // add publication with distance 0 similarPublications.add(new PubMedId(entry, 0)); // get similar publications (distance 1) if (maxPubMedDist >= 1) similarPublications.addAll(getPubMedIdSet(pubMedRetriever.getSimilars(pubMedURL, entry), 1)); // get publications with distance 2 if (null != similarPublications && maxPubMedDist == 2) { SortedSet<PubMedId> iterationSet = new TreeSet<PubMedId>(similarPublications); for (PubMedId publication : iterationSet) similarPublications.addAll(/*from ww w. j a v a 2 s . c o m*/ getPubMedIdSet(pubMedRetriever.getSimilars(pubMedURL, publication.getPublicationId()), 2)); } if (!similarPublications.isEmpty()) pubMedIdRelationMap.putIfAbsent(entry, similarPublications); // delay job to run for 1 second Thread.currentThread().wait(1000); logger.debug("Finished " + pubMedCounter.incrementAndGet() + " of " + pubMedNewIds.size() + " PubMedDataMinerJobs"); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.thesis.ManageThesisDA.java
private Thesis findPreviousThesis(final SortedSet<Enrolment> dissertationEnrolments) { if (dissertationEnrolments.isEmpty()) { return null; }//from w ww .j a va 2s . co m final Enrolment previous = dissertationEnrolments.last(); if (previous != null) { if (!previous.getThesesSet().isEmpty()) { return previous.getThesis(); } else { dissertationEnrolments.remove(previous); return findPreviousThesis(dissertationEnrolments); } } return null; }
From source file:org.wrml.runtime.rest.ApiNavigator.java
public UUID getResourceTemplateId(final URI uri) { final SortedSet<ResourceMatchResult> results = match(uri); if (results == null || results.isEmpty()) { return null; }// w w w. j a va 2 s . co m final ResourceMatchResult result = results.first(); final Resource resource = result.getResource(); return resource.getResourceTemplateId(); }
From source file:org.apache.cxf.fediz.service.oidc.clients.ClientRegistrationService.java
protected RegisteredClients registerNewClient(Client newClient) { String userName = newClient.getResourceOwnerSubject().getLogin(); Set<String> names = clientNames.get(userName); if (names == null) { names = new HashSet<String>(); clientNames.put(userName, names); } else if (names.contains(newClient.getApplicationName())) { String newName = newClient.getApplicationName(); SortedSet<Integer> numbers = new TreeSet<Integer>(); for (String name : names) { if (name.startsWith(newName) && !name.equals(newName)) { try { numbers.add(Integer.valueOf(name.substring(newName.length()))); } catch (Exception ex) { // can be characters, continue; }//ww w. jav a 2s . c o m } } int nextNumber = numbers.isEmpty() ? 2 : numbers.last() + 1; newClient.setApplicationName(newName + nextNumber); } names.add(newClient.getApplicationName()); clientProvider.setClient(newClient); Collection<Client> clientRegistrations = getClientRegistrations(); clientRegistrations.add(newClient); return new RegisteredClients(clientRegistrations); }
From source file:org.apache.geronimo.console.databasemanager.wizard.DatabasePoolPortlet.java
private static File getRAR(PortletRequest request, String rarPath) { org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact .create(rarPath);/*w w w .j a v a 2 s .c o m*/ ListableRepository[] repos = PortletManager.getCurrentServer(request).getRepositories(); for (ListableRepository repo : repos) { // if the artifact is not fully resolved then try to resolve it if (!artifact.isResolved()) { SortedSet results = repo.list(artifact); if (!results.isEmpty()) { artifact = (Artifact) results.first(); } else { continue; } } File url = repo.getLocation(artifact); if (url != null) { if (url.exists() && url.canRead() && !url.isDirectory()) { return url; } } } return null; }
From source file:org.stockwatcher.data.cassandra.StockDAOImpl.java
@Override public SortedSet<Industry> getIndustries(StatementOptions options) { SortedSet<Industry> industries = new TreeSet<Industry>(); try {/*from ww w . j a v a 2 s . c o m*/ Statement statement = select().column("industry_id").column("industry_name").column("sector_id") .column("sector_name").from("Industry"); for (Row row : execute(statement, options)) { industries.add(createIndustry(row)); } } catch (DriverException e) { throw new DAOException(e); } if (industries.isEmpty()) { throw new DAOException("no industries found"); } return industries; }
From source file:org.xwiki.extension.repository.internal.DefaultExtensionRepositoryManager.java
@Override public IterableResult<Version> resolveVersions(String id, int offset, int nb) throws ResolveException { SortedSet<Version> versionSet = new TreeSet<Version>(); for (ExtensionRepository repository : this.repositories) { try {/*from ww w . ja va2 s .c o m*/ IterableResult<Version> versions = repository.resolveVersions(id, 0, -1); for (Version version : versions) { versionSet.add(version); } } catch (ResolveException e) { this.logger.debug("Could not find versions for extension with id [{}]", id, e); } } if (versionSet.isEmpty()) { throw new ResolveException( MessageFormat.format("Could not find versions for extension with id [{0}]", id)); } return RepositoryUtils.getIterableResult(offset, nb, versionSet); }