Set retainAll - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Set retainAll method.

This code example shows how to use the following methods:retainAll
    public boolean removeAll(Collection<?> c) {
        return this.base.removeAll(c);
    } 
 
    public boolean retainAll(Collection<?> c) {
        return this.base.retainAll(c);
    } 
 
    public int size() { 
        return this.base.size();
    } 
 
    @SuppressWarnings("unchecked") 
    public Object[] toArray() {        
        Object[] froms = this.base.toArray();
        Object[] tos = new Object[froms.length];
        for (int i = 0; i < froms.length; i++)
            tos[i] = filter.to((F)tos[i]);
        return tos;
    } 
6
CodeRank
This code example shows how to use the following methods:retainAll, size
	 * @param target set of strings to check 
	 * @param members the members to compare to 
	 * @return true if all members are in the target 
	 */ 
	public static boolean containsAll(Set<String> target, Set<String> members) {
		target = new HashSet<String>(target);
		target.retainAll(members);
		return target.size() == members.size();
	} 
} 
7
CodeRank
This code example shows how to use the following methods:retainAll
    public boolean addAll(Collection<? extends E> c) {
        return getReference().addAll(c);
    } 
 
    public boolean retainAll(Collection<?> c) {
        return getReference().retainAll(c);
    } 
 
    public boolean removeAll(Collection<?> c) {
        return getReference().removeAll(c);
    } 
 
    public void clear() { 
        getReference().clear();
    } 
 
    public Set<E> getReference() {
        Set<E> reference = this.reference ;
        if (reference != null) {
            return reference;
6
CodeRank
This code example shows how to use the following methods:isEmpty, retainAll
        Assert.assertTrue(actual.containsAll(Arrays.asList(expected)));
    } 
 
    protected void assertDoesNotContain(Set<String> actual, String... unexpected)
    { 
        Set<String> copy = new HashSet<String>(actual);
        copy.retainAll(Arrays.asList(unexpected));
        Assert.assertTrue(copy.isEmpty());
    } 
} 
6
CodeRank
This code example shows how to use the following methods:retainAll
        // The diff snapshots behaves like a snapshot that only contains the new allocations 
        // not present in the old snapshot 
        super(getNewAllocations(newSnapshot, oldSnapshot));
 
        Set<NativeAllocationInfo> commonAllocations =
                new HashSet<NativeAllocationInfo>(oldSnapshot.getAllocations());
        commonAllocations.retainAll(newSnapshot.getAllocations());
 
        // Memory common between the old and new snapshots 
        mCommonAllocationsTotalMemory = getTotalMemory(commonAllocations);
    } 
 
    private static List<NativeAllocationInfo> getNewAllocations(NativeHeapSnapshot newSnapshot,
            NativeHeapSnapshot oldSnapshot) {
        Set<NativeAllocationInfo> allocations =
                new HashSet<NativeAllocationInfo>(newSnapshot.getAllocations());
        allocations.removeAll(oldSnapshot.getAllocations());
        return new ArrayList<NativeAllocationInfo>(allocations);
    } 
 
6
CodeRank
This code example shows how to use the following methods:retainAll
	 * Returns the intersection of two collections  
	 *  
	 * @param coll A Collection of sets 
	 */ 
	public static <T> Set<T> intersection( Collection<? extends T> c1, Collection<? extends T> c2 ) {
		Set<T> set = new HashSet<T>( c1 );
		set.retainAll(c2);
		 
		return set;
	}	 
	 
	/** 
	 * Checks if two collections have any elements in common  
	 */ 
	public static boolean intersects( Collection<?> c1, Collection<?> c2 ) {
        for(Iterator<?> i = c1.iterator(); i.hasNext();) {
            if( c2.contains( i.next() ) ) 
                return true; 
        } 
 
5
CodeRank
This code example shows how to use the following methods:retainAll
    return changed;
  } 
 
  @Override 
  public synchronized boolean retainAll(Collection<?> c) {
    SortedSet<E> newSet = new TreeSet<E>(internalSet);
    boolean changed = newSet.retainAll(c);
    internalSet = newSet;
    return changed;
  } 
 
  @Override 
  public synchronized boolean removeAll(Collection<?> c) {
    SortedSet<E> newSet = new TreeSet<E>(internalSet);
    boolean changed = newSet.removeAll(c);
    internalSet = newSet;
    return changed;
  } 
 
  @Override 
6
CodeRank
This code example shows how to use the following methods:retainAll
    public boolean removeAll(Collection<?> coll) {
        return map.keySet().removeAll(coll);
    } 
 
    public boolean retainAll(Collection<?> coll) {
        return map.keySet().retainAll(coll);
    } 
 
    public void clear() { 
        map.clear();
    } 
 
    public Object[] toArray() {
        return map.keySet().toArray();
    } 
 
    public <T> T[] toArray(T[] array) {
        return map.keySet().toArray(array);
    } 
 
5
CodeRank
This code example shows how to use the following methods:retainAll
		return set.addAll(col); 
	} 
 
	@Override 
	public boolean retainAll(final Collection<?> col) { 
		return set.retainAll(col); 
	} 
 
	@Override 
	public boolean removeAll(final Collection<?> col) { 
		return set.removeAll(col); 
	} 
 
	@Override 
	public void clear() { 
		set.clear(); 
	} 
 
	@Override 
	public boolean equals(final Object obj) { 
5
CodeRank
This code example shows how to use the following methods:retainAll
		return set.addAll(col);
	} 
 
	@Override 
	public boolean retainAll(final Collection<?> col) {
		return set.retainAll(col);
	} 
 
	@Override 
	public boolean removeAll(final Collection<?> col) {
		return set.removeAll(col);
	} 
 
	@Override 
	public void clear() { 
		set.clear();
	} 
 
	@Override 
	public boolean equals(final Object obj) {
5
CodeRank
retainAll Method Overview
Retains only the elements in this set that are contained in the specified collection (optional operation).
See Code Examples for other Java 8 Set Methods: