Example usage for java.util Set removeAll

List of usage examples for java.util Set removeAll

Introduction

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

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this set all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:com.ignorelist.kassandra.steam.scraper.Tagger.java

private void addTags(SharedConfig sharedConfig, Long gameId, Options taggerOptions, Set<String> externalTags) {
    Set<String> existingTags = sharedConfig.getTags(gameId);

    if (null != taggerOptions.getWhiteList() && !taggerOptions.getWhiteList().isEmpty()) {
        externalTags.retainAll(taggerOptions.getWhiteList());
    }//from  w w w. jav a2s . c  om

    existingTags.addAll(externalTags);

    if (null != taggerOptions.getReplacementMap()) {
        for (Map.Entry<String, String> e : taggerOptions.getReplacementMap().entrySet()) {
            if (existingTags.remove(e.getKey())) {
                existingTags.add(e.getValue());
            }
        }
    }

    if (null != taggerOptions.getRemoveTags()) {
        existingTags.removeAll(taggerOptions.getRemoveTags());
    }
    if (null != taggerOptions.getWhiteList() && !taggerOptions.getWhiteList().isEmpty()
            && taggerOptions.isRemoveNotWhiteListed()) {
        existingTags.retainAll(taggerOptions.getWhiteList());
    }

    sharedConfig.setTags(gameId, existingTags);
}

From source file:com.connexta.arbitro.ctx.xacml3.XACML3EvaluationCtx.java

/**
 * Process multiple attributes with same category
 * /*from   ww w.j  a  va 2 s .  c o m*/
 * @param evaluationCtx <code>XACML3EvaluationCtx</code>
 * @return <code>MultipleCtxResult</code>
 */
private MultipleCtxResult processMultipleAttributes(XACML3EvaluationCtx evaluationCtx) {

    Set<EvaluationCtx> children = new HashSet<EvaluationCtx>();

    Map<String, List<Attributes>> mapAttributes = evaluationCtx.getMapAttributes();

    Set<Set<Attributes>> tempRequestAttributes = new HashSet<Set<Attributes>>(
            Arrays.asList(evaluationCtx.getAttributesSet()));

    for (Map.Entry<String, List<Attributes>> mapAttributesEntry : mapAttributes.entrySet()) {
        if (mapAttributesEntry.getValue().size() > 1) {
            Set<Set<Attributes>> temp = new HashSet<Set<Attributes>>();
            for (Attributes attributesElement : mapAttributesEntry.getValue()) {
                for (Set<Attributes> tempRequestAttribute : tempRequestAttributes) {
                    Set<Attributes> newSet = new HashSet<Attributes>(tempRequestAttribute);
                    newSet.removeAll(mapAttributesEntry.getValue());
                    newSet.add(attributesElement);
                    temp.add(newSet);
                }
            }
            tempRequestAttributes = temp;
        }
    }

    for (Set<Attributes> ctx : tempRequestAttributes) {
        RequestCtx requestCtx = new RequestCtx(ctx, null);
        children.add(new XACML3EvaluationCtx(requestCtx, pdpConfig));
    }

    return new MultipleCtxResult(children);
}

From source file:com.genentech.application.calcProps.SDFCalcProps.java

/**
 * Consolidate calculators with the same aggregation id into one calculator
 * with the given aggregation id as calculator name.
 * //from www.  ja  va 2  s.c om
 * The new calculator contains the combined progOptions, requiredCalculators,
 * keepRequiredCalculators, outputFields, and verboseFields. The list of the 
 * original calculators are kept in the 
 * 
 * @param oldCalcSet
 *          The calculator set containing calculators with aggregation IDs
 * @return the consolidated calculator set in which the calculators with the 
 *          same aggregation ID are replaced by the corresponding aggregation 
 *          calculator. The requiredCalculators and keepRequiredCalculators
 *          lists in calculators containing the names of calculators with a
 *          aggregation ID are replaced with the name of their respective 
 *          aggregation calculators
 */
private static Set<Calculator> consolidateByAggregationId(Set<Calculator> oldCalcSet) {
    //Resulting calculator list after the aggregation
    Set<Calculator> newCalcSet = new LinkedHashSet<Calculator>();

    //List of calculators replacing the calculators with aggregation ID
    Map<String, Calculator> aggCalcMap = new HashMap<String, Calculator>();

    for (Calculator oldCalc : oldCalcSet) {
        String oldAggId = oldCalc.getProgAggregateID();
        String oldCalcName = oldCalc.getName();

        if (oldAggId == null || oldAggId.length() == 0) {
            newCalcSet.add(oldCalc);
            continue;
        }

        Calculator aggCalc = aggCalcMap.get(oldAggId);
        if (aggCalc == null) {
            oldCalc.setName("AggCalc_" + oldAggId);
            oldCalc.addOriginalCalculator(oldCalcName);
            oldCalc.setHelpText("Aggregation of " + oldCalcName);
            newCalcSet.add(oldCalc);
            aggCalcMap.put(oldAggId, oldCalc);

        } else {
            if (!aggCalc.getProgName().equalsIgnoreCase(oldCalc.getProgName())) {
                throw new Error("Expect program name \"" + aggCalc.getProgName()
                        + "\" for calculators with aggregation Id \"" + oldAggId + " but " + oldCalcName
                        + " has the program name " + oldCalc.getProgName() + "\".");
            }
            aggCalc.addOriginalCalculator(oldCalcName);
            aggCalc.setHelpText(aggCalc.getHelpText() + ", " + oldCalcName);
            aggCalc.setProgOps(aggCalc.getProgOps() + " " + oldCalc.getProgOps());

            aggCalc.addRequiredCalculators(oldCalc.getRequiredCalculators());
            aggCalc.addKeepRequiredCalculators(oldCalc.getKeepRequiredCalculators());

            aggCalc.addOutputFields(oldCalc.getOutputFields());
            aggCalc.addVerboseFields(oldCalc.getVerboseFields());
        }
    }

    /*
     * For all calculators in newCalcSet, replace the calculator names in 
     * requiredCalculators and keepRequiredCalculatorsn lists with the names 
     * of the corresponding aggregation calculators
     */
    for (Calculator newCalc : newCalcSet) {
        Set<String> newReqCalcs = newCalc.getRequiredCalculators();
        Set<String> newKeepReqCalcs = newCalc.getKeepRequiredCalculators();

        // Loop over the consolidation calculators
        Iterator<Calculator> aggCalcIterator = aggCalcMap.values().iterator();
        while (aggCalcIterator.hasNext()) {
            Calculator aggCalc = aggCalcIterator.next();
            String newAggCalcName = aggCalc.getName();

            /*
             * Remove the names of the aggregated (original) calculator from the 
             * requiredCalculators and keepRequiredCalculators lists. However,
             * only add the name of the current aggregation calculator newCalc
             * if removeAll() indicates change of lists and newCalc is not referring
             * to the same calculator instance as aggCalc. The latter condition
             * is essential for prevent circular dependencies. For exampled RO5
             * has the same aggregation ID as have some of its required calculators
             */
            if (newReqCalcs.removeAll(aggCalc.getOriginalCalculators())) {
                if (!newCalc.getName().equals(newAggCalcName))
                    newReqCalcs.add(newAggCalcName);
            }
            if (newKeepReqCalcs.removeAll(aggCalc.getOriginalCalculators())) {
                if (!newCalc.getName().equals(newAggCalcName))
                    newKeepReqCalcs.add(newAggCalcName);
            }
        }
    }
    return newCalcSet;
}

From source file:de.clusteval.tools.ClustQualityEval.java

