Example usage for java.util HashSet addAll

List of usage examples for java.util HashSet addAll

Introduction

In this page you can find the example usage for java.util HashSet addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java

private static Pair<Boolean, Boolean> pushThroughOp(HashSet<LogicalVariable> toPush,
        Mutable<ILogicalOperator> opRef2, ILogicalOperator initialOp, IOptimizationContext context)
        throws AlgebricksException {
    List<LogicalVariable> initProjectList = new ArrayList<LogicalVariable>(toPush);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
    do {//from  w ww  . jav  a  2s  . c o m
        if (op2.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE
                || op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE
                || op2.getOperatorTag() == LogicalOperatorTag.PROJECT
                || op2.getOperatorTag() == LogicalOperatorTag.REPLICATE
                || op2.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
            return new Pair<Boolean, Boolean>(false, false);
        }
        if (!op2.isMap()) {
            break;
        }
        LinkedList<LogicalVariable> usedVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getUsedVariables(op2, usedVars);
        toPush.addAll(usedVars);
        LinkedList<LogicalVariable> producedVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getProducedVariables(op2, producedVars);
        toPush.removeAll(producedVars);
        // we assume pipelineable ops. have only one input
        opRef2 = op2.getInputs().get(0);
        op2 = (AbstractLogicalOperator) opRef2.getValue();
    } while (true);

    LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>();
    VariableUtilities.getProducedVariables(op2, produced2);
    LinkedList<LogicalVariable> used2 = new LinkedList<LogicalVariable>();
    VariableUtilities.getUsedVariables(op2, used2);

    boolean canCommuteProjection = initProjectList.containsAll(toPush) && initProjectList.containsAll(produced2)
            && initProjectList.containsAll(used2);
    // if true, we can get rid of the initial projection

    // get rid of useless decor vars.
    if (!canCommuteProjection && op2.getOperatorTag() == LogicalOperatorTag.GROUP) {
        boolean gbyChanged = false;
        GroupByOperator gby = (GroupByOperator) op2;
        List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> newDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) {
            LogicalVariable decorVar = GroupByOperator.getDecorVariable(p);
            if (!toPush.contains(decorVar)) {
                used2.remove(decorVar);
                gbyChanged = true;
            } else {
                newDecorList.add(p);
            }
        }
        gby.getDecorList().clear();
        gby.getDecorList().addAll(newDecorList);
        if (gbyChanged) {
            context.computeAndSetTypeEnvironmentForOperator(gby);
        }
    }
    used2.clear();
    VariableUtilities.getUsedVariables(op2, used2);

    toPush.addAll(used2); // remember that toPush is a Set
    toPush.removeAll(produced2);

    if (toPush.isEmpty()) {
        return new Pair<Boolean, Boolean>(false, false);
    }

    boolean smthWasPushed = false;
    for (Mutable<ILogicalOperator> c : op2.getInputs()) {
        if (pushNeededProjections(toPush, c, context, initialOp)) {
            smthWasPushed = true;
        }
    }
    if (op2.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans n = (AbstractOperatorWithNestedPlans) op2;
        for (ILogicalPlan p : n.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                if (pushNeededProjections(toPush, r, context, initialOp)) {
                    smthWasPushed = true;
                }
            }
        }
    }
    return new Pair<Boolean, Boolean>(smthWasPushed, canCommuteProjection);
}

From source file:org.apache.fluo.recipes.core.export.it.ExportTestBase.java

protected void diff(Map<String, Set<String>> fr, Map<String, Set<String>> er) {
    HashSet<String> allKeys = new HashSet<>(fr.keySet());
    allKeys.addAll(er.keySet());

    for (String k : allKeys) {
        Set<String> s1 = fr.getOrDefault(k, Collections.emptySet());
        Set<String> s2 = er.getOrDefault(k, Collections.emptySet());

        HashSet<String> sub1 = new HashSet<>(s1);
        sub1.removeAll(s2);/*from  ww w.  j  a v a 2s  . com*/

        HashSet<String> sub2 = new HashSet<>(s2);
        sub2.removeAll(s1);

        if (sub1.size() > 0 || sub2.size() > 0) {
            System.out.println(k + " " + sub1 + " " + sub2);
        }

    }
}

From source file:org.apache.hyracks.algebricks.rewriter.rules.IntroduceProjectsRule.java

/**
 * Collect all used variables after each operator, including the used variables in itself in the plan.
 * Collecting information in a separate method is required since there can be multiple paths in the plan
 * and introduceProjects() method can deal with only one path at a time during conducting depth-first-search.
 *//*  w  w w  .j a  v a 2s .co  m*/
protected void collectUsedVars(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> parentUsedVars)
        throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    HashSet<LogicalVariable> usedVarsPerOp = new HashSet<>();
    VariableUtilities.getUsedVariables(op, usedVarsPerOp);
    usedVarsPerOp.addAll(parentUsedVars);

    if (allUsedVarsAfterOpMap.get(op) == null) {
        allUsedVarsAfterOpMap.put(op, usedVarsPerOp);
    } else {
        allUsedVarsAfterOpMap.get(op).addAll(usedVarsPerOp);
    }

    for (Mutable<ILogicalOperator> inputOpRef : op.getInputs()) {
        collectUsedVars(inputOpRef, usedVarsPerOp);
    }

}

