Example usage for org.apache.commons.collections ListUtils union

List of usage examples for org.apache.commons.collections ListUtils union

Introduction

In this page you can find the example usage for org.apache.commons.collections ListUtils union.

Prototype

public static List union(final List list1, final List list2) 

Source Link

Document

Returns a new list containing the second list appended to the first list.

Usage

From source file:br.ufrj.nce.recureco.distributedindex.search.service.SearchService.java

public List<String> getDocuments(String query, boolean booleanOr) {

    List<String> andWords = lineTokenizer.tokenize(query);

    //if query words list is null, return empty results
    if (andWords == null) {
        return new ArrayList<String>();
    }//from  w w  w  . j  av a 2 s  . com
    //if query words list is  empty, return empty results
    if (andWords.size() == 0) {
        return new ArrayList<String>();
    }

    //if still here, there is something to search
    List<String> results = searchDAO.getDocuments(andWords);

    List<String> documentsResults = new ArrayList<String>();

    boolean firstTime = true;

    for (String docs : results) {

        List<String> auxList = new ArrayList<String>();
        CollectionUtils.addAll(auxList, docs.split(","));

        if (booleanOr) {
            documentsResults = ListUtils.sum(documentsResults, auxList);
        } else {
            if (firstTime) {
                documentsResults = ListUtils.union(documentsResults, auxList);
                firstTime = false;
            } else {
                documentsResults = ListUtils.intersection(documentsResults, auxList);
            }
        }
    }

    return documentsResults;
}

From source file:gobblin.data.management.retention.TimeBasedRetentionPolicyTest.java

private void verify(String duration, List<TimestampedDatasetVersion> toBeDeleted,
        List<TimestampedDatasetVersion> toBeRetained) {

    @SuppressWarnings("unchecked")
    List<TimestampedDatasetVersion> allVersions = ListUtils.union(toBeRetained, toBeDeleted);

    List<TimestampedDatasetVersion> deletableVersions = Lists
            .newArrayList(new TimeBasedRetentionPolicy(duration).listDeletableVersions(allVersions));

    assertThat(deletableVersions, Matchers.containsInAnyOrder(toBeDeleted.toArray()));
    assertThat(deletableVersions, Matchers.not(Matchers.containsInAnyOrder(toBeRetained.toArray())));

}

From source file:com.vmware.upgrade.progress.DefaultExecutionStateAggregatorTest.java

@SuppressWarnings("unchecked")
@DataProvider(name = DEPTH_TWO_PROVIDER)
public Object[][] generateAllDepthTwoTransitions() {
    return mapToObjectArray(ListUtils.union(
            ListUtils.union(computeDepthTwoPairWithStableTransitionStates(),
                    computeDepthTwoPairWithoutStableTransitionStates()),
            computeDepthTwoTripleTransitionStates()));
}

From source file:com.eryansky.modules.sys.service.OrganManager.java

/**
 * ?./*from w w w. j a  va2  s.c  om*/
 * <br/>?? ??
 * @param entity 
 * @throws com.eryansky.common.exception.DaoException
 * @throws com.eryansky.common.exception.SystemException
 * @throws com.eryansky.common.exception.ServiceException
 */
public void saveOrgan(Organ entity) throws DaoException, SystemException, ServiceException {
    Assert.notNull(entity, "?[entity]!");
    this.saveEntity(entity);
    if (entity.getType() != null && OrganType.department.getValue().equals(entity.getType())) {
        List<Organ> subOrgans = entity.getSubOrgans();
        while (!Collections3.isEmpty(subOrgans)) {
            Iterator<Organ> iterator = subOrgans.iterator();
            while (iterator.hasNext()) {
                Organ subOrgan = iterator.next();
                subOrgan.setType(OrganType.department.getValue());
                iterator.remove();
                subOrgans = ListUtils.union(subOrgans, subOrgan.getSubOrgans());
                super.update(subOrgan);
            }
        }
    }
}

From source file:com.strider.datadefender.FileDiscoverer.java

