Java Code Examples for java.util.HashSet#containsAll()

The following examples show how to use java.util.HashSet#containsAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyTodoContentProvider.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private void checkColumns(String[] projection) {
	String[] available = { TodoTable.COLUMN_CATEGORY,
			TodoTable.COLUMN_SUMMARY, TodoTable.COLUMN_DESCRIPTION,
			TodoTable.COLUMN_ID };
	if (projection != null) {
		HashSet<String> requestedColumns = new HashSet<String>(
				Arrays.asList(projection));
		HashSet<String> availableColumns = new HashSet<String>(
				Arrays.asList(available));
		// Check if all columns which are requested are available
		if (!availableColumns.containsAll(requestedColumns)) {
			throw new IllegalArgumentException(
					"Unknown columns in projection");
		}
	}
}
 
Example 2
Source File: Angle.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Checks if an angle is in a ring of given size. Will also check that
 * the atoms form an angle.
 *  @param mol The molecule that the angle is in.
 *  @param a1 Atom 1 of the angle.
 *  @param a2 Atom 2 of the angle.
 *  @param a3 Atom 3 of the angle.
 *  @param size The size of ring to check for.
 *  @return True if the angle is in the given size, false otherwise.
 */
public static boolean inRingOfSize(MMFFMolecule mol, int a1, int a2,
                                   int a3, int size) {
    RingCollection rings = mol.getRingSet();
    HashSet<Integer> angle = new HashSet<Integer>();
    angle.add(a1);
    angle.add(a2);
    angle.add(a3);

    if (mol.getBond(a1, a2) >= 0 && mol.getBond(a2, a3) >= 0)
        for (int r=0; r<rings.getSize(); r++)
            if (rings.getRingSize(r) == size) {
                HashSet<Integer> ring = new HashSet<Integer>();

                for (int a : rings.getRingAtoms(r))
                    ring.add(a);

                if (ring.containsAll(angle))
                    return true;
            }
    return false;
}
 
Example 3
Source File: MoviesProvider.java    From Popular-Movies-App with Apache License 2.0 6 votes vote down vote up
private void checkColumns(String[] projection) {
    if (projection != null) {
        HashSet<String> availableColumns = new HashSet<>(Arrays.asList(
                MoviesContract.MovieEntry.getColumns()));
        HashSet<String> requestedColumns = new HashSet<>(Arrays.asList(projection));
        if (!availableColumns.containsAll(requestedColumns)) {
            throw new IllegalArgumentException("Unknown columns in projection.");
        }
    }
}
 
Example 4
Source File: MyTodoContentProvider.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private void checkColumns(String[] projection) {
	String[] available = { TodoTable.COLUMN_CATEGORY,
			TodoTable.COLUMN_SUMMARY, TodoTable.COLUMN_DESCRIPTION,
			TodoTable.COLUMN_ID };
	if (projection != null) {
		HashSet<String> requestedColumns = new HashSet<String>(
				Arrays.asList(projection));
		HashSet<String> availableColumns = new HashSet<String>(
				Arrays.asList(available));
		// Check if all columns which are requested are available
		if (!availableColumns.containsAll(requestedColumns)) {
			throw new IllegalArgumentException(
					"Unknown columns in projection");
		}
	}
}
 
Example 5
Source File: RecentContentProvider.java    From android with Apache License 2.0 6 votes vote down vote up
private void checkColumns(String[] projection) {
    String[] available = {
            RecentTable.COLUMN_ID,
            RecentTable.COLUMN_TYPE,
            RecentTable.COLUMN_TITLE,
            RecentTable.COLUMN_LINK,
            RecentTable.COLUMN_SEASON,
            RecentTable.COLUMN_EPISODE,
            RecentTable.COLUMN_IMAGE,
            RecentTable.COLUMN_NUM_SEASONS,
            RecentTable.COLUMN_NUM_EPISODES,
            RecentTable.COLUMN_RATING};
    if (projection != null) {
        HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
        HashSet<String> availableColumns = new HashSet<String>(Arrays.asList(available));
        // check if all columns which are requested are available
        if (!availableColumns.containsAll(requestedColumns)) {
            throw new IllegalArgumentException("Unknown columns in projection");
        }
    }
}
 