public ClustQualityEval(final String absRepoPath, final String dataConfigName, final String... qualityMeasures)
        throws RepositoryAlreadyExistsException, InvalidRepositoryException, RepositoryConfigNotFoundException,
        RepositoryConfigurationException, UnknownClusteringQualityMeasureException, InterruptedException,
        UnknownDataSetFormatException, UnknownGoldStandardFormatException, GoldStandardNotFoundException,
        GoldStandardConfigurationException, DataSetConfigurationException, DataSetNotFoundException,
        DataSetConfigNotFoundException, GoldStandardConfigNotFoundException, NoDataSetException,
        DataConfigurationException, DataConfigNotFoundException, NumberFormatException, RunResultParseException,
        ConfigurationException, RegisterException, UnknownContextException, UnknownParameterType, IOException,
        UnknownRunResultFormatException, InvalidRunModeException, UnknownParameterOptimizationMethodException,
        NoOptimizableProgramParameterException, UnknownProgramParameterException,
        InvalidConfigurationFileException, NoRepositoryFoundException, InvalidOptimizationParameterException,
        RunException, UnknownDataStatisticException, UnknownProgramTypeException, UnknownRProgramException,
        IncompatibleParameterOptimizationMethodException, UnknownDistanceMeasureException,
        UnknownRunStatisticException, UnknownDataSetTypeException, UnknownRunDataStatisticException,
        UnknownDataPreprocessorException, IncompatibleDataSetConfigPreprocessorException,
        IncompatibleContextException, InvalidDataSetFormatVersionException, RNotAvailableException,
        FormatConversionException {//from  w  ww.j a  v a 2 s. c  o m
    super();
    ClustevalBackendServer.logLevel(Level.INFO);
    ClustevalBackendServer.getBackendServerConfiguration().setNoDatabase(true);
    ClustevalBackendServer.getBackendServerConfiguration().setCheckForRunResults(false);
    this.log = LoggerFactory.getLogger(this.getClass());
    final Repository parent = new Repository(
            new File(absRepoPath).getParentFile().getParentFile().getAbsolutePath(), null);
    parent.initialize();
    this.repo = new RunResultRepository(absRepoPath, parent);
    this.repo.initialize();

    List<ParameterOptimizationResult> result = new ArrayList<ParameterOptimizationResult>();
    final ParameterOptimizationRun run = (ParameterOptimizationRun) ParameterOptimizationResult
            .parseFromRunResultFolder(parent, new File(absRepoPath), result, false, false, false);

    this.dataConfig = this.repo.getStaticObjectWithName(DataConfig.class, dataConfigName);

    final List<ClusteringQualityMeasure> measures = new ArrayList<ClusteringQualityMeasure>();

    if (qualityMeasures.length == 0) {
        log.error("Please add at least one quality measure to the command line arguments.");
        this.repo.terminateSupervisorThread();
        return;
    }
    for (String measureSimpleName : qualityMeasures) {
        measures.add(ClusteringQualityMeasure.parseFromString(this.repo, measureSimpleName));
    }

    Set<Thread> threads = new HashSet<Thread>();
    System.out.println("Program configurations:");
    System.out.println(run.getProgramConfigs());
    for (final ProgramConfig pc : run.getProgramConfigs()) {
        // get the dataset for this program config
        DataSet dsIn = Parser.parseFromFile(DataSet.class,
                new File(FileUtils.buildPath(absRepoPath, "inputs", pc.toString() + "_" + dataConfig.toString(),
                        dataConfig.getDatasetConfig().getDataSet().getMajorName(),
                        dataConfig.getDatasetConfig().getDataSet().getMinorName())));
        // get dataset in standard format
        final DataSet ds = dsIn.preprocessAndConvertTo(run.getContext(),
                run.getContext().getStandardInputFormat(),
                dataConfig.getDatasetConfig().getConversionInputToStandardConfiguration(),
                dataConfig.getDatasetConfig().getConversionStandardToInputConfiguration());

        ds.loadIntoMemory();

        Thread t = new Thread() {

            public void run() {
                try {
                    DataConfig dc = dataConfig.clone();
                    dc.getDatasetConfig().setDataSet(ds);

                    File f = new File(FileUtils.buildPath(repo.getBasePath(), "clusters"));
                    File[] childs = f.listFiles(new FilenameFilter() {

                        /*
                         * (non-Javadoc)
                         * 
                         * @see java.io.FilenameFilter#accept(java.io.File,
                         * java.lang.String)
                         */
                        @Override
                        public boolean accept(File dir, String name) {
                            return name.startsWith(pc.getName() + "_" + dataConfig.getName())
                                    && name.endsWith(".results.conv");
                        }
                    });
                    // printer = new MyProgressPrinter(childs.length, true);
                    ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))
                            .info("Assessing qualities of clusterings ...");

                    final Map<Long, ClusteringQualitySet> qualsMap = new HashMap<Long, ClusteringQualitySet>();

                    for (File clusteringFile : childs) {
                        try {
                            Clustering cl = Clustering
                                    .parseFromFile(repo, clusteringFile.getAbsoluteFile(), true).getSecond();

                            // only recalculate for those, for which the
                            // measure
                            // hasn't
                            // been evaluated
                            List<ClusteringQualityMeasure> toEvaluate = new ArrayList<ClusteringQualityMeasure>(
                                    measures);
                            try {
                                if (cl.getQualities() != null)
                                    toEvaluate.removeAll(cl.getQualities().keySet());
                            } catch (NullPointerException e) {
                                System.out.println(clusteringFile);
                                throw e;
                            }
                            ClusteringQualitySet quals = new ClusteringQualitySet();
                            // evaluate the new quality measures
                            if (!toEvaluate.isEmpty()) {
                                quals.putAll(cl.assessQuality(dc, toEvaluate));
                                System.out.println(quals);

                                // write the new qualities into the
                                // results.qual
                                // file
                                for (ClusteringQualityMeasure m : quals.keySet())
                                    FileUtils.appendStringToFile(
                                            clusteringFile.getAbsolutePath().replaceFirst(".results.conv",
                                                    ".results.qual"),
                                            String.format("%s\t%s", m.toString(), quals.get(m).getValue())
                                                    + "\n");
                            }

                            long iterationNumber = Long.parseLong(clusteringFile.getName()
                                    .replaceFirst(String.format("%s_%s.", pc.toString(), dc.toString()), "")
                                    .replaceFirst(".results.conv", ""));

                            // store all qualities of the clustering in one
                            // set
                            ClusteringQualitySet allQuals = new ClusteringQualitySet();
                            if (cl.getQualities() != null)
                                allQuals.putAll(cl.getQualities());
                            allQuals.putAll(quals);
                            qualsMap.put(iterationNumber, allQuals);

                        } catch (IOException e) {
                            e.printStackTrace();
                        } catch (UnknownGoldStandardFormatException e) {
                            e.printStackTrace();
                        } catch (UnknownDataSetFormatException e) {
                            e.printStackTrace();
                        } catch (InvalidDataSetFormatVersionException e) {
                            e.printStackTrace();
                        }
                    }

                    // update complete quality file
                    // we want to have the same lines conserving the same NT
                    // and
                    // skipped
                    // iterations infos (missing lines), therefore we parse
                    // the
                    // old file
                    // first, iterate over all lines and write the same
                    // lines
                    // but add
                    // the additional infos (if there are any)
                    TextFileParser parser = new TextFileParser(
                            FileUtils.buildPath(repo.getBasePath(), "clusters",
                                    String.format("%s_%s.results.qual.complete", pc.toString(), dc.toString())),
                            new int[0], new int[0],
                            FileUtils.buildPath(repo.getBasePath(), "clusters", String
                                    .format("%s_%s.results.qual.complete.new", pc.toString(), dc.toString())),
                            OUTPUT_MODE.STREAM) {

                        protected List<ClusteringQualityMeasure> measures;

                        /*
                         * (non-Javadoc)
                         * 
                         * @see
                         * utils.parse.TextFileParser#processLine(java.lang.
                         * String[], java.lang.String[])
                         */
                        @Override
                        protected void processLine(String[] key, String[] value) {
                        }

                        /*
                         * (non-Javadoc)
                         * 
                         * @see
                         * utils.parse.TextFileParser#getLineOutput(java
                         * .lang .String[], java.lang.String[])
                         */
                        @Override
                        protected String getLineOutput(String[] key, String[] value) {
                            StringBuffer sb = new StringBuffer();
                            // sb.append(combineColumns(value));
                            sb.append(combineColumns(Arrays.copyOf(value, 2)));

                            if (currentLine == 0) {
                                sb.append(outSplit);
                                sb.append(combineColumns(Arrays.copyOfRange(value, 2, value.length)));
                                measures = new ArrayList<ClusteringQualityMeasure>();
                                for (int i = 2; i < value.length; i++)
                                    try {
                                        measures.add(
                                                ClusteringQualityMeasure.parseFromString(parent, value[i]));
                                    } catch (UnknownClusteringQualityMeasureException e) {
                                        e.printStackTrace();
                                        this.terminate();
                                    }

                                // get measures, which are not in the
                                // complete
                                // file
                                // header
                                if (qualsMap.keySet().iterator().hasNext()) {
                                    Set<ClusteringQualityMeasure> requiredMeasures = qualsMap
                                            .get(qualsMap.keySet().iterator().next()).keySet();
                                    requiredMeasures.removeAll(measures);

                                    for (ClusteringQualityMeasure m : requiredMeasures) {
                                        sb.append(outSplit);
                                        sb.append(m.toString());
                                    }

                                    measures.addAll(requiredMeasures);
                                }
                            } else if (value[0].contains("*")) {
                                // do nothing
                            } else {
                                long iterationNumber = Long.parseLong(value[0]);
                                ClusteringQualitySet quals = qualsMap.get(iterationNumber);

                                boolean notTerminated = value[3].equals("NT");

                                // for (int i = value.length - 2; i <
                                // measures
                                // .size(); i++) {
                                // sb.append(outSplit);
                                // if (notTerminated)
                                // sb.append("NT");
                                // else
                                // sb.append(quals.get(measures.get(i)));
                                // }
                                for (int i = 0; i < measures.size(); i++) {
                                    sb.append(outSplit);
                                    if (notTerminated)
                                        sb.append("NT");
                                    else if (quals.containsKey(measures.get(i)))
                                        sb.append(quals.get(measures.get(i)));
                                    else
                                        sb.append(value[i + 2]);
                                }
                            }

                            sb.append(System.getProperty("line.separator"));
                            return sb.toString();
                        }
                    };
                    try {
                        parser.process();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    ds.unloadFromMemory();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        threads.add(t);
        t.start();
    }
    // add the new clustering quality measures into the run config file
    TextFileParser p = new TextFileParser(run.getAbsolutePath(), null, null, false, "",
            run.getAbsolutePath() + ".new", OUTPUT_MODE.STREAM) {

        /*
         * (non-Javadoc)
         * 
         * @see utils.parse.TextFileParser#processLine(java.lang.String[],
         * java.lang.String[])
         */
        @Override
        protected void processLine(String[] key, String[] value) {
        }

        /*
         * (non-Javadoc)
         * 
         * @see utils.parse.TextFileParser#getLineOutput(java.lang.String[],
         * java.lang.String[])
         */
        @Override
        protected String getLineOutput(String[] key, String[] value) {
            StringBuilder sb = new StringBuilder();
            sb.append(value[0]);
            if (value[0].contains("qualityMeasures = "))
                for (ClusteringQualityMeasure m : measures)
                    if (!value[0].contains(m.toString())) {
                        sb.append(",");
                        sb.append(m.toString());
                    }

            sb.append(System.getProperty("line.separator"));
            return sb.toString();
        }
    }.process();
    for (Thread t : threads)
        t.join();
    System.exit(0);
}

From source file:com.concursive.connect.web.modules.lists.portlets.AddProjectToListPortlet.java

/**
 * Inserts the project to boomark in new listItem (task) records, a record is created for each of the
 * listIds (taskCategoryIds) specified.//from  w  w w .  j  a  v a2 s.co  m
 * <p/>
 * Returns boolean on whether the operation was successful. Once one failure occurs the method returns
 * false without further processing.
 *
 * @param db                    - the database connection
 * @param existingTasks         - the list of tasks already persisted
 * @param listIds               - this list of listIds that will have the projectIdToBookmark saved
 * @param userId                - the id of the user inserting the records
 * @param projectIdToBookmark   - the id of the project that is being bookmarked
 * @param projectNameToBookmark - the name that will saved for the bookmark (task)
 * @param projectIdOfLists      - the id of the project that owns the lists
 * @param request               - the request
 * @return boolean on whether the operation was successful
 * @throws SQLException - generated trying to retrieve data
 */
private boolean saveToLists(Connection db, TaskList existingTasks, Collection<Integer> listIds, int userId,
        int projectIdToBookmark, String projectNameToBookmark, int projectIdOfLists, ActionRequest request)
        throws SQLException {
    Set<Integer> existingIds = new HashSet<Integer>(existingTasks.size());
    Set<Integer> createForTaskCategoryIds = new HashSet<Integer>(listIds);
    for (Task task : existingTasks) {
        existingIds.add(task.getCategoryId());
    }
    // find all the task category ids that do not already have tasks (these will have tasks inserted)
    createForTaskCategoryIds.removeAll(existingIds);
    if (!createForTaskCategoryIds.isEmpty()) {
        boolean recordInserted = false;
        LookupList priorityList = CacheUtils.getLookupList("lookup_task_priority");
        if (priorityList.isEmpty())
            throw new RuntimeException("Could not load task priorities");
        // just default to the top priority
        int priorityId = priorityList.get(0).getId();
        for (LookupElement priority : priorityList) {
            if (priority.getDefaultItem()) {
                priorityList.get(0).getId();
                break;
            }
        }

        //Parameters
        TaskList taskList = new TaskList();
        for (Integer taskCategoryId : createForTaskCategoryIds) {

            Task task = new Task();
            task.setEnteredBy(userId);
            task.setOwner(userId);
            task.setDescription(projectNameToBookmark);
            task.setModifiedBy(userId);
            task.setProjectId(projectIdOfLists);
            task.setLinkModuleId(Constants.TASK_CATEGORY_PROJECTS);
            task.setLinkItemId(projectIdToBookmark);
            task.setCategoryId(taskCategoryId);
            task.setPriority(priorityId);
            // Verify the specified category is in the same project
            TaskCategoryList list = new TaskCategoryList();
            list.setProjectId(projectIdOfLists);
            list.setCategoryId(taskCategoryId);
            list.buildList(db);
            if (list.size() == 0) {
                return false;
            }
            recordInserted = task.insert(db);
            if (!recordInserted) {
                request.getPortletSession().setAttribute("task", task);
                return false;
            }
            taskList.add(task);
        }

        //Trigger the workflow
        PortalUtils.processInsertHook(request, taskList);

        return recordInserted;
    } else {
        return true; //no inserts needed
    }
}

From source file:io.pivotal.cla.service.github.MylynGitHubApi.java

public ContributingUrlsResponse getContributingUrls(List<String> repositoryIds) {
    Set<String> remainingRepositoryIds = new LinkedHashSet<>(repositoryIds);

    Map<String, String> mdUrls = createEditLinks(remainingRepositoryIds,
            String.format("%s.md", CONTRIBUTING_FILE));
    remainingRepositoryIds.removeAll(mdUrls.keySet());
    Map<String, String> adocUrls = createEditLinks(remainingRepositoryIds,
            String.format("%s.adoc", CONTRIBUTING_FILE));
    remainingRepositoryIds.removeAll(adocUrls.keySet());
    List<String> newUrls = createNewLinks(remainingRepositoryIds, String.format("%s.adoc", CONTRIBUTING_FILE));

    ContributingUrlsResponse response = new ContributingUrlsResponse();
    response.setMarkdown(new ArrayList<>(mdUrls.values()));
    response.setAsciidoc(new ArrayList<>(adocUrls.values()));
    response.getAsciidoc().addAll(newUrls);

    return response;
}

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

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue();
    if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }/*w ww.j ava2s  .c  o m*/
    SubplanOperator subplan = (SubplanOperator) op0;

    Iterator<ILogicalPlan> plansIter = subplan.getNestedPlans().iterator();
    ILogicalPlan p = null;
    while (plansIter.hasNext()) {
        p = plansIter.next();
    }
    if (p == null) {
        return false;
    }
    if (p.getRoots().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> subplanRoot = p.getRoots().get(0);
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) subplanRoot.getValue();

    Mutable<ILogicalOperator> botRef = subplanRoot;
    AbstractLogicalOperator op2;
    // Project is optional
    if (op1.getOperatorTag() != LogicalOperatorTag.PROJECT) {
        op2 = op1;
    } else {
        ProjectOperator project = (ProjectOperator) op1;
        botRef = project.getInputs().get(0);
        op2 = (AbstractLogicalOperator) botRef.getValue();
    }
    if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    AggregateOperator aggregate = (AggregateOperator) op2;

    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    VariableUtilities.getUsedVariables(aggregate, free);

    Mutable<ILogicalOperator> op3Ref = aggregate.getInputs().get(0);
    AbstractLogicalOperator op3 = (AbstractLogicalOperator) op3Ref.getValue();

    while (op3.getInputs().size() == 1) {
        Set<LogicalVariable> prod = new HashSet<LogicalVariable>();
        VariableUtilities.getProducedVariables(op3, prod);
        free.removeAll(prod);
        VariableUtilities.getUsedVariables(op3, free);
        botRef = op3Ref;
        op3Ref = op3.getInputs().get(0);
        op3 = (AbstractLogicalOperator) op3Ref.getValue();
    }

    if (op3.getOperatorTag() != LogicalOperatorTag.INNERJOIN
            && op3.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
        return false;
    }
    AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op3;
    if (join.getCondition().getValue() == ConstantExpression.TRUE) {
        return false;
    }
    VariableUtilities.getUsedVariables(join, free);

    AbstractLogicalOperator b0 = (AbstractLogicalOperator) join.getInputs().get(0).getValue();
    // see if there's an NTS at the end of the pipeline
    NestedTupleSourceOperator outerNts = getNts(b0);
    if (outerNts == null) {
        AbstractLogicalOperator b1 = (AbstractLogicalOperator) join.getInputs().get(1).getValue();
        outerNts = getNts(b1);
        if (outerNts == null) {
            return false;
        }
    }

    Set<LogicalVariable> pkVars = computeGbyVars(outerNts, free, context);
    if (pkVars == null || pkVars.size() < 1) {
        // there is no non-trivial primary key, group-by keys are all live variables
        ILogicalOperator subplanInput = subplan.getInputs().get(0).getValue();
        pkVars = new HashSet<LogicalVariable>();
        VariableUtilities.getLiveVariables(subplanInput, pkVars);
    }
    AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Found FD for introducing group-by: " + pkVars);

    Mutable<ILogicalOperator> rightRef = join.getInputs().get(1);
    LogicalVariable testForNull = null;
    AbstractLogicalOperator right = (AbstractLogicalOperator) rightRef.getValue();
    switch (right.getOperatorTag()) {
    case UNNEST: {
        UnnestOperator innerUnnest = (UnnestOperator) right;
        // Select [ $y != null ]
        testForNull = innerUnnest.getVariable();
        break;
    }
    case RUNNINGAGGREGATE: {
        ILogicalOperator inputToRunningAggregate = right.getInputs().get(0).getValue();
        Set<LogicalVariable> producedVars = new ListSet<LogicalVariable>();
        VariableUtilities.getProducedVariables(inputToRunningAggregate, producedVars);
        if (!producedVars.isEmpty()) {
            // Select [ $y != null ]
            testForNull = producedVars.iterator().next();
        }
        break;
    }
    case DATASOURCESCAN: {
        DataSourceScanOperator innerScan = (DataSourceScanOperator) right;
        // Select [ $y != null ]
        if (innerScan.getVariables().size() == 1) {
            testForNull = innerScan.getVariables().get(0);
        }
        break;
    }
    }
    if (testForNull == null) {
        testForNull = context.newVar();
        AssignOperator tmpAsgn = new AssignOperator(testForNull,
                new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
        tmpAsgn.getInputs().add(new MutableObject<ILogicalOperator>(rightRef.getValue()));
        rightRef.setValue(tmpAsgn);
        context.computeAndSetTypeEnvironmentForOperator(tmpAsgn);
    }

    IFunctionInfo finfoEq = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.IS_NULL);
    ILogicalExpression isNullTest = new ScalarFunctionCallExpression(finfoEq,
            new MutableObject<ILogicalExpression>(new VariableReferenceExpression(testForNull)));
    IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
    ScalarFunctionCallExpression nonNullTest = new ScalarFunctionCallExpression(finfoNot,
            new MutableObject<ILogicalExpression>(isNullTest));
    SelectOperator selectNonNull = new SelectOperator(new MutableObject<ILogicalExpression>(nonNullTest), false,
            null);
    GroupByOperator g = new GroupByOperator();
    Mutable<ILogicalOperator> newSubplanRef = new MutableObject<ILogicalOperator>(subplan);
    NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(g));
    opRef.setValue(g);
    selectNonNull.getInputs().add(new MutableObject<ILogicalOperator>(nts));

    List<Mutable<ILogicalOperator>> prodInpList = botRef.getValue().getInputs();
    prodInpList.clear();
    prodInpList.add(new MutableObject<ILogicalOperator>(selectNonNull));

    ILogicalPlan gPlan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(subplanRoot.getValue()));
    g.getNestedPlans().add(gPlan);
    subplanRoot.setValue(op3Ref.getValue());
    g.getInputs().add(newSubplanRef);

    HashSet<LogicalVariable> underVars = new HashSet<LogicalVariable>();
    VariableUtilities.getLiveVariables(subplan.getInputs().get(0).getValue(), underVars);
    underVars.removeAll(pkVars);
    Map<LogicalVariable, LogicalVariable> mappedVars = buildVarExprList(pkVars, context, g, g.getGroupByList());
    context.updatePrimaryKeys(mappedVars);
    for (LogicalVariable uv : underVars) {
        g.getDecorList().add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(null,
                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(uv))));
    }
    OperatorPropertiesUtil.typeOpRec(subplanRoot, context);
    OperatorPropertiesUtil.typeOpRec(gPlan.getRoots().get(0), context);
    context.computeAndSetTypeEnvironmentForOperator(g);
    return true;
}

