Java Code Examples for java.util.TreeSet#descendingIterator()
The following examples show how to use
java.util.TreeSet#descendingIterator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeProtocol.java From letv with Apache License 2.0 | 6 votes |
public static int computeLatestAvailableVersionFromVersionSpec(TreeSet<Integer> allAvailableFacebookAppVersions, int latestSdkVersion, int[] versionSpec) { int versionSpecIndex = versionSpec.length - 1; Iterator<Integer> fbAppVersionsIterator = allAvailableFacebookAppVersions.descendingIterator(); int latestFacebookAppVersion = -1; while (fbAppVersionsIterator.hasNext()) { int fbAppVersion = ((Integer) fbAppVersionsIterator.next()).intValue(); latestFacebookAppVersion = Math.max(latestFacebookAppVersion, fbAppVersion); while (versionSpecIndex >= 0 && versionSpec[versionSpecIndex] > fbAppVersion) { versionSpecIndex--; } if (versionSpecIndex < 0) { return -1; } if (versionSpec[versionSpecIndex] == fbAppVersion) { return versionSpecIndex % 2 == 0 ? Math.min(latestFacebookAppVersion, latestSdkVersion) : -1; } } return -1; }
Example 2
Source File: BarChartRenderer.java From pumpernickel with MIT License | 6 votes |
public DataRow(String groupLabel, Map<String, Long> data) { this.groupLabel = groupLabel; groupLabelRect = getTextSize(groupLabel); TreeSet<Long> sortedLongs = new TreeSet<>(data.values()); maxValue = sortedLongs.last(); Iterator<Long> iter = sortedLongs.descendingIterator(); while (iter.hasNext()) { Long z = iter.next(); for (Entry<String, Long> e : data.entrySet()) { if (e.getValue().equals(z)) { this.data.put(e.getKey(), e.getValue()); } } } }
Example 3
Source File: AcronymVectorOfflineTrainer.java From biomedicus with Apache License 2.0 | 6 votes |
/** * Get total word counts from a corpus before training co-occurrence vectors * * @param corpusPath path to a single file or directory (in which case all files will be visited * recursively) */ public void precountWords(String corpusPath) throws IOException { vectorSpace = new WordVectorSpace(); wordFrequency = new HashMap<>(); visited = 0; Files.walkFileTree(Paths.get(corpusPath), new FileVectorizer(false)); TreeSet<String> sortedWordFreq = new TreeSet<>(new ByValue<>(wordFrequency)); sortedWordFreq.addAll(wordFrequency.keySet()); Map<String, Integer> dictionary = new HashMap<>(); Iterator<String> iter = sortedWordFreq.descendingIterator(); for (int i = 0; i < nWords; i++) { if (!iter.hasNext()) { break; } String word = iter.next(); dictionary.put(word, i); } vectorSpace.setDictionary(dictionary); }
Example 4
Source File: FingerprintDAO.java From browserprint with MIT License | 6 votes |
/** * Get number of samples for each version. * Counts include all samples with version number higher than or equal to the version number in question. * E.g. For version 1 we have all samples, since all samples are version 1 or higher. * For version 2 we have all samples of version 2, version 3, version 4, ..., up until the latest version. * We only need to use this version aware version of sample count because we're adding features to the live site, so there will be fingerprints from older versions. * @param conn * @return * @throws SQLException */ public static TreeSet<VersionCount> getSampleCountVersionAware(Connection conn) throws SQLException { PreparedStatement getSampleCount = conn.prepareStatement(getSampleCountVersionAwareStr); TreeSet<VersionCount> counts = new TreeSet<VersionCount>(); ResultSet rs = getSampleCount.executeQuery(); while(rs.next()){ counts.add(new VersionCount(rs.getInt(1), rs.getInt(2))); } Iterator<VersionCount> it = counts.descendingIterator(); int total = 0; while(it.hasNext()){ VersionCount vc = it.next(); total += vc.getCount(); vc.setCount(total); } counts.add(new VersionCount(0, total)); rs.close(); return counts; }
Example 5
Source File: ContextQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { final CompletionWeight innerWeight = ((CompletionWeight) innerQuery.createWeight(searcher, scoreMode, boost)); final Automaton innerAutomaton = innerWeight.getAutomaton(); // If the inner automaton matches nothing, then we return an empty weight to avoid // traversing all contexts during scoring. if (innerAutomaton.getNumStates() == 0) { return new CompletionWeight(this, innerAutomaton); } // if separators are preserved the fst contains a SEP_LABEL // behind each gap. To have a matching automaton, we need to // include the SEP_LABEL in the query as well Automaton optionalSepLabel = Operations.optional(Automata.makeChar(ConcatenateGraphFilter.SEP_LABEL)); Automaton prefixAutomaton = Operations.concatenate(optionalSepLabel, innerAutomaton); Automaton contextsAutomaton = Operations.concatenate(toContextAutomaton(contexts, matchAllContexts), prefixAutomaton); contextsAutomaton = Operations.determinize(contextsAutomaton, Operations.DEFAULT_MAX_DETERMINIZED_STATES); final Map<IntsRef, Float> contextMap = new HashMap<>(contexts.size()); final TreeSet<Integer> contextLengths = new TreeSet<>(); for (Map.Entry<IntsRef, ContextMetaData> entry : contexts.entrySet()) { ContextMetaData contextMetaData = entry.getValue(); contextMap.put(entry.getKey(), contextMetaData.boost); contextLengths.add(entry.getKey().length); } int[] contextLengthArray = new int[contextLengths.size()]; final Iterator<Integer> iterator = contextLengths.descendingIterator(); for (int i = 0; iterator.hasNext(); i++) { contextLengthArray[i] = iterator.next(); } return new ContextCompletionWeight(this, contextsAutomaton, innerWeight, contextMap, contextLengthArray); }
Example 6
Source File: BeanUtilsTest.java From yuzhouwan with Apache License 2.0 | 5 votes |
@Test public void treeSetTest() { TreeSet<Integer> t = new TreeSet<>(); t.add(3); t.add(1); t.add(2); StringBuilder stringBuilder = new StringBuilder(); Iterator<Integer> iterator = t.descendingIterator(); while (iterator.hasNext()) stringBuilder.append(iterator.next()); assertEquals("321", stringBuilder.toString()); }
Example 7
Source File: SimpleTaskExplorerTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private List<Long> getSortedOfTaskExecIds(Map<Long, TaskExecution> taskExecutionMap) { List<Long> sortedExecIds = new ArrayList<>(taskExecutionMap.size()); TreeSet<TaskExecution> sortedSet = getTreeSet(); sortedSet.addAll(taskExecutionMap.values()); Iterator<TaskExecution> iterator = sortedSet.descendingIterator(); while (iterator.hasNext()) { sortedExecIds.add(iterator.next().getExecutionId()); } return sortedExecIds; }
Example 8
Source File: WhenUsingTreeSet.java From tutorials with MIT License | 5 votes |
@Test public void whenIteratingTreeSet_shouldIterateTreeSetInDescendingOrder() { TreeSet<String> treeSet = new TreeSet<>(); treeSet.add("First"); treeSet.add("Second"); treeSet.add("Third"); Iterator<String> itr = treeSet.descendingIterator(); while (itr.hasNext()) { System.out.println(itr.next()); } }