Java Collections.swap Examples

Java Collections.swap - 30 examples found. These are the top rated real world Java examples of java.util.Collections.swap extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 @Override
 public synchronized void swapColumns(final int a, final int b) {
   ensureChangeAllowed();
   setColumn(setColumn(getColumn(null, a), b), a).clear();
   Collections.swap(widths, a, b);
   Collections.swap(colNames, a, b);
 }
 public boolean onContextItemSelected(MenuItem item) {
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
   switch (item.getItemId()) {
     case ADD_STEP:
       selectedStep = preset.blankStep();
       preset.steps.add(info.position + 1, selectedStep);
       modifiedStep = selectedStep.clone();
       showDialog(EDIT_STEP);
       return true;
     case DUP_STEP:
       selectedStep = preset.steps.get(info.position).clone();
       selectedStep.name = selectedStep.name + " copy";
       preset.steps.add(info.position + 1, selectedStep);
       modifiedStep = selectedStep.clone();
       showDialog(EDIT_STEP);
       return true;
     case UP_STEP:
       Collections.swap(preset.steps, info.position, info.position - 1);
       adapter.notifyDataSetChanged();
       return true;
     case DOWN_STEP:
       Collections.swap(preset.steps, info.position, info.position + 1);
       adapter.notifyDataSetChanged();
       return true;
     case DEL_STEP: // Unreachable right now.
       preset.steps.remove(preset.steps.get(info.position));
       adapter.notifyDataSetChanged();
       return true;
     default:
       return super.onContextItemSelected(item);
   }
 }
Example #3
0
 @Override
 public synchronized void swapRows(final int a, final int b) {
   ensureChangeAllowed();
   Collections.swap(matrix, a, b);
   Collections.swap(heights, a, b);
   Collections.swap(rowNames, a, b);
 }
Example #4
0
 private void permute(
     ArrayList<State> list, int left, int right, ArrayList<ArrayList<State>> permutations) {
   if (left == right) { // In case no element is left add to permutation list
     permutations.add(new ArrayList<State>(list));
   } else {
     for (int index = left; index <= right; index++) {
       Collections.swap(list, left, index);
       permute(list, left + 1, right, permutations);
       Collections.swap(list, left, index);
     }
   }
 }
  /*
   * 移动Item
   * */
  public void moveItem(int fromPosition, int toPosition) {
    // 数据的交换
    if (fromPosition < toPosition) {
      for (int index = fromPosition; index < toPosition; index++)
        Collections.swap(mContentInfoList, index, index + 1);
    } else {
      for (int index = fromPosition; index > toPosition; index--) {
        Collections.swap(mContentInfoList, index, index - 1);
      }
    }

    notifyItemMoved(fromPosition, toPosition);
  }
Example #6
0
 private void moveTab(UITabContainer container, String childId, boolean isToLeft) {
   UIComponent selectedChild = container.getChildById(childId);
   List<UIComponent> children = container.getChildren();
   int selectedIndex = children.indexOf(selectedChild);
   if (isToLeft) {
     if (selectedIndex > 0) {
       Collections.swap(children, selectedIndex, selectedIndex - 1);
     }
   } else {
     if (selectedIndex < children.size() - 1) {
       Collections.swap(children, selectedIndex, selectedIndex + 1);
     }
   }
 }