From source file:com.dragome.compiler.units.ClassUnit.java

private Set<MemberUnit> getNotImplementedMethods() {
    Set<MemberUnit> interfacesMembers = new HashSet<MemberUnit>();
    getDeclaredMembersInInterfaces(this, interfacesMembers);

    Set<MemberUnit> implementedMembers = new HashSet<MemberUnit>();
    getImplementedMembersInHierarchy(this, implementedMembers);

    interfacesMembers.removeAll(implementedMembers);
    if (isImplementing(InvocationHandler.class) || isAbstract || isInterface || interfacesMembers.size() <= 0
            || interfacesMembers.isEmpty())
        interfacesMembers.clear();/*from   ww w  . ja  v a  2s.c  om*/

    return interfacesMembers;
}

From source file:com.ms.commons.udas.impl.commons.MemcachedKeyStore.java

/**
 * KeyMemcached/*from w  ww .ja v  a2s.c  o  m*/
 */
public void flushKey() {
    logger.debug("---------- ??Key?Memached...");
    // long t1 = System.currentTimeMillis();
    Set<String> allStoedKey = getAllStoredKey();// ??Key
    // long t2 = System.currentTimeMillis();
    // logger.warn(nameSpace + "flushKey: getAllStoredKey() " + (t2 - t1));
    if (logger.isDebugEnabled()) {
        logger.warn(" Key?,?: " + getIndexSize());
        logger.warn(" ??Key: " + allStoedKey.size());
        logger.warn(" ?key: " + keyToAdd.size());
        logger.warn(" ?key: " + keyToDel.size());
    }

    allStoedKey.removeAll(keyToDel);
    allStoedKey.addAll(keyToAdd);

    // long t3 = System.currentTimeMillis();
    // 
    restoreToRemote(allStoedKey);
    // long t4 = System.currentTimeMillis();
    // logger.warn(nameSpace + "flushKey: restoreToRemote() " + (t4 - t3));
    // 
    keyToAdd.clear();
    keyToDel.clear();

    if (logger.isDebugEnabled()) {
        logger.debug(
                "-------??Key???: "
                        + getIndexSize() + ",Key: " + getAllStoredKey().size());
    }
}

