當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。