Java Code Examples for java.util.ArrayList.retainAll()

The following are Jave code examples for showing how to use retainAll() of the java.util.ArrayList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: MFM   File: ListEditor.java   Source Code and License Vote up 7 votes
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();
}
 
Example 2
Project: instacart   File: Evaluations.java   Source Code and License Vote up 6 votes
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;
}
 
Example 3
Project: hashnest   File: LimitTradingStrategy.java   Source Code and License Vote up 6 votes
/**
 * 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.");
    }
}
 
Example 4
Project: esup-sgc   File: CardEtatService.java   Source Code and License Vote up 5 votes
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;
}
 
Example 5
Project: parabuild-ci   File: Bag.java   Source Code and License Vote up 5 votes
public DBag intersection(DBag otherBag) {
	read();
	ArrayList list = new ArrayList( this.bag.size() );
	list.addAll(bag);
	list.retainAll(otherBag);
	return new Bag( getSession(), list );
}
 
Example 6
Project: PigSPARQL   File: PigOpBase.java   Source Code and License Vote up 5 votes
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;
}
 
Example 7
Project: ShotsNewsApp   File: VerticalCycleAdapter.java   Source Code and License Vote up 5 votes
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;
}
 
Example 8
Project: ditb   File: SortedList.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 9
Project: n4js   File: WorkingSetAdapter.java   Source Code and License Vote up 4 votes
@Override
public IAdaptable[] adaptElements(final IAdaptable[] objects) {
	final ArrayList<IAdaptable> elements = newArrayList(getElements());
	elements.retainAll(newArrayList(objects));
	return Iterables.toArray(elements, IAdaptable.class);
}
 
Example 10
Project: n4js   File: NpmExportWizard.java   Source Code and License Vote up 4 votes
@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();
			}
		}
	};
}
 
Example 11
Project: quickblox-android   File: OpponentsActivity.java   Source Code and License Vote up 4 votes
private boolean isCurrentOpponentsListActual(ArrayList<QBUser> actualCurrentOpponentsList) {
    boolean equalActual = actualCurrentOpponentsList.retainAll(currentOpponentsList);
    boolean equalCurrent = currentOpponentsList.retainAll(actualCurrentOpponentsList);
    return !equalActual && !equalCurrent;
}