Example 6
Source File: VariableFragment.java    From gAnswer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean containsAll(HashSet<Integer> s1) {
	Iterator<HashSet<Integer>> it = candTypes.iterator();
	while(it.hasNext()) {
		HashSet<Integer> s2 = it.next();
		if (s2.contains(magic_number)) {
			if (!Collections.disjoint(s1, s2)) {
				return true;
			}
		}
		else {
			if (s1.containsAll(s2) && s2.containsAll(s1)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 7
Source File: OfflineNotesProvider.java    From soas with Apache License 2.0 5 votes vote down vote up
private void checkColumns(String[] projection) {
    String[] available = {OfflineNotesDataSource.COLUMN_PHOTO_ID,
            OfflineNotesDataSource.COLUMN_NOTE,
            OfflineNotesDataSource.COLUMN_ID};

    if (projection != null) {
        HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
        HashSet<String> availableColumns = new HashSet<String>(Arrays.asList(available));

        // Check if all columns which are requested are available.
        if (!availableColumns.containsAll(requestedColumns)) {
            throw new IllegalArgumentException("Unknown columns in projection");
        }
    }
}
 
Example 8
Source File: MinionContentProvider.java    From WonderAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * This method is invoked on the query process. It's responsible to verify if all the columns projected do exist in the database.
 * Should throw a IllegalArgumentException runtime error if failed
 * @param projection The array of fields to verify
 */
public void checkColumns(String[] projection) {
    String[] available = getAvailableColumns();
    if (projection != null) {
        HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
        HashSet<String> availableColumns = new HashSet<String>(Arrays.asList(available));
        // Check if all columns which are requested are available
        if (!availableColumns.containsAll(requestedColumns)) {
            throw new IllegalArgumentException(
                    "Unknown columns in projection");
        }
    }
}
 
Example 9
Source File: DatabaseContentProvider.java    From bitseal with GNU General Public License v3.0 5 votes vote down vote up
private void checkColumns(String[] projection, int uriType) 
{
   String[] available = getAvailable(uriType);

   if (projection != null)
   {
    HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
    HashSet<String> availableColumns = new HashSet<String>(Arrays.asList(available));
    // check if all columns which are requested are available
    if (!availableColumns.containsAll(requestedColumns)) 
    {
	    throw new IllegalArgumentException("Unknown columns in projection. Exception occurred in DatabaseContentProvider.checkColumns()");
    }
  }
}
 
Example 10
Source File: TaxaOriginTrait.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private HashMap<String,String> getIncomingJumpOrigins(FlexibleTree tree){
    HashMap<String,String> out = new HashMap<String, String>();

    FlexibleNode[] tips = getTipsOfInterest(tree);
    FlexibleNode mrca = findCommonAncestor(tree, tips);
    HashSet<FlexibleNode> taxaSet = new HashSet<FlexibleNode>(Arrays.asList(tips));
    HashSet<FlexibleNode> tipSet = getTipSet(tree, mrca);
    if(!taxaSet.containsAll(tipSet)){
        System.out.println("WARNING: mixed traits in a clade");
    }
    if(!mrca.getAttribute(attributeName).equals(traitName)){
        out.put(traitName,"Multiple");
        System.out.println("Multiple origin found.");
    } else {
        boolean sameTrait = true;
        FlexibleNode currentParent = mrca;
        while(sameTrait){
            currentParent = (FlexibleNode)tree.getParent(currentParent);
            if(currentParent==null){
                out.put(traitName,"root");
                break;
            } else {
                String parentTrait = (String)currentParent.getAttribute(attributeName);
                if(!parentTrait.equals(traitName)){
                    sameTrait = false;
                    out.put(traitName,parentTrait);
                }
            }
        }


    }
    return out;
}
 
Example 11
Source File: ConcurrentHashMapIteratorTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void checkForInitialSet(int i, ConcurrentMap testMap, Map initialSet) {
  HashSet found = new HashSet(testMap.values());
  if(!found.containsAll(initialSet.values())) {
    HashSet missed = new HashSet(initialSet.values());
    missed.removeAll(found);
    fail("On run " + i + " did not find these elements of the initial set using the iterator " + missed);
  }
}
 
Example 12
Source File: Torsion.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Checks and returns the minimum ring size that a torsion is
 * contained in. Only checks rings of size 4 and 5.
 *  @param mol The molecule that the atoms are in.
 *  @param a1 Atom 1.
 *  @param a2 Atom 2.
 *  @param a3 Atom 3.
 *  @param a4 Atom 4.
 */
public static int inRingOfSize(MMFFMolecule mol, int a1, int a2,
                               int a3, int a4) {

    // If any of the four atoms don't have bonds between them, then they
    // don't form a torsion angle and there fore this invalid torsion
    // cannot be in a ring.
    if (mol.getBond(a1, a2) == -1 || mol.getBond(a2, a3) == -1
            || mol.getBond(a3, a4) == -1)
        return 0;

    // If atom 4 is connected to atom 1, then the torsion loops back on to
    // itself and is in a ring of size 4.
    if (mol.getBond(a4, a1) >= 0)
        return 4;


    RingCollection rings = mol.getRingSet();
    HashSet<Integer> tor = new HashSet<Integer>();
    tor.add(a1);
    tor.add(a2);
    tor.add(a3);
    tor.add(a4);

    // Loop over all the molecule rings, for all rings of size 5 check if
    // the set of ring atoms contains the torsion angle atoms with a set
    // intersection. If true then the ring contains the torsion.
    for (int r=0; r<rings.getSize(); r++)
        if (rings.getRingSize(r) == 5) {
            HashSet<Integer> ring = new HashSet<Integer>();

            for (int a : rings.getRingAtoms(r))
                ring.add(a);

            if (ring.containsAll(tor))
                return 5;
        }

    return 0;
}
 
Example 13
Source File: NFAGraph.java    From RegexStaticAnalysis with MIT License 5 votes vote down vote up
@Override
public boolean equals(Object o) {
	if (!super.equals(o)) {
		return false;
	}
	
	/* testing that the amount of parallel edges are equal */
	NFAGraph n = (NFAGraph) o;
	for (NFAEdge e : n.edgeSet()) {
		Set<NFAEdge> nEdges = super.getAllEdges(e.getSourceVertex(), e.getTargetVertex());
		for (NFAEdge nEdge : nEdges) {
			if (e.equals(nEdge) && e.getNumParallel() != nEdge.getNumParallel()) {
				return false;
			}
		}
		
	}
	
	if (initialState != null && !initialState.equals(n.getInitialState())) {
		return false;
	}
	
	HashSet<NFAVertexND> myAcceptingStates = new HashSet<NFAVertexND>(acceptingStates);
	HashSet<NFAVertexND> otherAcceptingStates = new HashSet<NFAVertexND>(n.getAcceptingStates());

	boolean condition1 = myAcceptingStates.size() == otherAcceptingStates.size();
	boolean condition2 = myAcceptingStates.containsAll(otherAcceptingStates);
	boolean condition3 = otherAcceptingStates.containsAll(myAcceptingStates);
	/* first condition might be redundant */
	return condition1 && condition2 && condition3 ;

}
 
Example 14
Source File: DirectMatch.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
private boolean isMatch(DecomposedGraphNode specNode, DecomposedGraphNode libNode) throws GeneticGatesException {

		HashSet<DecomposedGraphNode> visited = new HashSet<>();
		Queue<EndNode> queue = new LinkedList<>();
		queue.add(new EndNode(specNode, libNode));

		while(!queue.isEmpty()) {
			EndNode node = queue.poll();

			if(node.libNode.getChildrenNodeList().size() == 0) {
				break;
			}
			else {
				for(int i = 0; i < node.libNode.getChildrenNodeList().size(); i++) {
					if(node.specNode.getChildrenNodeList().size() != node.libNode.getChildrenNodeList().size()) {
						return false;
					}

					for(int j = 0; j < node.specNode.getChildrenNodeList().size(); j++) {
						if(!visited.contains(node.specNode.getChildrenNodeList().get(j)) &&
								node.specNode.getChildInteractionType(node.specNode.getChildrenNodeList().get(j)) == node.libNode.getChildInteractionType(node.libNode.getChildrenNodeList().get(i))) {

							visited.add(node.specNode.getChildrenNodeList().get(j));
							queue.add(new EndNode(node.specNode.getChildrenNodeList().get(j), node.libNode.getChildrenNodeList().get(i)));
						}
					}
					if(!visited.containsAll(node.specNode.getChildrenNodeList())) {
						return false;
					}

				}
			}
		}
		return true;
	}
 
Example 15
Source File: TextProvider.java    From Document-Scanner with GNU General Public License v3.0 5 votes vote down vote up
private void checkColumns(String[] projection) {
    String[] available = {TextEntry.COLUMN_SUMMARY, TextEntry.COLUMN_DESCRIPTION,TextEntry._ID };

    if (projection != null) {
        HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
        HashSet<String> availableColumns = new HashSet<String>(Arrays.asList(available));
        // check if all columns which are requested are available
        if (!availableColumns.containsAll(requestedColumns)) {
            throw new IllegalArgumentException("Unknown columns in projection");
        }
    }
}
 
Example 16
Source File: ConcurrentHashMapIteratorTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void checkForInitialSet(int i, ConcurrentMap testMap, Map initialSet) {
  HashSet found = new HashSet(testMap.values());
  if(!found.containsAll(initialSet.values())) {
    HashSet missed = new HashSet(initialSet.values());
    missed.removeAll(found);
    fail("On run " + i + " did not find these elements of the initial set using the iterator " + missed);
  }
}
 
Example 17
Source File: SetUtils.java    From workcraft with MIT License 5 votes vote down vote up
public static <T> boolean isFirstSmaller(HashSet<T> set1, HashSet<T> set2, boolean equalWins) {
    if (set2.containsAll(set1)) {
        if (set2.size() > set1.size()) return true;
        return equalWins;
    }
    return false;
}
 
Example 18
Source File: HashSetInclusionTester.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isIncludedIn(SimpleColumnCombination a, SimpleColumnCombination b) {
    HashSet<List<Long>> setA = sets.get(Integer.valueOf(a.getTable())).get(a);
    HashSet<List<Long>> setB = sets.get(Integer.valueOf(b.getTable())).get(b);
    this.numChecks++;
    return setB.containsAll(setA);
}
 
Example 19
Source File: Ideas_2011_07_24.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@ExpectWarning("GC_UNRELATED_TYPES")
static boolean test4(HashSet<Integer> s, LinkedList<String> lst) {
    return s.containsAll(lst) && lst.containsAll(s);
}
 
Example 20
Source File: Ideas_2011_07_24.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@NoWarning("GC_UNRELATED_TYPES")
static boolean test2(HashSet<Integer> s, LinkedList<Integer> lst) {
    return s.containsAll(lst) && lst.containsAll(s);
}