List of usage examples for java.util TreeMap descendingKeySet
public NavigableSet<K> descendingKeySet()
From source file:org.dspace.discovery.SolrServiceImpl.java
protected DiscoverResult retrieveResult(Context context, DiscoverQuery query, QueryResponse solrQueryResponse) throws SQLException { DiscoverResult result = new DiscoverResult(); if (solrQueryResponse != null) { result.setSearchTime(solrQueryResponse.getQTime()); result.setStart(query.getStart()); result.setMaxResults(query.getMaxResults()); result.setTotalSearchResults(solrQueryResponse.getResults().getNumFound()); List<String> searchFields = query.getSearchFields(); for (SolrDocument doc : solrQueryResponse.getResults()) { DSpaceObject dso = findDSpaceObject(context, doc); if (dso != null) { result.addDSpaceObject(dso); } else { log.error(LogManager.getHeader(context, "Error while retrieving DSpace object from discovery index", "Handle: " + doc.getFirstValue("handle"))); continue; }/*from w w w . ja va 2s. com*/ DiscoverResult.SearchDocument resultDoc = new DiscoverResult.SearchDocument(); //Add information about our search fields for (String field : searchFields) { List<String> valuesAsString = new ArrayList<String>(); for (Object o : doc.getFieldValues(field)) { valuesAsString.add(String.valueOf(o)); } resultDoc.addSearchField(field, valuesAsString.toArray(new String[valuesAsString.size()])); } result.addSearchDocument(dso, resultDoc); if (solrQueryResponse.getHighlighting() != null) { Map<String, List<String>> highlightedFields = solrQueryResponse.getHighlighting() .get(dso.getType() + "-" + dso.getID()); if (MapUtils.isNotEmpty(highlightedFields)) { //We need to remove all the "_hl" appendix strings from our keys Map<String, List<String>> resultMap = new HashMap<String, List<String>>(); for (String key : highlightedFields.keySet()) { resultMap.put(key.substring(0, key.lastIndexOf("_hl")), highlightedFields.get(key)); } result.addHighlightedResult(dso, new DiscoverResult.DSpaceObjectHighlightResult(dso, resultMap)); } } } //Resolve our facet field values List<FacetField> facetFields = solrQueryResponse.getFacetFields(); if (facetFields != null) { for (int i = 0; i < facetFields.size(); i++) { FacetField facetField = facetFields.get(i); DiscoverFacetField facetFieldConfig = query.getFacetFields().get(i); List<FacetField.Count> facetValues = facetField.getValues(); if (facetValues != null) { if (facetFieldConfig.getType().equals(DiscoveryConfigurationParameters.TYPE_DATE) && facetFieldConfig.getSortOrder() .equals(DiscoveryConfigurationParameters.SORT.VALUE)) { //If we have a date & are sorting by value, ensure that the results are flipped for a proper result Collections.reverse(facetValues); } for (FacetField.Count facetValue : facetValues) { String displayedValue = transformDisplayedValue(context, facetField.getName(), facetValue.getName()); String field = transformFacetField(facetFieldConfig, facetField.getName(), true); String authorityValue = transformAuthorityValue(context, facetField.getName(), facetValue.getName()); String sortValue = transformSortValue(context, facetField.getName(), facetValue.getName()); String filterValue = displayedValue; if (StringUtils.isNotBlank(authorityValue)) { filterValue = authorityValue; } result.addFacetResult(field, new DiscoverResult.FacetResult(filterValue, displayedValue, authorityValue, sortValue, facetValue.getCount())); } } } } if (solrQueryResponse.getFacetQuery() != null) { //TODO: do not sort when not a date, just retrieve the facets in the order they where requested ! //At the moment facet queries are only used for dates so we need to sort our results TreeMap<String, Integer> sortedFacetQueries = new TreeMap<String, Integer>( solrQueryResponse.getFacetQuery()); for (String facetQuery : sortedFacetQueries.descendingKeySet()) { //TODO: do not assume this, people may want to use it for other ends, use a regex to make sure //We have a facet query, the values looks something like: dateissued.year:[1990 TO 2000] AND -2000 //Prepare the string from {facet.field.name}:[startyear TO endyear] to startyear - endyear String facetField = facetQuery.substring(0, facetQuery.indexOf(":")); String name = facetQuery.substring(facetQuery.indexOf('[') + 1); name = name.substring(0, name.lastIndexOf(']')).replaceAll("TO", "-"); String filter = facetQuery.substring(facetQuery.indexOf('[')); filter = filter.substring(0, filter.lastIndexOf(']') + 1); Integer count = sortedFacetQueries.get(facetQuery); //No need to show empty years if (0 < count) { result.addFacetResult(facetField, new DiscoverResult.FacetResult(filter, name, null, name, count)); } } } } return result; }
From source file:org.talend.core.model.runprocess.data.SparkBatchPerformance.java
public String createHtmlText() { StringBuilder html = new StringBuilder(); TreeMap<Integer, String> treeMap = new TreeMap<>(jobProgress); short index = 0; for (Integer job : treeMap.descendingKeySet()) { html.append("<font style='font-size:11px' color='" //$NON-NLS-1$ + (jobMode.get(job) == 2 ? COLOR_FINISHED : COLOR_RUNNING) + "'>Job " + job + " : " + jobProgress.get(job) + "%</font>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ html.append("<br>"); //$NON-NLS-1$ if (++index == LIMIT) { break; }/*from w w w.ja v a 2 s .co m*/ } return html.toString(); }