List of usage examples for java.util Collections reverse
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List<?> list)
This method runs in linear time.
From source file:de.hybris.platform.acceleratorstorefrontcommons.breadcrumb.impl.SearchBreadcrumbBuilder.java
protected void createBreadcrumbCategoryHierarchyPath(final String categoryCode, final boolean emptyBreadcrumbs, final List<Breadcrumb> breadcrumbs) { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<>(); final Collection<CategoryModel> categoryModels = new ArrayList<>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs.add(getCategoryBreadcrumb(lastCategoryModel, !emptyBreadcrumbs ? LAST_LINK_CLASS : "")); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear();//w ww . j a v a 2 s.co m categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); }
From source file:com.seajas.search.profiler.service.taxonomy.TaxonomyService.java
/** * Request the parent IDs which match the given identifier (inclusive). * //from w w w . j a v a 2s. c om * @param id * @return List<Integer> */ public List<Integer> getTaxonomyParentIds(final Integer id) { // Retrieve the node TaxonomyNode node = taxonomyDAO.findNodeById(id); // Create a new node if one doesn't already exist if (node == null) return Arrays.asList(new Integer[] { id }); else { List<Integer> result = new ArrayList<Integer>(); do { result.add(node.getId()); } while (node.getParentId() != null && (node = taxonomyDAO.findNodeById(node.getParentId())) != null); Collections.reverse(result); return result; } }
From source file:de.hybris.platform.category.impl.DefaultCategoryService.java
@Override public List<CategoryModel> getCategoryPathForProduct(final ProductModel product, final Class... includeOnlyCategories) { final List<CategoryModel> result = new ArrayList<CategoryModel>(); final Collection<CategoryModel> currentLevel = new ArrayList<CategoryModel>(); currentLevel.addAll(product.getSupercategories()); while (!CollectionUtils.isEmpty(currentLevel)) { CategoryModel categoryModel = null; for (final CategoryModel category : currentLevel) { if (categoryModel == null && shouldAddPathElement(category.getClass(), includeOnlyCategories)) { categoryModel = category; }// ww w . j a va2s. com } currentLevel.clear(); if (categoryModel != null) { currentLevel.addAll(categoryModel.getSupercategories()); result.add(categoryModel); } } Collections.reverse(result); return result; }
From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java
private void buildEntityGraph(EntityGraph<T> entityGraph, String[] attributeGraph) { List<String> attributePaths = Arrays.asList(attributeGraph); // Sort to ensure that the intermediate entity subgraphs are created accordingly. Collections.sort(attributePaths); Collections.reverse(attributePaths); // We build the entity graph based on the paths with highest depth first for (String path : attributePaths) { // Fast path - just single attribute if (!path.contains(".")) { entityGraph.addAttributeNodes(path); continue; }// w ww . j a va2s . c o m // We need to build nested sub fetch graphs String[] pathComponents = StringUtils.delimitedListToStringArray(path, "."); Subgraph<?> parent = null; for (int c = 0; c < pathComponents.length - 1; c++) { parent = c == 0 ? entityGraph.addSubgraph(pathComponents[c]) : parent.addSubgraph(pathComponents[c]); } parent.addAttributeNodes(pathComponents[pathComponents.length - 1]); } }
From source file:com.codebutler.farebot.transit.SuicaTransitData.java
public SuicaTransitData(FelicaCard card) { FelicaService service = card.getSystem(FeliCaLib.SYSTEMCODE_SUICA) .getService(FeliCaLib.SERVICE_SUICA_HISTORY); long previousBalance = -1; List<SuicaTrip> trips = new ArrayList<SuicaTrip>(); // Read blocks oldest-to-newest to calculate fare. FelicaBlock[] blocks = service.getBlocks(); for (int i = (blocks.length - 1); i >= 0; i--) { FelicaBlock block = blocks[i];/*w ww. j a v a 2 s . co m*/ SuicaTrip trip = new SuicaTrip(block, previousBalance); previousBalance = trip.getBalance(); if (trip.getTimestamp() == 0) { continue; } trips.add(trip); } // Return trips in descending order. Collections.reverse(trips); mTrips = trips.toArray(new SuicaTrip[trips.size()]); }
From source file:com.powers.wsexplorer.gui.GUIUtil.java
public static Listener createTextSortListener(final Table table, final List<String> list) { Listener sortListener = new Listener() { public void handleEvent(Event e) { final int direction = table.getSortDirection(); Collator collator = Collator.getInstance(Locale.getDefault()); TableColumn column = (TableColumn) e.widget; Collections.sort(list, collator); if (direction == SWT.DOWN) { Collections.reverse(list); table.setSortDirection(SWT.UP); } else { table.setSortDirection(SWT.DOWN); }//from ww w . jav a 2 s .c om table.removeAll(); Iterator<String> itr = list.iterator(); while (itr.hasNext()) { String value = itr.next(); if (StringUtils.isNotBlank(value)) { TableItem ti = new TableItem(table, SWT.BORDER); ti.setText(0, value); } } table.setSortColumn(column); } }; return sortListener; }
From source file:org.openmrs.module.webservices.rest.web.v1_0.search.openmrs2_0.EncounterSearchHandler2_0.java
@Override public PageableResult search(RequestContext context) throws ResponseException { String patientUuid = context.getRequest().getParameter("patient"); String encounterTypeUuid = context.getRequest().getParameter("encounterType"); String dateFrom = context.getRequest().getParameter(DATE_FROM); String dateTo = context.getRequest().getParameter(DATE_TO); Date fromDate = dateFrom != null ? (Date) ConversionUtil.convert(dateFrom, Date.class) : null; Date toDate = dateTo != null ? (Date) ConversionUtil.convert(dateTo, Date.class) : null; Patient patient = ((PatientResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Patient.class)).getByUniqueId(patientUuid); EncounterType encounterType = ((EncounterTypeResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(EncounterType.class)).getByUniqueId(encounterTypeUuid); if (patient != null && encounterType != null) { EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder() .setPatient(patient).setFromDate(fromDate).setToDate(toDate) .setEncounterTypes(Arrays.asList(encounterType)).setIncludeVoided(false) .createEncounterSearchCriteria(); List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria); String order = context.getRequest().getParameter("order"); if ("desc".equals(order)) { Collections.reverse(encounters); }/* w ww . ja v a 2s.com*/ return new NeedsPaging<Encounter>(encounters, context); } return new EmptySearchResult(); }
From source file:com.google.mr4c.config.category.CategoryBuilder.java
/** * Files in order of precedence/*w w w. j av a 2s . c o m*/ */ public void addProperties(List<URI> propFiles) throws IOException { propFiles = new ArrayList<URI>(propFiles); Collections.reverse(propFiles); // need to apply in reverse order of precedence for (URI file : propFiles) { addProperties(file); } }
From source file:de.Keyle.MyPet.api.util.inventory.IconMenuItem.java
public IconMenuItem addLoreLine(String line, int position) { Validate.notNull(line, "Lore line cannot be null"); if (line.contains("\n")) { List<String> lore = new LinkedList<>(); Collections.addAll(lore, line.split("\n")); Collections.reverse(lore); for (String l : lore) { this.lore.add(position, l); }//from w ww . j a v a 2 s.c om } else { this.lore.add(position, line); } hasChanged = true; return this; }
From source file:annis.gui.resultview.SingleResultPanel.java
public SingleResultPanel(final SDocument result, int resultNumber, ResolverProvider resolverProvider, PluginSystem ps, Set<String> visibleTokenAnnos, String segmentationName, InstanceConfig instanceConfig) { this.ps = ps; this.result = result; this.segmentationName = segmentationName; calculateHelperVariables();//from w ww . j a va 2s. co m setWidth("100%"); setHeight("-1px"); infoBar = new HorizontalLayout(); infoBar.addStyleName("docPath"); infoBar.setWidth("100%"); infoBar.setHeight("-1px"); Label lblNumber = new Label("" + (resultNumber + 1)); infoBar.addComponent(lblNumber); lblNumber.setSizeUndefined(); btInfo = new Button(); btInfo.setStyleName(ChameleonTheme.BUTTON_LINK); btInfo.setIcon(ICON_RESOURCE); btInfo.addClickListener((Button.ClickListener) this); infoBar.addComponent(btInfo); path = CommonHelper.getCorpusPath(result.getSCorpusGraph(), result); Collections.reverse(path); Label lblPath = new Label("Path: " + StringUtils.join(path, " > ")); lblPath.setWidth("100%"); lblPath.setHeight("-1px"); infoBar.addComponent(lblPath); infoBar.setExpandRatio(lblPath, 1.0f); infoBar.setSpacing(true); // THIS WAS in attach() addComponent(infoBar); try { ResolverEntry[] entries = resolverProvider.getResolverEntries(result); visualizers = new LinkedList<VisualizerPanel>(); List<VisualizerPanel> openVisualizers = new LinkedList<VisualizerPanel>(); token = result.getSDocumentGraph().getSortedSTokenByText(); List<SNode> segNodes = CommonHelper.getSortedSegmentationNodes(segmentationName, result.getSDocumentGraph()); markedAndCovered = calculateMarkedAndCoveredIDs(result, segNodes); calulcateColorsForMarkedAndCoverd(); String resultID = "" + new Random().nextInt(Integer.MAX_VALUE); for (int i = 0; i < entries.length; i++) { String htmlID = "resolver-" + resultNumber + "_" + i; VisualizerPanel p = new VisualizerPanel(entries[i], result, token, visibleTokenAnnos, markedAndCovered, markedCoveredMap, markedExactMap, htmlID, resultID, this, segmentationName, ps, instanceConfig); visualizers.add(p); Properties mappings = entries[i].getMappings(); if (Boolean.parseBoolean(mappings.getProperty(INITIAL_OPEN, "false"))) { openVisualizers.add(p); } } // for each resolver entry for (VisualizerPanel p : visualizers) { addComponent(p); } for (VisualizerPanel p : openVisualizers) { p.toggleVisualizer(true, null); } } catch (RuntimeException ex) { log.error("problems with initializing Visualizer Panel", ex); } catch (Exception ex) { log.error("problems with initializing Visualizer Panel", ex); } }