Example usage for java.util Set containsAll

List of usage examples for java.util Set containsAll

Introduction

In this page you can find the example usage for java.util Set containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this set contains all of the elements of the specified collection.

Usage

From source file:com.datatorrent.lib.appdata.schemas.SchemaUtils.java

/**
 * This is a utility method to check that the given JSONObject has the given keys.
 * It throws an {@link IllegalArgumentException} if it doesn't contain all the given keys.
 * @param jo The {@link JSONObject} to check.
 * @param fields The keys in the {@link JSONObject} to check.
 *//* w w w. jav  a 2  s. co  m*/
public static void checkValidKeysEx(JSONObject jo, Fields fields) {
    @SuppressWarnings("unchecked")
    Set<String> fieldSet = fields.getFields();
    Set<String> jsonKeys = getSetOfJSONKeys(jo);

    if (!jsonKeys.containsAll(fieldSet)) {

        throw new IllegalArgumentException(
                "The given set of keys " + fieldSet + " doesn't equal the set of keys in the json " + jsonKeys);
    }
}

From source file:org.thingsboard.server.dao.service.DataValidator.java

protected static void validateJsonStructure(JsonNode expectedNode, JsonNode actualNode) {
    Set<String> expectedFields = new HashSet<>();
    Iterator<String> fieldsIterator = expectedNode.fieldNames();
    while (fieldsIterator.hasNext()) {
        expectedFields.add(fieldsIterator.next());
    }/*from  w w  w.  j av a2s  .c  om*/

    Set<String> actualFields = new HashSet<>();
    fieldsIterator = actualNode.fieldNames();
    while (fieldsIterator.hasNext()) {
        actualFields.add(fieldsIterator.next());
    }

    if (!expectedFields.containsAll(actualFields) || !actualFields.containsAll(expectedFields)) {
        throw new DataValidationException(
                "Provided json structure is different from stored one '" + actualNode + "'!");
    }

    for (String field : actualFields) {
        if (!actualNode.get(field).isTextual()) {
            throw new DataValidationException(
                    "Provided json structure can't contain non-text values '" + actualNode + "'!");
        }
    }
}

From source file:com.splicemachine.db.impl.ast.JoinConditionVisitor.java

/**
 * Returns a fn that returns true if a Predicate can be evaluated at the node rsn
 *///  w ww.ja v a 2s  .  com
public static org.spark_project.guava.base.Predicate<Predicate> evalableAtNode(final ResultSetNode rsn)
        throws StandardException {
    final Set<Integer> rsns = Sets
            .newHashSet(Lists.transform(RSUtils.getSelfAndDescendants(rsn), RSUtils.rsNum));
    return new org.spark_project.guava.base.Predicate<Predicate>() {
        @Override
        public boolean apply(Predicate p) {
            try {
                return rsns.containsAll(resultSetRefs(p));
            } catch (StandardException se) {
                throw new RuntimeException(se);
            }
        }
    };
}

From source file:org.ebayopensource.turmeric.tools.errorlibrary.util.ErrorLibraryUtils.java

public static boolean isConsistent(Set<String> xmlErrors, Set<String> propertyErrors)
        throws PreProcessFailedException {
    boolean isErrorPropertiesConsistent = false;

    Set<String> propErrorscopy = new HashSet<String>();
    propErrorscopy.addAll(propertyErrors);

    if (propertyErrors.containsAll(xmlErrors)) {
        isErrorPropertiesConsistent = true;
        propErrorscopy.removeAll(xmlErrors);
    }//from   www.  j  a v a  2 s  .c o m

    if (propErrorscopy.isEmpty())
        getLogger().log(Level.INFO, "The meta-data files are consistent");
    else {
        getLogger().log(Level.WARNING,
                "The Errors.properties file has more "
                        + "errors defined in addition to those existing in ErrorData.xml. They are \n"
                        + propErrorscopy);
    }
    xmlErrors.removeAll(propertyErrors);

    if (!xmlErrors.isEmpty()) {
        getLogger().log(Level.SEVERE, "The meta-data files are inconsistent. Errors.properties does not"
                + " have all the errors defined in ErrorData.xml");
        throw new PreProcessFailedException("Errors.properties does not"
                + " have all the errors defined in ErrorData.xml namely " + xmlErrors);

    }

    return isErrorPropertiesConsistent;
}

From source file:com.popdeem.sdk.core.utils.PDSocialUtils.java

/**
 * Check if user has granted all Facebook Read Permissions
 *
 * @return true if permissions are granted, false if not
 *///from   w w w.j  ava  2s  .  c  om
public static boolean hasAllFacebookReadPermissions() {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    if (accessToken == null) {
        return false;
    }
    Set<String> grantedPermissions = AccessToken.getCurrentAccessToken().getPermissions();
    return grantedPermissions.containsAll(Arrays.asList(FACEBOOK_READ_PERMISSIONS));
}

From source file:edu.umass.cs.utils.Util.java

public static Object getRandomOtherThan(Set<?> all, Set<?> exclude) {
    Object[] allArray = all.toArray();
    int index = -1;
    if (exclude.containsAll(all))
        return null;
    while (exclude.contains(allArray[index = (int) (Math.random() * allArray.length)]))
        ;/*from   w w w . ja v a  2s  .co  m*/
    return allArray[index];
}

From source file:org.apache.asterix.optimizer.rules.util.EquivalenceClassUtils.java

/**
 * Find the header variables that can imply all subplan-local live variables at <code>operator</code>.
 *
 * @param operator//from w  ww.  j  ava2 s.c  o  m
 *            the operator of interest.
 * @param usedForCorrelationJoin
 *            whether the generated primary key will be used for a join that recovers the correlation.
 * @param context
 *            the optimization context.
 * @return Pair<ILogicalOperator, Set<LogicalVariable>>, an operator (which is either the original parameter
 *         <code>operator</code> or a newly created operator) and
 *         a set of primary key variables at the operator.
 * @throws AlgebricksException
 */