From source file:org.syncope.core.rest.controller.UserController.java

@PreAuthorize("hasRole('USER_CREATE')")
@RequestMapping(method = RequestMethod.POST, value = "/create")
public UserTO create(final HttpServletResponse response, @RequestBody final UserTO userTO)
        throws PropagationException, UnauthorizedRoleException, WorkflowException, NotFoundException {

    LOG.debug("User create called with {}", userTO);

    Set<Long> requestRoleIds = new HashSet<Long>(userTO.getMemberships().size());
    for (MembershipTO membership : userTO.getMemberships()) {
        requestRoleIds.add(membership.getRoleId());
    }/*w  ww .  j  a  va  2s.  c om*/
    Set<Long> adminRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
    requestRoleIds.removeAll(adminRoleIds);
    if (!requestRoleIds.isEmpty()) {
        throw new UnauthorizedRoleException(requestRoleIds);
    }

    WorkflowResult<Map.Entry<Long, Boolean>> created = wfAdapter.create(userTO);

    List<PropagationTask> tasks = propagationManager.getCreateTaskIds(created, userTO.getPassword(),
            userTO.getVirtualAttributes());

    final List<PropagationTO> propagations = new ArrayList<PropagationTO>();

    propagationManager.execute(tasks, new PropagationHandler() {

        @Override
        public void handle(final String resourceName, final PropagationTaskExecStatus executionStatus,
                final ConnectorObject before, final ConnectorObject after) {

            final PropagationTO propagation = new PropagationTO();
            propagation.setResourceName(resourceName);
            propagation.setStatus(executionStatus);

            if (before != null) {
                propagation.setBefore(connInstanceDataBinder.getConnObjectTO(before));
            }

            if (after != null) {
                propagation.setAfter(connInstanceDataBinder.getConnObjectTO(after));
            }

            propagations.add(propagation);
        }
    });

    notificationManager.createTasks(new WorkflowResult<Long>(created.getResult().getKey(),
            created.getPropByRes(), created.getPerformedTasks()));

    final UserTO savedTO = userDataBinder.getUserTO(created.getResult().getKey());

    savedTO.setPropagationTOs(propagations);

    LOG.debug("About to return created user\n{}", savedTO);

    response.setStatus(HttpServletResponse.SC_CREATED);
    return savedTO;
}