@SuppressWarnings("unchecked")
public List<FileMatchMetaData> discover(final Properties fileDiscoveryProperties)
        throws FileDiscoveryException, DatabaseDiscoveryException, IOException, SAXException, TikaException {
    log.info("Data discovery in process");

    // Get the probability threshold from property file
    final double probabilityThreshold = parseDouble(
            fileDiscoveryProperties.getProperty("probability_threshold"));

    log.info("Probability threshold [" + probabilityThreshold + "]");

    // Get list of models used in data discovery
    final String models = fileDiscoveryProperties.getProperty("models");

    modelList = models.split(",");
    log.info("Model list [" + Arrays.toString(modelList) + "]");

    List<FileMatchMetaData> finalList = new ArrayList<>();

    for (final String model : modelList) {
        log.info("********************************");
        log.info("Processing model " + model);
        log.info("********************************");

        final Model modelPerson = createModel(fileDiscoveryProperties, model);

        fileMatches = discoverAgainstSingleModel(fileDiscoveryProperties, modelPerson, probabilityThreshold);
        finalList = ListUtils.union(finalList, fileMatches);
    }//from   w w w .ja  v  a  2s .  c  o m

    // Special case
    String[] specialCaseFunctions = null;
    boolean specialCase = false;
    final String extentionList = fileDiscoveryProperties.getProperty("extentions");

    final String directories = fileDiscoveryProperties.getProperty("directories");
    final String exclusions = fileDiscoveryProperties.getProperty("exclusions");
    String exclusionList[] = null;
    if ((exclusions == null) || exclusions.equals("")) {
        log.info("exclusions property is empty in firediscovery.properties file");
    } else {
        exclusionList = exclusions.split(",");
        log.info("File types not considered for analysis: " + exclusions);
    }
    log.info("Directories to analyze: " + directories);

    if ((directories == null) || directories.equals("")) {
        log.error("directories property is empty in firediscovery.properties file");

        throw new DatabaseDiscoveryException("directories property is empty in firediscovery.properties file");
    }

    final String[] directoryList = directories.split(",");
    if (!CommonUtils.isEmptyString(extentionList)) {
        log.info("***** Extension list:" + extentionList);
        specialCaseFunctions = extentionList.split(",");

        if ((specialCaseFunctions != null) && (specialCaseFunctions.length > 0)) {
            log.debug("special case:" + specialCase);
            File node;
            Metadata metadata;

            try {
                log.info("**************" + specialCaseFunctions.toString());
                for (int j = 0; j < specialCaseFunctions.length; j++) {
                    for (final String directory : directoryList) {

                        node = new File(directory);
                        final List<File> files = (List<File>) FileUtils.listFiles(node, null, true);

                        for (final File fich : files) {
                            final String file = fich.getName();
                            final String recursivedir = fich.getParent();

                            log.info("Analyzing [" + fich.getCanonicalPath() + "]");
                            final String ext = CommonUtils.getFileExtension(fich).toLowerCase(Locale.ENGLISH);
                            log.debug("Extension: " + ext);

                            if ((exclusionList != null) && Arrays.asList(exclusionList).contains(ext)) {
                                log.info("Ignoring type " + ext);
                                continue;
                            }

                            final BodyContentHandler handler = new BodyContentHandler(-1);
                            final AutoDetectParser parser = new AutoDetectParser();

                            metadata = new Metadata();

                            String handlerString = "";
                            try {
                                final InputStream stream = new FileInputStream(fich.getCanonicalPath());
                                log.debug("Loading data into the stream");
                                if (stream != null) {
                                    parser.parse(stream, handler, metadata);
                                    handlerString = handler.toString().replaceAll("( )+", " ")
                                            .replaceAll("[\\t\\n\\r]+", " ");

                                    String[] tokens = handlerString.split(" ");

                                    for (int t = 0; t < tokens.length; t++) {
                                        String token = tokens[t];
                                        if (token.trim().length() < 1) {
                                            continue;
                                        }
                                        String specialFunction = specialCaseFunctions[j];
                                        log.info(specialFunction);
                                        FileMatchMetaData returnData = null;
                                        try {
                                            returnData = (FileMatchMetaData) callExtention(
                                                    new FileMatchMetaData(recursivedir, file), specialFunction,
                                                    token);
                                        } catch (InvocationTargetException e) {
                                            continue;
                                        }
                                        if (returnData != null) {
                                            returnData.setModel("sin");
                                            returnData.setAverageProbability(1.0);
                                            List<FileMatchMetaData> specialFileMatches = new ArrayList();
                                            specialFileMatches.add(returnData);

                                            finalList = ListUtils.union(finalList, specialFileMatches);
                                        }
                                        log.debug(tokens[t]);
                                    }

                                }
                            } catch (IOException e) {
                                log.info("Unable to read " + fich.getCanonicalPath() + ".Ignoring...");
                            }
                            log.info("Finish processing " + fich.getCanonicalPath());
                        }
                        log.info("Finish speclai case " + specialCaseFunctions[j]);
                    }
                }
            } catch (IOException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException
                    | SecurityException | SQLException | TikaException | SAXException e) {
                log.error(e.toString());
            }
        }
    }

    final DecimalFormat decimalFormat = new DecimalFormat("#.##");

    log.info("List of suspects:");
    log.info(String.format("%40s %20s %20s %20s", "Directory*", "File*", "Probability*", "Model*"));

    finalList = uniqueList(finalList);

    Collections.sort(finalList, Comparator.comparing(FileMatchMetaData::getFileName));

    for (final FileMatchMetaData data : finalList) {
        String result = "";
        final String probability = decimalFormat.format(data.getAverageProbability());
        result = String.format("%40s %20s %20s %20s", data.getDirectory(), data.getFileName(), probability,
                data.getModel());
        log.info(result);
    }

    return Collections.unmodifiableList(fileMatches);
}

