当前位置: 首页>>代码示例>>Java>>正文


Java Collections.swap方法代码示例

本文整理汇总了Java中java.util.Collections.swap方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.swap方法的具体用法?Java Collections.swap怎么用?Java Collections.swap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Collections的用法示例。


在下文中一共展示了Collections.swap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onItemDragMoving

import java.util.Collections; //导入方法依赖的package包/类
public void onItemDragMoving(RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
    int from = getViewHolderPosition(source);
    int to = getViewHolderPosition(target);

    if (from < to) {
        for (int i = from; i < to; i++) {
            Collections.swap(mData, i, i + 1);
        }
    } else {
        for (int i = from; i > to; i--) {
            Collections.swap(mData, i, i - 1);
        }
    }
    notifyItemMoved(source.getAdapterPosition(), target.getAdapterPosition());

    if (mOnItemDragListener != null && itemDragEnabled) {
        mOnItemDragListener.onItemDragMoving(source, from, target, to);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:BaseItemDraggableAdapter.java

示例2: setMainASMFile

import java.util.Collections; //导入方法依赖的package包/类
@Override
public void setMainASMFile()
{
	ASMFile activeFile = getActiveFile();
	if (activeFile == null)
	{
		Dialogues.showActionFailedDialogue("No file is selected!");
		return;
	}
	
	Project activeProject = activeFile.getProject();
	String message = "The file \"" + activeFile.getName()
			+ "\" will be used as the main file for the project \""
			+ activeProject.getName() + "\"";
	Optional<ButtonType> result = Dialogues.showConfirmationDialogue(message);
	
	if (result.get() == ButtonType.OK)
	{
		int index = activeProject.indexOf(activeFile);
		Collections.swap(activeProject, 0, index);
	}
}
 
开发者ID:dhawal9035,项目名称:WebPLP,代码行数:23,代码来源:Main.java

示例3: onItemMove

import java.util.Collections; //导入方法依赖的package包/类
@Override
public boolean onItemMove(RecyclerView.ViewHolder srcHolder, RecyclerView.ViewHolder targetHolder) {
    closeContextMenu();         // 关闭上下文菜单

    // 不同的ViewType不能拖拽换位置。
    if (srcHolder.getItemViewType() != targetHolder.getItemViewType()) return false;

    int fromPosition = srcHolder.getAdapterPosition();
    int toPosition = targetHolder.getAdapterPosition();

    Collections.swap(eventList, fromPosition, toPosition); // 交换这两个对象

    eventList.get(fromPosition).setPos(fromPosition); // 重新设置pos, Item根据pos排序
    eventList.get(toPosition).setPos(toPosition);     // 重新设置pos, Item根据pos排序

    MyAdapter.notifyItemMoved(fromPosition, toPosition);
    isSwap = true;          // 标记发生了交换

    return true; // 返回true表示处理了并可以换位置,返回false表示你没有处理并不能换位置。
}
 
开发者ID:wendyltan,项目名称:EasyTodo,代码行数:21,代码来源:MainActivity.java

示例4: selectSolution

import java.util.Collections; //导入方法依赖的package包/类
public ArrayList<Integer> selectSolution(){
    iterationNumber++;
    int  actualCost= 0;
    int bestCost = 10000000;

    candidateSolution = clone(actualSolution);
    for(int i = 0 ; i < size; i++){
        for(int j = 0; j< i; j++){
            Collections.swap(candidateSolution, i, j);
            actualCost = getCost(candidateSolution);
            Collections.swap(candidateSolution, j, i);
            if(actualCost<bestCost){
                    bestCost = actualCost;
                    intercambioX = i;
                    intercambioY = j;
            }
        }
    }


  //  System.out.println("El intercambio es " + intercambioX + " , " + intercambioY);
    Collections.swap(candidateSolution, intercambioX, intercambioY);
    return candidateSolution;

}
 
开发者ID:notanumber11,项目名称:metaheuristics,代码行数:26,代码来源:Annealing.java

示例5: keySort

import java.util.Collections; //导入方法依赖的package包/类
public <T extends Comparable<T>> void keySort(
  final List<Integer> indices, List<?> list) {
  swapMap.clear();
  for (int i = 0; i < indices.size(); i++) {
    int k = indices.get(i);
    while (swapMap.containsKey(k)) {
      k = swapMap.get(k, 0);
    }

    swapMap.put(i, k);
  }

  for (IntIntMap.Entry e : swapMap) {
    Collections.swap(list, e.key, e.value);
  }
}
 
开发者ID:implicit-invocation,项目名称:jbump,代码行数:17,代码来源:Collisions.java

示例6: onMove

import java.util.Collections; //导入方法依赖的package包/类
@Override
public boolean onMove(int srcPosition, int targetPosition) {
    if (shortCutList != null) {
        // 更换数据源中的数据Item的位置
        Collections.swap(shortCutList, srcPosition, targetPosition);
        // 更新UI中的Item的位置,主要是给用户看到交互效果
        rcvHomeAdapter.notifyItemMoved(srcPosition, targetPosition);
        Log.i(TAG, "onMove: ---");
        return true;
    }
    return false;
}
 
开发者ID:EggUncle,项目名称:XposedNavigationBar,代码行数:13,代码来源:SetFunFragment.java

示例7: onItemMove

import java.util.Collections; //导入方法依赖的package包/类
@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    // 当Item被拖拽的时候。
    Collections.swap(searchEngines, fromPosition, toPosition);
    mMenuAdapter.notifyItemMoved(fromPosition, toPosition);
    SearchEngineUtil.getInstance().save(searchEngines);
    return true;// 返回true表示处理了,返回false表示你没有处理。
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:9,代码来源:SearchEngineActivity.java

示例8: permutate

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Permutate the list and store all possible permutations in the list of integer array.
 * 
 * 
 * @param listofObjects the list of objects for which all possible permutations are required
 * @param k the recursion parameter to keep track of all permutations
 */
public static void permutate(List<Integer> listofObjects, int k) {
   for (int i = k; i < listofObjects.size(); i++) {
      Collections.swap(listofObjects, i, k);
      permutate(listofObjects, k + 1);
      Collections.swap(listofObjects, k, i);
   }
   if (k == listofObjects.size() - 1) {
      permutations.add(listofObjects.toArray(new Integer[listofObjects.size()]));
   }
}
 
开发者ID:Intelligent-Systems-Group,项目名称:jpl-framework,代码行数:18,代码来源:PermuatorCombinator.java

示例9: fireItemMoved

import java.util.Collections; //导入方法依赖的package包/类
public void fireItemMoved(int fromPosition, int toPosition) {
    if (fromPosition < toPosition) {
        for (int i = fromPosition; i < toPosition; i++) {
            Collections.swap(data, i, i + 1);
        }
    } else {
        for (int i = fromPosition; i > toPosition; i--) {
            Collections.swap(data, i, i - 1);
        }
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:12,代码来源:DrawerEditPresenter.java

示例10: calculateNextPermutation

import java.util.Collections; //导入方法依赖的package包/类
void calculateNextPermutation() {
  j = list.size() - 1;
  int s = 0;

  // Handle the special case of an empty list. Skip the calculation of the
  // next permutation.
  if (j == -1) {
    return;
  }

  while (true) {
    int q = c[j] + o[j];
    if (q < 0) {
      switchDirection();
      continue;
    }
    if (q == j + 1) {
      if (j == 0) {
        break;
      }
      s++;
      switchDirection();
      continue;
    }

    Collections.swap(list, j - c[j] + s, j - q + s);
    c[j] = q;
    break;
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:31,代码来源:Collections2.java

示例11: swapPositions

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Swap the item of list
 *
 * @param list data list
 * @param from position from
 * @param to   position to
 */
public void swapPositions(List<?> list, int from, int to) {
    if (customHeaderView != null) {
        from--;
        to--;
    }
    Collections.swap(list, from, to);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:NormalUltimateViewAdapter.java

示例12: swapPositions

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Swap the item of list
 *
 * @param list data list
 * @param from position from
 * @param to   position to
 */
public void swapPositions(List<?> list, int from, int to) {
    if (hasHeaderView()) {
        from--;
        to--;
    }
    if (enableLoadMore() && to == getItemCount() - 1) return;
    if (hasHeaderView() && to == 0) return;
    if (hasHeaderView() && from == 0) return;
    if (enableLoadMore() && from == getItemCount() - 1) return;
    Collections.swap(list, from, to);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:UltimateViewAdapter.java

示例13: moveRowDown

import java.util.Collections; //导入方法依赖的package包/类
private void moveRowDown(TableViewer nameValueTableViewer)
{
	Table table = nameValueTableViewer.getTable();
	int[] indexes = table.getSelectionIndices();
	for (int i = indexes.length - 1; i > -1; i--) {

		if (indexes[i] < mappingSheetRow.getNameValueProperty().size() - 1) {
			Collections.swap(mappingSheetRow.getNameValueProperty(), indexes[i], indexes[i] + 1);
			nameValueTableViewer.refresh();
			applyButton.setEnabled(true);

		}
	}

}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:16,代码来源:OperationClassDialog.java

示例14: reorderItems

import java.util.Collections; //导入方法依赖的package包/类
@Override
public void reorderItems(int oldPosition, int newPosition) {
	HashMap<String, Object> temp = list.get(oldPosition);
	if (oldPosition < newPosition) {
		for (int i = oldPosition; i < newPosition; i++) {
			Collections.swap(list, i, i + 1);
		}
	} else if (oldPosition > newPosition) {
		for (int i = oldPosition; i > newPosition; i--) {
			Collections.swap(list, i, i - 1);
		}
	}

	list.set(newPosition, temp);
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:16,代码来源:DragAdapter.java

示例15: onItemMove

import java.util.Collections; //导入方法依赖的package包/类
@Override
public void onItemMove(int fromPosition, int toPosition) {
    boolean attemptingToSwapWithFooter = toPosition >= mBuildItems.size();
    if (attemptingToSwapWithFooter) return;

    boolean pointlessSwap = (fromPosition == toPosition);
    if (pointlessSwap) return;

    Collections.swap(mBuildItems, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
}
 
开发者ID:kiwiandroiddev,项目名称:starcraft-2-build-player,代码行数:12,代码来源:EditBuildItemRecyclerAdapter.java


注:本文中的java.util.Collections.swap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。