From source file:it.cnr.icar.eric.client.xml.registry.infomodel.ClassificationSchemeImpl.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public HashSet getComposedObjects() throws JAXRException {
    HashSet composedObjects = super.getComposedObjects();
    composedObjects.addAll(getChildrenConcepts());

    return composedObjects;
}

From source file:org.mariotaku.twidere.fragment.support.AddStatusFilterDialogFragment.java

private FilterItemInfo[] getFilterItemsInfo() {
    final Bundle args = getArguments();
    if (args == null || !args.containsKey(EXTRA_STATUS))
        return new FilterItemInfo[0];
    final ParcelableStatus status = args.getParcelable(EXTRA_STATUS);
    final ArrayList<FilterItemInfo> list = new ArrayList<>();
    if (status.is_retweet) {
        list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, new UserItem(status.retweeted_by_user_id,
                status.retweeted_by_user_name, status.retweeted_by_user_screen_name)));
    }/* www .  j av  a  2  s. co m*/
    if (status.is_quote) {
        list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, new UserItem(status.quoted_by_user_id,
                status.quoted_by_user_name, status.quoted_by_user_screen_name)));
    }
    list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER,
            new UserItem(status.user_id, status.user_name, status.user_screen_name)));
    final ParcelableUserMention[] mentions = status.mentions;
    if (mentions != null) {
        for (final ParcelableUserMention mention : mentions) {
            if (mention.id != status.user_id) {
                list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, mention));
            }
        }
    }
    final HashSet<String> hashtags = new HashSet<>();
    hashtags.addAll(mExtractor.extractHashtags(status.text_plain));
    for (final String hashtag : hashtags) {
        list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_KEYWORD, hashtag));
    }
    final String source = HtmlEscapeHelper.toPlainText(status.source);
    list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_SOURCE, source));
    return list.toArray(new FilterItemInfo[list.size()]);
}

From source file:com.digitalbuana.smiles.ui.ContactAdd.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    String account = AccountManager.getInstance().getAccountKu();
    if (account == null) {
        onNothingSelected(parent);/*from w  w w . j  av a  2s . com*/
    } else {
        HashSet<String> groups = new HashSet<String>(RosterManager.getInstance().getGroups(account));
        groups.addAll(getSelected());
        setGroups(groups, getSelected());
    }
}

From source file:och.service.props.impl.MultiProps.java

public void resetSources(Props... sources) {

    HashSet<String> keys = new HashSet<>();

    //remove old/*from   w ww  .  j av a2  s. co  m*/
    for (Props old : list) {
        keys.addAll(old.toMap().keySet());
    }
    list.clear();

    //add new
    for (Props source : sources) {
        addSource(source);
        keys.addAll(source.toMap().keySet());
    }

    fireChangedEvent(keys);
}

From source file:com.mousefeed.eclipse.GlobalSelectionListener.java

/**
 * Checks if for the current action a keyboard shortcut can be configured.
 * //from w w  w.  ja va 2s. co m
 * @param actionDesc ActionDesc for the current action. Not null.
 * @return true, if the current action has at least one ParameterizedCommand
 * (only those are listed in the keys preference page), false else.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected boolean isConfigurableAction(final AbstractActionDesc actionDesc) {
    final String actionId = actionDesc.getId();

    final Command command = commandService.getCommand(actionId);
    if (command != null) {
        final HashSet allParameterizedCommands = new HashSet();
        try {
            allParameterizedCommands.addAll(ParameterizedCommand.generateCombinations(command));
        } catch (final NotDefinedException e) {
            // It is safe to just ignore undefined commands.
        }
        return !allParameterizedCommands.isEmpty();
    }
    return false;
}

From source file:jsentvar.SubstitutionTest.java

/**
 * Test of oneTerm method, of class Substitution.
 */// www  .j av a2s  .  c  om