From source file:fitnesse.testsystems.slim.tables.ScriptTableExtensionTest.java

private void assertScriptResults(String scriptStatements, List<List<String>> scriptResults, String table)
        throws Exception {
    buildInstructionsFor(scriptStatements);
    List<List<?>> resultList = ListUtils.union(asList(asList("htmlScriptTable_id_0", "OK")), scriptResults);
    Map<String, Object> pseudoResults = SlimCommandRunningClient.resultToMap(resultList);
    SlimAssertion.evaluateExpectations(assertions, pseudoResults);
    assertEquals(table, HtmlUtil.unescapeWiki(st.getTable().toString()));
}

From source file:fitnesse.testsystems.slim.tables.ScriptTableTest.java

private void assertScriptResults(String scriptStatements, List<List<String>> scriptResults, String table,
        boolean localized) throws Exception {
    buildInstructionsFor(scriptStatements, localized);
    List<List<?>> resultList = ListUtils.union(
            asList(asList(localized ? "localizedScriptTable_id_0" : "scriptTable_id_0", "OK")), scriptResults);
    Map<String, Object> pseudoResults = SlimCommandRunningClient.resultToMap(resultList);
    SlimAssertion.evaluateExpectations(assertions, pseudoResults);
    assertEquals(table, HtmlUtil.unescapeWiki(st.getTable().toString()));
}

From source file:eu.uqasar.web.dashboard.widget.datadeviation.DataDeviationSettingsPanel.java

public DataDeviationSettingsPanel(String id, IModel<DataDeviationWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    // Get the project from the settings
    projectName = getModelObject().getSettings().get("project");

    // DropDown select for Projects
    TreeNodeService treeNodeService = null;
    try {//from   w  w w .ja  va2  s. co  m
        InitialContext ic = new InitialContext();
        treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
        projects = treeNodeService.getAllProjectsOfLoggedInUser();
        if (projects != null && projects.size() != 0) {
            if (projectName == null || projectName.isEmpty()) {
                projectName = projects.get(0).getName();
            }
            project = treeNodeService.getProjectByName(projectName);
            recreateAllProjectTreeChildrenForProject(project);
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }

    //Form and WMCs
    final Form<Widget> form = new Form<>("form");
    wmcGeneral = newWebMarkupContainer("wmcGeneral");
    form.add(wmcGeneral);

    //project
    List<String> joinedQualityParameters = ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX);
    qualityParameterChoice = new DropDownChoice<String>("qualityParams",
            new PropertyModel<String>(this, "qualityParams"), joinedQualityParameters) {
        @Override
        protected void appendOptionHtml(AppendingStringBuffer buffer, String choice, int index,
                String selected) {
            super.appendOptionHtml(buffer, choice, index, selected);
            int noOfObjs = OBJS.size();
            int noOfIndis = INDIS.size();

            if (index + 1 == 1 && noOfObjs > 0) {
                buffer.append("<optgroup label='Quality Objectives'></optgroup>");
            }
            if (index + 1 == noOfObjs && noOfObjs > 0) {
                buffer.append("<optgroup label='Quality Indicators'></optgroup>");
            }
            if (index + 1 == (noOfObjs + noOfIndis) && noOfIndis > 0) {
                buffer.append("<optgroup label='Metrics'></optgroup>");
            }
        }
    };
    qualityParameterChoice.setOutputMarkupId(true);
    wmcGeneral.add(qualityParameterChoice);

    // project
    projectChoice = new DropDownChoice<>("projects", new PropertyModel<Project>(this, "project"), projects);
    projectChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            System.out.println(project);
            recreateAllProjectTreeChildrenForProject(project);
            qualityParameterChoice.setChoices(ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX));
            target.add(qualityParameterChoice);
            target.add(wmcGeneral);

            target.add(form);
        }
    });

    wmcGeneral.setOutputMarkupId(true);
    wmcGeneral.add(projectChoice);

    form.add(new AjaxSubmitLink("submit") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (project != null) {
                getModelObject().getSettings().put("qualityParams", qualityParams);
                getModelObject().getSettings().put("project", project.getName());

                Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
                DbDashboard dbdb = (DbDashboard) dashboard;
                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                DataDeviationWidgetView widgetView = (DataDeviationWidgetView) widgetPanel.getWidgetView();
                target.add(widgetView);
                hideSettingPanel(target);

                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }
    });
    form.add(new AjaxLink<Void>("cancel") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }
    });

    add(form);
}

