本文整理汇总了Java中java.util.ArrayList.retainAll方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayList.retainAll方法的具体用法?Java ArrayList.retainAll怎么用?Java ArrayList.retainAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayList
的用法示例。
在下文中一共展示了ArrayList.retainAll方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: editWorkingList
import java.util.ArrayList; //导入方法依赖的package包/类
private void editWorkingList() {
String list = listComboBox.getSelectedItem().toString();
if (list.equals(CLEAR_LIST)) {
((ListEditorModel<String>) workingList.getModel()).clear();
} else {
if (unionCB.isSelected()) {
((ListEditorModel<String>) workingList.getModel()).addAll(
new ArrayList<String>(MFMPlayLists.getInstance().getPlayList(list)));
} else if (intersectionCB.isSelected()) {
// Gotta be a more direct way of doing this
Object[] elements = ((ListEditorModel<String>) workingList.getModel()).toArray();
String[] strings = Arrays.copyOf(elements, elements.length, String[].class);
ArrayList<String> currentList = new ArrayList<String>(Arrays.asList(strings));
currentList.retainAll(new ArrayList<String>(MFMPlayLists.getInstance().getPlayList(list)));
((ListEditorModel<String>) workingList.getModel()).refreshList(currentList);
} else if (exclusionCB.isSelected()) {
((ListEditorModel<String>) workingList.getModel()).removeAll(
new ArrayList<String>(MFMPlayLists.getInstance().getPlayList(list)));
}
}
displayCurrentCount();
}
示例2: all
import java.util.ArrayList; //导入方法依赖的package包/类
static HashMap<String, Object> all( List<Node> lastOrdered, List<Node> predicted) {
HashMap<String, Object> evaluations = new HashMap<>();
ArrayList<Node> intersection = new ArrayList<>(lastOrdered);
intersection.retainAll(predicted);
Double precision = (double)intersection.size()/predicted.size();
Double recall = (double) intersection.size()/lastOrdered.size();
Double f1 = 2 * precision * recall / (precision + recall);
evaluations.put("intersection", intersection);
evaluations.put("precision", precision);
evaluations.put("recall", recall);
evaluations.put("f1", f1);
return evaluations;
}
示例3: cancelListOfOrders
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* take the list of orders and call hashnest to cancel them.
* <p>on successful cancelling, remove the orders from the active list</p>
* <p>Hashnest client exceptions will be swallowed. Logmessage will be written.</p>
* <p>cancels will have all unsuccessful removes retained.</p>
* @param activeOrders the list of active orders, will be modified!
* @param cancels the list of cancellations, successful cancels are removed
*/
protected void cancelListOfOrders(List<OrderData> activeOrders, ArrayList<OrderData> cancels) {
if(!cancels.isEmpty()) {
log.debug("going to hashnest, will cancel {} orders", cancels.size());
for (OrderData order : cancels) {
try {
client.cancelOrder(order.getId());
log.info("Order {} cancelled in the market", order.getId());
activeOrders.remove(order);
} catch (HashnestServiceException e) {
log.warn("unable to cancel order {}, cancel manually!", order.getId());
}
}
// remove all elements from cancels, that are no longer active.
cancels.retainAll(activeOrders);
}
else {
log.debug("no orders cancelled.");
}
}
示例4: getDistinctEtats
import java.util.ArrayList; //导入方法依赖的package包/类
public ArrayList<String> getDistinctEtats(){
ArrayList<String> etats = new ArrayList<String>();
for(Etat etat: Arrays.asList(Etat.values())){
etats.add(etat.name());
}
List <String> distinctEtats = Card.findDistinctEtats();
etats.retainAll(distinctEtats);
return etats;
}
示例5: intersection
import java.util.ArrayList; //导入方法依赖的package包/类
public DBag intersection(DBag otherBag) {
read();
ArrayList list = new ArrayList( this.bag.size() );
list.addAll(bag);
list.retainAll(otherBag);
return new Bag( getSession(), list );
}
示例6: checkForNullJoin
import java.util.ArrayList; //导入方法依赖的package包/类
protected boolean checkForNullJoin(ArrayList<String> sharedVars) {
ArrayList<String> nullVars = new ArrayList<String>();
nullVars.addAll(sharedVars);
nullVars.retainAll(varsWithNulls);
if (nullVars.isEmpty())
return false;
else
return true;
}
示例7: intersection
import java.util.ArrayList; //导入方法依赖的package包/类
public boolean intersection(List<String> list1, List<String> list2) {
ArrayList<String> result = new ArrayList<String>(list1);
result.retainAll(list2);
if(result.size()!=0)
return true;
else
return false;
}
示例8: retainAll
import java.util.ArrayList; //导入方法依赖的package包/类
@Override
public synchronized boolean retainAll(Collection<?> c) {
ArrayList<E> newList = new ArrayList<E>(list);
// Removals in ArrayList won't break sorting
boolean changed = newList.retainAll(c);
list = Collections.unmodifiableList(newList);
return changed;
}
示例9: adaptElements
import java.util.ArrayList; //导入方法依赖的package包/类
@Override
public IAdaptable[] adaptElements(final IAdaptable[] objects) {
final ArrayList<IAdaptable> elements = newArrayList(getElements());
elements.retainAll(newArrayList(objects));
return Iterables.toArray(elements, IAdaptable.class);
}
示例10: init
import java.util.ArrayList; //导入方法依赖的package包/类
@Override
public void init(IWorkbench targetWorkbench, IStructuredSelection currentSelection) {
// this.selection = currentSelection;
List<?> selectedResources = IDE.computeSelectedResources(currentSelection);
List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
// Find all selected projects
Set<IProject> projects = selectedResources.stream()
.filter(m -> m instanceof IResource)
.map(m -> ((IResource) m).getProject())
.filter(p -> p.isOpen()) // only open projects
.collect(Collectors.toSet());
// make the behavior predictable by ordering:
TreeSet<IProject> sortedProjects = Sets
.<IProject> newTreeSet((a, b) -> a.getName()
.compareToIgnoreCase(b.getName()));
sortedProjects.addAll(projects);
// 0) turn into IN4JSProject and give and process further.
// a) find out which projects fulfill the npm-"exportable"-contract
// b) give back a list to the user what to export,
// c) disable things not fullfilling the contract.
// d) take choosing from the list and pass to exporter in non-ui package.
// 0)
List<IN4JSEclipseProject> rawN4jsProjects = Lists.newArrayList();
iP2in4jsP = HashBiMap.create();
for (IProject iProject : workspaceProjects) {
IN4JSEclipseProject mappedIn4jsProject = map2In4js(iProject);
if (mappedIn4jsProject != null) {
rawN4jsProjects.add(mappedIn4jsProject);
iP2in4jsP.put(iProject, mappedIn4jsProject);
}
}
// filter out Non-N4JS-projects from initial selection.
sortedProjects.retainAll(iP2in4jsP.keySet());
// filter out all non-N4JS-projects from the workspace projects.
ArrayList<IProject> filteredWorkspaceProjects = new ArrayList<>(workspaceProjects);
filteredWorkspaceProjects.retainAll(iP2in4jsP.keySet());
setWindowTitle("N4JS to npm Export");
setNeedsProgressMonitor(true);
Map<IProject, Boolean> selectedProjects = new HashMap<>();
// Add all workspace projects to list, default selection value is false
filteredWorkspaceProjects.forEach(project -> selectedProjects.put(project, false));
// Override selection value for all initially selected projects
sortedProjects.forEach(project -> selectedProjects.put(project, true));
// exportPage = new ExportSelectionPage("Export Page", rawN4jsProjects, labelProvider);
exportPage = new ExportSelectionPage("Export Page", selectedProjects);
if (runTools())
toolRunnerPage = new NpmToolRunnerPage("npm Execution Page");
comparePage = new PackageJsonComparePage("Compare package.json Page");
pageListener = new IPageChangedListener() {
@Override
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == comparePage) {
udpatePackagJasonComparison();
}
}
};
}
示例11: isCurrentOpponentsListActual
import java.util.ArrayList; //导入方法依赖的package包/类
private boolean isCurrentOpponentsListActual(ArrayList<QBUser> actualCurrentOpponentsList) {
boolean equalActual = actualCurrentOpponentsList.retainAll(currentOpponentsList);
boolean equalCurrent = currentOpponentsList.retainAll(actualCurrentOpponentsList);
return !equalActual && !equalCurrent;
}