@Test
public void testOneTerm() throws IOException {
    System.out.println("Substitution.oneTerm() Test");
    RDFReader lector = new RDFReader();
    String filename;
    //filename = "resources/test/miniReasoner.owl";
    filename = "resources/IEEE_reasoner20022016.owl";
    Model model;
    //String term_value = term_value0.substring(0, 1).toUpperCase() +term_value0.substring(1);

    model = lector.reader(filename);

    //Read positions, a json file
    String possFile = "resources/test/text_doc0.json";
    JsonReader jreader = new JsonReader();
    HashMap<String, HashMap<Integer, Integer>> poss = jreader.reader(possFile);
    /*
    try {
    System.out.println(poss.toString());
    } catch (NullPointerException e) {
    System.out.println("ERROR showing results " + e);
    }
    */
    ArrayList<String> terms1 = new ArrayList<>();

    Set originS = poss.keySet();
    terms1.addAll(originS);

    //Get all the terms for substitution
    /*
    ArrayList<String> terms0 = new ArrayList<>();
            terms0.add("military satellites");
            terms0.add("intelligent_systems");
    */
    Surrogate sur = new Surrogate(model);
    HashMap<String, ArrayList<String>> alternatives;
    Utils utils = new Utils();
    ArrayList<String> terms = utils.firstUpperForeach(terms1);
    alternatives = sur.surrogatesForeach(terms);
    //System.out.println(alternatives.toString());

    String docFile = "resources/test/tex_doc0.txt";
    String doc = FileUtils.readFileToString(new File(docFile), "utf8");
    Substitution gen = new Substitution();
    HashSet newDocs = new HashSet();
    for (String term : terms) {
        System.out.println(term);
        HashSet newDocs0 = gen.oneTerm(doc, term, alternatives.get(term));
        newDocs.addAll(newDocs0);
    }

    String expResult = FileUtils.readFileToString(new File("resources/test/substitutionOneTermResult.txt"),
            "utf8");
    assertEquals(expResult, newDocs.toString());

}

From source file:org.apache.hyracks.algebricks.rewriter.rules.IntroduceProjectsRule.java

protected boolean introduceProjects(AbstractLogicalOperator parentOp, int parentInputIndex,
        Mutable<ILogicalOperator> opRef, Set<LogicalVariable> parentUsedVars, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    boolean modified = false;

    usedVars.clear();/* www .  ja v  a2  s . c o  m*/
    VariableUtilities.getUsedVariables(op, usedVars);

    // In the top-down pass, maintain a set of variables that are used in op and all its parents.
    // This is a necessary step for the newly created project operator during this optimization,
    // since we already have all information from collectUsedVars() method for the other operators.
    HashSet<LogicalVariable> parentsUsedVars = new HashSet<>();
    parentsUsedVars.addAll(parentUsedVars);
    parentsUsedVars.addAll(usedVars);

    if (allUsedVarsAfterOpMap.get(op) != null) {
        parentsUsedVars.addAll(allUsedVarsAfterOpMap.get(op));
    }

    // Descend into children.
    for (int i = 0; i < op.getInputs().size(); i++) {
        Mutable<ILogicalOperator> inputOpRef = op.getInputs().get(i);
        if (introduceProjects(op, i, inputOpRef, parentsUsedVars, context)) {
            modified = true;
        }
    }

    if (modified) {
        context.computeAndSetTypeEnvironmentForOperator(op);
    }
    // In the bottom-up pass, determine which live variables are not used by op's parents.
    // Such variables are be projected away.
    liveVars.clear();
    VariableUtilities.getLiveVariables(op, liveVars);
    producedVars.clear();
    VariableUtilities.getProducedVariables(op, producedVars);
    liveVars.removeAll(producedVars);

    projectVars.clear();
    for (LogicalVariable liveVar : liveVars) {
        if (parentsUsedVars.contains(liveVar)) {
            projectVars.add(liveVar);
        }
    }

    // Some of the variables that are live at this op are not used above.
    if (projectVars.size() != liveVars.size()) {
        // Add a project operator under each of op's qualifying input branches.
        for (int i = 0; i < op.getInputs().size(); i++) {
            ILogicalOperator childOp = op.getInputs().get(i).getValue();
            liveVars.clear();
            VariableUtilities.getLiveVariables(childOp, liveVars);
            List<LogicalVariable> vars = new ArrayList<>();
            vars.addAll(projectVars);
            // Only retain those variables that are live in the i-th input branch.
            vars.retainAll(liveVars);
            if (vars.size() != liveVars.size()) {
                ProjectOperator projectOp = new ProjectOperator(vars);
                projectOp.getInputs().add(new MutableObject<ILogicalOperator>(childOp));
                op.getInputs().get(i).setValue(projectOp);
                context.computeAndSetTypeEnvironmentForOperator(projectOp);
                modified = true;
            }
        }
    } else if (op.getOperatorTag() == LogicalOperatorTag.PROJECT) {
        // Check if the existing project has become useless.
        liveVars.clear();
        VariableUtilities.getLiveVariables(op.getInputs().get(0).getValue(), liveVars);
        ProjectOperator projectOp = (ProjectOperator) op;
        List<LogicalVariable> projectVarsTemp = projectOp.getVariables();
        if (liveVars.size() == projectVarsTemp.size() && liveVars.containsAll(projectVarsTemp)) {
            boolean eliminateProject = true;
            // For UnionAll the variables must also be in exactly the correct order.
            if (parentOp.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
                eliminateProject = canEliminateProjectBelowUnion((UnionAllOperator) parentOp, projectOp,
                        parentInputIndex);
            }
            if (eliminateProject) {
                // The existing project has become useless. Remove it.
                parentOp.getInputs().get(parentInputIndex).setValue(op.getInputs().get(0).getValue());
            }
        }
    }

    if (modified) {
        context.computeAndSetTypeEnvironmentForOperator(op);
    }
    return modified;
}