List of usage examples for java.util Collections swap
private static void swap(Object[] arr, int i, int j)
From source file:com.nextep.datadesigner.dbgm.model.IKeyConstraint.java
public void up(IBasicColumn c) { int index = colRef.indexOf(c.getReference()); if (index > 0) { final IBasicColumn swappedCol = getColumns().get(index - 1); Collections.swap(colRef, index, index - 1); notifyListeners(ChangeEvent.MODEL_CHANGED, c); c.notifyListeners(ChangeEvent.MODEL_CHANGED, null); swappedCol.notifyListeners(ChangeEvent.MODEL_CHANGED, null); }//from w w w . j av a2 s. c o m }
From source file:io.syng.adapter.DAppDrawerAdapter.java
@Override public boolean onItemMove(int fromPosition, int toPosition) { Collections.swap(mDataSet, fromPosition, toPosition); notifyItemMoved(fromPosition, toPosition); ProfileManager.reorderDAppsInProfile(ProfileManager.getCurrentProfile(), fromPosition, toPosition); return true;//w w w .j av a 2 s . c o m }
From source file:org.nuxeo.ecm.webapp.search.SearchColumnsBean.java
private void swapResultColumns(String fieldRef1, String fieldRef2) throws ClientException { if (fieldRef1 == null || fieldRef2 == null) { throw new IllegalArgumentException("null arguments not allowed"); }/*from w w w. j ava2 s . c o m*/ int beginIndex = "fieldRef:".length(); String ref1 = fieldRef1.substring(beginIndex); String ref2 = fieldRef2.substring(beginIndex); int index = 0; int pos1 = -1; int pos2 = -1; for (FieldWidget field : resultColumns) { if (field.getFullName().equals(ref1)) { pos1 = index; } if (field.getFullName().equals(ref2)) { pos2 = index; } index++; } if (pos1 == -1 || pos2 == -1) { throw new ClientException("field not found"); } Collections.swap(resultColumns, pos1, pos2); }
From source file:edu.byu.nlp.util.Collections3.java
public static <E> void shuffle(List<E> arr, RandomGenerator rnd) { for (int i = arr.size() - 1; i > 0; i--) { Collections.swap(arr, i, rnd.nextInt(i + 1)); }// w ww . j a v a 2 s . c om }
From source file:com.nextep.datadesigner.dbgm.model.IKeyConstraint.java
public void down(IBasicColumn c) { int index = colRef.indexOf(c.getReference()); if (index < colRef.size() - 1) { final IBasicColumn swappedCol = getColumns().get(index + 1); Collections.swap(colRef, index, index + 1); notifyListeners(ChangeEvent.MODEL_CHANGED, c); c.notifyListeners(ChangeEvent.MODEL_CHANGED, null); swappedCol.notifyListeners(ChangeEvent.MODEL_CHANGED, null); }//from ww w.j a va2 s. c o m }
From source file:org.betaconceptframework.astroboa.console.jsf.edit.ComplexCmsPropertyParentWrapper.java
private void swapChildPropertyPositions(String childPropertyName, Integer fromIndex, Integer toIndex) { if (CollectionUtils.isEmpty(childComplexCmsPropertyWrappers)) { logger.error("List of child properties is empty."); JSFUtilities.addMessage(null, "object.edit.swapPropertyValuePositions.failed", null, FacesMessage.SEVERITY_WARN); return;/*from w w w. j ava 2 s . com*/ } if (cmsProperty.swapChildPropertyValues(childPropertyName, fromIndex, toIndex)) { ComplexCmsPropertyWrapper fromChildPropertyWrapper = childComplexCmsPropertyWrappers.get(fromIndex); ComplexCmsPropertyWrapper toChildPropertyWrapper = childComplexCmsPropertyWrappers.get(toIndex); fromChildPropertyWrapper.resetCmsPropertyIndex(); toChildPropertyWrapper.resetCmsPropertyIndex(); Collections.swap(childComplexCmsPropertyWrappers, fromIndex, toIndex); } else { JSFUtilities.addMessage(null, "object.edit.swapPropertyValuePositions.failed", null, FacesMessage.SEVERITY_WARN); } }
From source file:net.sourceforge.subsonic.domain.Playlist.java
/** * Moves the song at the given index one step up. * * @param index The playlist index.//w w w . j a v a 2s. c o m */ public synchronized void moveUp(int index) { makeBackup(); if (index <= 0 || index >= size()) { return; } Collections.swap(files, index, index - 1); if (this.index == index) { this.index--; } else if (this.index == index - 1) { this.index++; } }
From source file:net.sourceforge.subsonic.domain.Playlist.java
/** * Moves the song at the given index one step down. * * @param index The playlist index./*from w ww. java2s. c o m*/ */ public synchronized void moveDown(int index) { makeBackup(); if (index < 0 || index >= size() - 1) { return; } Collections.swap(files, index, index + 1); if (this.index == index) { this.index++; } else if (this.index == index + 1) { this.index--; } }
From source file:org.betaconceptframework.astroboa.model.impl.SimpleCmsPropertyImpl.java
@Override public boolean swapValues(int from, int to) { if (values == null) { return false; }//from w ww . j av a 2 s. c o m if (from == to || from < 0 || to < 0) { return false; } try { Collections.swap(values, from, to); resetPaths(); return true; } catch (Exception e) { //Ignore exception return false; } }
From source file:org.openmrs.web.controller.person.PersonAttributeTypeListController.java
/** * Moves the selected types down in the order * /*from ww w . j av a 2 s .c o m*/ * @param personAttributeTypeId list of ids to move down * @param httpSession the current session * @should move selected ids down in the list * @should not fail if given last id * @should not fail if not given any ids */ @RequestMapping(method = RequestMethod.POST, params = "action=movedown") public String moveDown(Integer[] personAttributeTypeId, HttpSession httpSession) { if (personAttributeTypeId == null) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "PersonAttributeType.select"); } else { PersonService ps = Context.getPersonService(); List<PersonAttributeType> attributes = ps.getAllPersonAttributeTypes(); // assumes attributes are returned in sortWeight order Set<PersonAttributeType> attributesToSave = new HashSet<PersonAttributeType>(); List<Integer> selectedIds = Arrays.asList(personAttributeTypeId); for (int i = attributes.size() - 2; i >= 0; i--) { PersonAttributeType current = attributes.get(i); if (selectedIds.contains(current.getPersonAttributeTypeId())) { PersonAttributeType below = attributes.get(i + 1); // swap current and the attribute below it double temp = current.getSortWeight(); current.setSortWeight(below.getSortWeight()); below.setSortWeight(temp); Collections.swap(attributes, i, i + 1); // move the actual elements in the list as well attributesToSave.add(current); attributesToSave.add(below); } } // now save things for (PersonAttributeType pat : attributesToSave) { ps.savePersonAttributeType(pat); } } return "redirect:/admin/person/personAttributeType.list"; }