List of usage examples for java.util Collections swap
private static void swap(Object[] arr, int i, int j)
From source file:com.ubershy.streamsis.project.CuteProject.java
/** * Moves down the Actor in CuteProject's current SisScene. <br> * Can be useful only for GUI.//from w ww . j a v a 2 s . c o m * * @param actor * the Actor to move */ public void moveDownActorInSisScene(Actor actor) { int index = currentActors.indexOf(actor); if (currentActors.size() != index + 1) Collections.swap(currentActors, index, index + 1); getSisSceneByName(currentSisSceneName.get()).moveDownActorName(actor.getElementInfo().getName()); }
From source file:com.evolveum.midpoint.schema.util.AdminGuiConfigTypeUtil.java
public static List<GuiObjectColumnType> orderCustomColumns(List<GuiObjectColumnType> customColumns) { if (customColumns == null || customColumns.size() == 0) { return new ArrayList<>(); }/* w ww . j a va2 s . com*/ List<GuiObjectColumnType> customColumnsList = new ArrayList<>(); customColumnsList.addAll(customColumns); List<String> previousColumnValues = new ArrayList<>(); previousColumnValues.add(null); previousColumnValues.add(""); Map<String, String> columnRefsMap = new HashedMap(); for (GuiObjectColumnType column : customColumns) { columnRefsMap.put(column.getName(), column.getPreviousColumn() == null ? "" : column.getPreviousColumn()); } List<String> temp = new ArrayList<>(); int index = 0; while (index < customColumns.size()) { int sortFrom = index; for (int i = index; i < customColumnsList.size(); i++) { GuiObjectColumnType column = customColumnsList.get(i); if (previousColumnValues.contains(column.getPreviousColumn()) || !columnRefsMap.containsKey(column.getPreviousColumn())) { Collections.swap(customColumnsList, index, i); index++; temp.add(column.getName()); } } if (temp.size() == 0) { temp.add(customColumnsList.get(index).getName()); index++; } if (index - sortFrom > 1) { Collections.sort(customColumnsList.subList(sortFrom, index - 1), new Comparator<GuiObjectColumnType>() { @Override public int compare(GuiObjectColumnType o1, GuiObjectColumnType o2) { return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName()); } }); } previousColumnValues.clear(); previousColumnValues.addAll(temp); temp.clear(); } return customColumnsList; }
From source file:org.catrobat.catroid.ui.fragment.SpritesListFragment.java
private void moveSpriteDown() { Collections.swap(spriteList, spritePosition + 1, spritePosition); spriteAdapter.notifyDataSetChanged(); }
From source file:org.catrobat.catroid.ui.fragment.SpritesListFragment.java
private void moveSpriteUp() { Collections.swap(spriteList, spritePosition - 1, spritePosition); spriteAdapter.notifyDataSetChanged(); }
From source file:com.ubershy.streamsis.project.CuteProject.java
/** * Moves down the SisScene in CuteProject's list of SisScenes. <br> * Can be useful only for GUI.//from w w w.ja v a2 s .c om * * @param sisScene * the SisScene to move */ public void moveDownSisScene(SisScene sisScene) { int index = sisScenes.indexOf(sisScene); if (sisScenes.size() != index + 1) Collections.swap(sisScenes, index, index + 1); }
From source file:org.catrobat.catroid.ui.fragment.SpritesListFragment.java
private void moveSpriteToBottom() { for (int i = spritePosition; i < spriteList.size() - 1; i++) { Collections.swap(spriteList, i, i + 1); }/* www . j a va2s . c om*/ spriteAdapter.notifyDataSetChanged(); }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.operational.OperationClassDialog.java
private void moveRowUp(TableViewer nameValueTableViewer) { Table table = nameValueTableViewer.getTable(); int[] indexes = table.getSelectionIndices(); for (int index : indexes) { if (index > 0) { Collections.swap(mappingSheetRow.getNameValueProperty(), index, index - 1); nameValueTableViewer.refresh(); applyButton.setEnabled(true); }/*from w ww . j a va 2s. c om*/ } }
From source file:com.ubershy.streamsis.project.CuteProject.java
/** * Moves up the Actor in CuteProject's current SisScene. <br> * Can be useful only for GUI.// w w w . j a v a2 s . c o m * * @param actor * the Actor to move */ public void moveUpActorInSisScene(Actor actor) { int index = currentActors.indexOf(actor); if (index != 0) Collections.swap(currentActors, index, index - 1); getSisSceneByName(currentSisSceneName.get()).moveUpActorName(actor.getElementInfo().getName()); }
From source file:org.catrobat.catroid.ui.fragment.SpritesListFragment.java
private void moveSpriteToTop() { for (int i = spritePosition; i > 1; i--) { Collections.swap(spriteList, i, i - 1); }//from w w w. j a v a 2 s . co m spriteAdapter.notifyDataSetChanged(); }
From source file:org.silverpeas.attachment.web.SimpleDocumentResource.java
/** * Moves the specified document up in the list. * * @return JSON status to true if the document was locked successfully - JSON status to false * otherwise..// w w w . j av a2 s .c o m */ @PUT @Path("moveUp") @Produces(MediaType.APPLICATION_JSON) public String moveSimpleDocumentUp() { SimpleDocument document = getSimpleDocument(defaultLanguage); List<SimpleDocument> docs = getListDocuments(document); int position = docs.indexOf(document); Collections.swap(docs, position, position - 1); String message = reorderDocuments(docs); return message; }