From source file:eu.uqasar.web.dashboard.widget.uqasardatavisualization.UqasarDataVisualizationSettingsPanel.java

public UqasarDataVisualizationSettingsPanel(String id, IModel<UqasarDataVisualizationWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    //Form and WMCs
    final Form<Widget> form = new Form<>("form");
    wmcGeneral = newWebMarkupContainer("wmcGeneral");
    form.add(wmcGeneral);//from w w w.j a v  a2 s . c om

    // Get the project from the settings
    projectName = getModelObject().getSettings().get("project");

    // DropDown select for Projects
    TreeNodeService treeNodeService = null;
    try {
        InitialContext ic = new InitialContext();
        treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
        projects = treeNodeService.getAllProjectsOfLoggedInUser();
        if (projects != null && projects.size() != 0) {
            if (projectName == null || projectName.isEmpty()) {
                projectName = projects.get(0).getName();
            }
            project = treeNodeService.getProjectByName(projectName);
            recreateAllProjectTreeChildrenForProject(project);
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
    //project
    List<String> joinedQualityParameters = ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX);
    qualityParameterChoice = new DropDownChoice<String>("qualityParams",
            new PropertyModel<String>(this, "qualityParams"), joinedQualityParameters) {
        @Override
        protected void appendOptionHtml(AppendingStringBuffer buffer, String choice, int index,
                String selected) {
            super.appendOptionHtml(buffer, choice, index, selected);

            if (UqasarDataVisualizationWidget.ALL.get(0).equals(choice)) {
                buffer.append("<optgroup label='Quality Objectives'></optgroup>");
            }

            int noOfObjs = OBJS.size();
            int noOfIndis = INDIS.size();

            if (index + 1 == noOfObjs && noOfObjs > 0) {
                buffer.append("<optgroup label='Quality Indicators'></optgroup>");
            }
            if (index + 1 == (noOfObjs + noOfIndis) && noOfIndis > 0) {
                buffer.append("<optgroup label='Metrics'></optgroup>");
            }

        }
    };
    qualityParameterChoice.setOutputMarkupId(true);
    wmcGeneral.add(qualityParameterChoice);

    // project
    projectChoice = new DropDownChoice<>("projects", new PropertyModel<Project>(this, "project"), projects);
    if (project != null) {
        projectChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                System.out.println(project);
                recreateAllProjectTreeChildrenForProject(project);
                qualityParameterChoice.setChoices(ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX));
                target.add(qualityParameterChoice);
                target.add(wmcGeneral);

                target.add(form);
            }
        });

    }

    wmcGeneral.setOutputMarkupId(true);
    wmcGeneral.add(projectChoice);

    form.add(new AjaxSubmitLink("submit") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            if (project != null) {
                getModelObject().getSettings().put("qualityParams", qualityParams);
                getModelObject().getSettings().put("project", project.getName());

                Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
                DbDashboard dbdb = (DbDashboard) dashboard;

                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                UqasarDataVisualizationWidgetView widgetView = (UqasarDataVisualizationWidgetView) widgetPanel
                        .getWidgetView();
                target.add(widgetPanel);
                hideSettingPanel(target);

                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }
    });
    form.add(new AjaxLink<Void>("cancel") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }
    });

    add(form);
}

From source file:com.eryansky.modules.sys.web.DictionaryItemController.java

/**
 * combotree?./*from www . jav a 2  s . c  o m*/
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = { "combotree" })
@ResponseBody
public List<TreeNode> combotree(@ModelAttribute("model") DictionaryItem dictionaryItem, String selectType)
        throws Exception {
    List<TreeNode> titleList = Lists.newArrayList();
    TreeNode selectTreeNode = SelectType.treeNode(selectType);
    if (selectTreeNode != null) {
        titleList.add(selectTreeNode);
    }
    List<TreeNode> treeNodes = dictionaryItemService.getByDictionaryId(dictionaryItem.getDictionaryId(),
            dictionaryItem.getId(), true);

    List<TreeNode> unionList = ListUtils.union(titleList, treeNodes);
    return unionList;
}