List of usage examples for java.util TreeSet isEmpty
public boolean isEmpty()
From source file:it.ozimov.springboot.templating.mail.service.PriorityQueueSchedulerService.java
private synchronized Optional<EmailSchedulingWrapper> dequeue() throws InterruptedException { EmailSchedulingWrapper emailSchedulingWrapper = null; timeOfNextScheduledMessage = null;/*from w w w. j a v a2s. c o m*/ while (consumer.enabled() && isNull(emailSchedulingWrapper)) { //try to find a message in queue final long now = TimeUtils.now(); for (final TreeSet<EmailSchedulingWrapper> queue : queues) { if (!queue.isEmpty()) { final long time = queue.first().getScheduledDateTime().toInstant().toEpochMilli(); if (time - now <= DELTA) { //message found! emailSchedulingWrapper = queue.pollFirst(); break; } else if (isNull(timeOfNextScheduledMessage) || time < timeOfNextScheduledMessage) { timeOfNextScheduledMessage = time; } } } if (isNull(emailSchedulingWrapper)) { //no message was found, let's sleep, some message may arrive in the meanwhile if (isNull(timeOfNextScheduledMessage)) { //all the queues are empty wait(); //the consumer starts waiting for a new email to be scheduled } else { final long waitTime = timeOfNextScheduledMessage - TimeUtils.now() - DELTA; if (waitTime > 0) { wait(waitTime); //wait before sending the most imminent scheduled email } } } } //here emailSchedulingWrapper is the message to send return Optional.ofNullable(emailSchedulingWrapper); }
From source file:org.apache.hadoop.hbase.zookeeper.lock.ZKInterProcessReadLock.java
/** * {@inheritDoc}//from w ww . j a v a 2s .co m */ @Override protected String getLockPath(String createdZNode, List<String> children) throws IOException { TreeSet<String> writeChildren = new TreeSet<String>(ZNodeComparator.COMPARATOR); for (String child : children) { if (isChildWriteLock(child)) { writeChildren.add(child); } } if (writeChildren.isEmpty()) { return null; } SortedSet<String> lowerChildren = writeChildren.headSet(createdZNode); if (lowerChildren.isEmpty()) { return null; } String pathToWatch = lowerChildren.last(); String nodeHoldingLock = lowerChildren.first(); String znode = ZKUtil.joinZNode(parentLockNode, nodeHoldingLock); handleLockMetadata(znode); return pathToWatch; }
From source file:org.mapfish.print.output.OutputFactory.java
private boolean permitted(String supportedFormat, Config config) { TreeSet<String> configuredFormats = config.getFormats(); if (configuredFormats.size() == 1 && configuredFormats.iterator().next().trim().equals("*")) { return true; }//from w ww.j ava 2 s . c o m if (configuredFormats.isEmpty()) { return "pdf".equalsIgnoreCase(supportedFormat); } for (String configuredFormat : configuredFormats) { if (configuredFormat.equalsIgnoreCase(supportedFormat)) return true; } return false; }
From source file:org.apache.hadoop.hbase.zookeeper.lock.HReadLockImpl.java
/** * {@inheritDoc}//from w w w .j a v a 2 s .c om */ @Override protected String getLockPath(String createdZNode, List<String> children) throws IOException, InterruptedException { TreeSet<String> writeChildren = new TreeSet<String>(new ZNodeComparator(zkWrapper.getIdentifier())); for (String child : children) { if (isWriteChild(child)) { writeChildren.add(child); } } if (writeChildren.isEmpty()) { return null; } SortedSet<String> lowerChildren = writeChildren.headSet(createdZNode); if (lowerChildren.isEmpty()) { return null; } String pathToWatch = lowerChildren.last(); String nodeHoldingLock = lowerChildren.first(); try { handleLockMetadata(nodeHoldingLock); } catch (IOException e) { LOG.warn("Error processing lock metadata in " + nodeHoldingLock, e); } return pathToWatch; }
From source file:org.jamocha.dn.ConflictSet.java
public synchronized RuleAndToken getCurrentlySelectedRuleAndToken() { final TreeSet<RuleAndToken> conflictingRulesAndTokensForMaxSalience = getConflictingRulesAndTokensForMaxSalience(); if (null == conflictingRulesAndTokensForMaxSalience || conflictingRulesAndTokensForMaxSalience.isEmpty()) { return null; }// ww w . j av a 2s . com return conflictingRulesAndTokensForMaxSalience.last(); }
From source file:org.cbioportal.mutationhotspots.mutationhotspotsdetection.impl.MutatedResidueImpl.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(protein.getGeneSymbol()).append("\t").append(protein.getTranscriptId().split("\\.")[0]) .append("\t").append(residue).append("\t").append(".") //score .append("\t").append(pvalue).append("\t").append(".") //qvalue ;/*from w ww .ja va 2 s .c o m*/ TreeSet<Integer> ids = new TreeSet<>(); for (Hotspot hs : hotspots) { if (hs.getPValue() <= pvalueThreahold) { ids.add(hs.getId()); } } if (!ids.isEmpty()) { sb.append("\tCLUSTER_ID=").append(StringUtils.join(ids, ",")); } TreeSet<String> pdbChains = new TreeSet<>(); for (Hotspot hs : hotspots) { if (hs.getId() > 0) { Hotspot3D hs3D = Hotspot3D.class.cast(hs); Set<Hotspot> phss = hs3D.getHotspots3D(); for (Hotspot phs : phss) { if (phs.getPValue() <= pvalueThreahold) { MutatedProtein3D p3d = MutatedProtein3D.class.cast(phs.getProtein()); pdbChains.add(p3d.getPdbId() + "." + p3d.getPdbChain() + "(" + phs.getPValue() + ")"); } } } } if (!pdbChains.isEmpty()) { sb.append(";PDB_CHAIN=").append(StringUtils.join(pdbChains, ",")); } return sb.toString(); }
From source file:org.jboss.dashboard.ui.config.components.sections.SectionCopyFormatter.java
public void service(HttpServletRequest request, HttpServletResponse response) throws FormatterException { try {/*ww w .j a va 2s.c o m*/ WorkspaceImpl workspace = (WorkspaceImpl) getSectionsPropertiesHandler().getWorkspace(); setAttribute("sectionTitle", getLocalizedValue(workspace .getSection(Long.decode(getSectionsPropertiesHandler().getSelectedSectionId())).getTitle())); renderFragment("outputStart"); WorkspacePermission sectionPerm = WorkspacePermission.newInstance(workspace, WorkspacePermission.ACTION_CREATE_PAGE); if (UserStatus.lookup().hasPermission(sectionPerm)) { Panel[] panels = workspace .getSection(Long.decode(getSectionsPropertiesHandler().getSelectedSectionId())) .getAllPanels(); TreeSet panelInstances = new TreeSet(); for (int i = 0; i < panels.length; i++) { Panel panel = panels[i]; panelInstances.add(panel.getInstanceId()); } if (!panelInstances.isEmpty()) { setAttribute("sectionTitle", LocaleManager.lookup().localize(workspace .getSection(Long.decode(getSectionsPropertiesHandler().getSelectedSectionId())) .getTitle())); renderFragment("outputMode"); renderFragment("outputHeaders"); Iterator it = panelInstances.iterator(); int counter = 0; while (it.hasNext()) { String instanceId = it.next().toString(); PanelInstance instance = workspace.getPanelInstance(instanceId); setAttribute("instanceId", instanceId); setAttribute("group", instance.getResource(instance.getProvider().getGroup(), getLocale())); setAttribute("description", instance.getResource(instance.getProvider().getDescription(), getLocale())); setAttribute("title", getLocalizedValue(instance.getTitle())); setAttribute("counter", counter); counter++; renderFragment("outputOpt"); } renderFragment("outputOptEnd"); renderFragment("outputHeadersEnd"); } else { renderFragment("outputEmpty"); getSectionsPropertiesHandler().setDuplicateSection(Boolean.FALSE); } } renderFragment("outputEnd"); } catch (Exception e) { log.error("Error rendering section copy form: ", e); } }
From source file:org.jamocha.dn.ConflictSet.java
public synchronized boolean remove(final RuleAndToken ruleAndToken) { final Integer salience = ruleAndToken.rule.getParent().getSalience(); final TreeSet<RuleAndToken> ratSet = this.rulesAndTokensBySalience.get(salience); if (null == ratSet) return false; final boolean removed = ratSet.remove(ruleAndToken); if (ratSet.isEmpty()) { this.rulesAndTokensBySalience.remove(salience); }/*from w w w. ja v a 2 s. c o m*/ return removed; }
From source file:org.opensextant.solrtexttagger.AbstractTaggerTest.java
/** Asserts the sorted arrays are equals, with a helpful error message when not. * @param message/*from ww w .j av a2 s. co m*/ * @param expecteds * @param actuals */ public void assertSortedArrayEquals(String message, Object[] expecteds, Object[] actuals) { AssertionError error = null; try { assertArrayEquals(null, expecteds, actuals); } catch (AssertionError e) { error = e; } if (error == null) return; TreeSet<Object> expectedRemaining = new TreeSet<>(Arrays.asList(expecteds)); expectedRemaining.removeAll(Arrays.asList(actuals)); if (!expectedRemaining.isEmpty()) fail(message + ": didn't find expected " + expectedRemaining.first() + " (of " + expectedRemaining.size() + "); " + error); TreeSet<Object> actualsRemaining = new TreeSet<>(Arrays.asList(actuals)); actualsRemaining.removeAll(Arrays.asList(expecteds)); fail(message + ": didn't expect " + actualsRemaining.first() + " (of " + actualsRemaining.size() + "); " + error); }
From source file:de.tudarmstadt.ukp.dkpro.tc.fstore.simple.SparseFeatureStore.java
@SuppressWarnings("unchecked") @Override//w w w .j av a2 s .c om public void setFeatureNames(TreeSet<String> featureNames) { if (featureNames == null) { throw new IllegalArgumentException("param featureNames is null"); } if (featureNames.isEmpty()) { throw new IllegalStateException("Cannot set empty feature space"); } if (!isSettingFeatureNamesAllowed()) { throw new IllegalStateException("Setting feature names is not allowed."); } Set<String> deletedFeatures = new HashSet<>( (Collection<String>) CollectionUtils.subtract(this.allFeatureNames, featureNames)); log.debug(deletedFeatures.size() + " features from test data not seen in training data, " + "removing features from the store."); this.allFeatureNames = featureNames; // update all instances to they do not contain old features for (Map<String, Object> instance : this.instanceList) { for (String deletedFeature : deletedFeatures) { if (instance.containsKey(deletedFeature)) { instance.remove(deletedFeature); } } } }