public static Pair<ILogicalOperator, Set<LogicalVariable>> findOrCreatePrimaryKeyOpAndVariables(
        ILogicalOperator operator, boolean usedForCorrelationJoin, IOptimizationContext context)
        throws AlgebricksException {
    computePrimaryKeys(operator, context);

    Set<LogicalVariable> liveVars = new HashSet<>();
    VariableUtilities.getSubplanLocalLiveVariables(operator, liveVars);

    Set<LogicalVariable> primaryKeyVars = new HashSet<>();
    Set<LogicalVariable> noKeyVars = new HashSet<>();
    for (LogicalVariable liveVar : liveVars) {
        List<LogicalVariable> keyVars = context.findPrimaryKey(liveVar);
        if (keyVars != null) {
            keyVars.retainAll(liveVars);
        }
        if ((keyVars == null || keyVars.isEmpty())) {
            noKeyVars.add(liveVar);
        } else {
            primaryKeyVars.addAll(keyVars);
        }
    }
    primaryKeyVars.retainAll(liveVars);
    if (primaryKeyVars.containsAll(noKeyVars)) {
        return new Pair<ILogicalOperator, Set<LogicalVariable>>(operator, primaryKeyVars);
    } else {
        LogicalVariable assignVar = context.newVar();
        ILogicalOperator assignOp = new AssignOperator(assignVar,
                new MutableObject<ILogicalExpression>(new StatefulFunctionCallExpression(
                        FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.CREATE_QUERY_UID), null)));
        OperatorPropertiesUtil.markMovable(assignOp, !usedForCorrelationJoin);
        assignOp.getInputs().add(new MutableObject<ILogicalOperator>(operator));
        context.addPrimaryKey(new FunctionalDependency(Collections.singletonList(assignVar),
                new ArrayList<LogicalVariable>(liveVars)));
        context.computeAndSetTypeEnvironmentForOperator(assignOp);
        return new Pair<ILogicalOperator, Set<LogicalVariable>>(assignOp, Collections.singleton(assignVar));
    }
}

From source file:uniol.apt.analysis.cycles.lts.AllSmallCyclesHavePVOne.java

/**
 * Recursive implementation of the depth-first search that looks for cycles with a Parikh vector of at most all
 * ones./*from www. ja v  a2 s .  c  om*/
 * @param ts The transition system to examine
 * @param state The next state that should be followed.
 * @param firedEvents Set of events which were already fired on the path from the initial state.
 * @param arcsFollowed List of arcs that were followed from the initial state to this state.
 * @return A pair were the first element is true if a cycle with Parikh vector 1 was found and the second
 * element is either null or a cycle with a smaller Parikh vector.
 */
static private Pair<Boolean, List<Arc>> checkPhase1(TransitionSystem ts, State state, Set<String> firedEvents,
        LinkedList<Arc> arcsFollowed) {
    boolean success = false;
    for (Arc arc : state.getPostsetEdges()) {
        if (firedEvents.contains(arc.getLabel()))
            continue;

        firedEvents.add(arc.getLabel());
        arcsFollowed.addLast(arc);

        State target = arc.getTarget();
        if (target.equals(ts.getInitialState())) {
            if (firedEvents.containsAll(ts.getAlphabet())) {
                // Found a suitable cycle!
                success = true;
            } else {
                // Found a counter-example
                return new Pair<Boolean, List<Arc>>(false, arcsFollowed);
            }
        } else {
            // Recurse to this new state
            Pair<Boolean, List<Arc>> result = checkPhase1(ts, target, firedEvents, arcsFollowed);
            if (result.getSecond() != null)
                return result;
            success = success || result.getFirst();
        }

        // Undo the modifications done above
        boolean r = firedEvents.remove(arc.getLabel());
        assert r == true;
        Arc last = arcsFollowed.removeLast();
        assert last == arc;
    }
    return new Pair<>(success, null);
}

From source file:ai.grakn.graql.internal.gremlin.GraqlTraversal.java

/**
 * Find a traversal plan that will satisfy the given equivalent fragment sets
 * @param fragmentSets a set of equivalent fragment sets describing part of a query
 * @param names a set of names that have already been encountered while executing the query
 * @param cost the cost of the query plan so far
 * @param depth the maximum depth the plan is allowed to descend in the tree
 * @return a pair, containing the cost of the plan and a list of fragments comprising the traversal plan
 *//* w  w w  . jav a2s.  co m*/
private static Pair<Double, List<Fragment>> findPlan(Set<EquivalentFragmentSet> fragmentSets, Set<String> names,
        double cost, long depth) {
    // Base case
    Pair<Double, List<Fragment>> baseCase = Pair.with(cost, Lists.newArrayList());

    if (depth == 0)
        return baseCase;

    Comparator<Pair<Double, List<Fragment>>> byCost = comparing(Pair::getValue0);

    // Try every fragment that has its dependencies met, then select the lowest cost fragment
    return fragments(fragmentSets).filter(fragment -> names.containsAll(fragment.getDependencies()))
            .map(fragment -> findPlanWithFragment(fragment, fragmentSets, names, cost, depth)).min(byCost)
            .orElse(baseCase);
}

From source file:grails.plugin.springsecurity.SpringSecurityUtils.java

public static boolean ifAllGranted(final Collection<? extends GrantedAuthority> roles) {
    Set<String> inferredNames = authoritiesToRoles(findInferredAuthorities(getPrincipalAuthorities()));
    return inferredNames.containsAll(authoritiesToRoles(roles));
}