List of usage examples for org.apache.commons.collections CollectionUtils subtract
public static Collection subtract(final Collection a, final Collection b)
From source file:org.kuali.rice.kim.document.rule.IdentityManagementGroupDocumentRule.java
protected boolean validGroupMemberPrincipalIDs(List<GroupDocumentMember> groupMembers) { boolean valid = true; List<String> principalIds = new ArrayList<String>(); for (GroupDocumentMember groupMember : groupMembers) { if (StringUtils.equals(groupMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode())) { principalIds.add(groupMember.getMemberId()); }/*ww w. j a v a 2s . c om*/ } if (!principalIds.isEmpty()) { // retrieve valid principals/principal-ids from identity service List<Principal> validPrincipals = getIdentityService().getPrincipals(principalIds); List<String> validPrincipalIds = new ArrayList<String>(validPrincipals.size()); for (Principal principal : validPrincipals) { validPrincipalIds.add(principal.getPrincipalId()); } // check that there are no invalid principals in the principal list, return false List<String> invalidPrincipalIds = new ArrayList<String>( CollectionUtils.subtract(principalIds, validPrincipalIds)); // if list is not empty add error messages and return false if (CollectionUtils.isNotEmpty(invalidPrincipalIds)) { GlobalVariables.getMessageMap().putError("document.member.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, invalidPrincipalIds.toArray(new String[invalidPrincipalIds.size()])); valid = false; } } return valid; }
From source file:org.lockss.devtools.CrawlRuleTester.java
private Set outputUrlResults(String url, Set m_inclset, Set m_exclset) { Set new_incls = new TreeSet(CollectionUtils.subtract(m_inclset, m_reported)); Set new_excls = new TreeSet(CollectionUtils.subtract(m_exclset, m_reported)); if (!m_inclset.isEmpty()) { outputMessage("\nIncluded Urls: (" + new_incls.size() + " new, " + (m_inclset.size() - new_incls.size()) + " old)", URL_SUMMARY_MESSAGE); depth_incl[m_curDepth - 1] += new_incls.size(); }/*from w w w . jav a2 s.c om*/ for (Iterator it = new_incls.iterator(); it.hasNext();) { outputMessage(it.next().toString(), PLAIN_MESSAGE); } if (!m_exclset.isEmpty()) { outputMessage("\nExcluded Urls: (" + new_excls.size() + " new, " + (m_exclset.size() - new_excls.size()) + " old)", URL_SUMMARY_MESSAGE); } for (Iterator it = new_excls.iterator(); it.hasNext();) { outputMessage(it.next().toString(), PLAIN_MESSAGE); } m_reported.addAll(new_incls); m_reported.addAll(new_excls); if (m_outWriter != null) { try { m_outWriter.flush(); } catch (IOException ex) { } } return new_incls; }
From source file:org.lockss.exporter.FuncZipExporter.java
public void testSeveralVariants() throws Exception { assertEquals(auUrls, testExport(true, -1, FilenameTranslation.XLATE_NONE, false)); testExport(false, 2000, FilenameTranslation.XLATE_NONE, false); testExport(true, -1, FilenameTranslation.XLATE_WINDOWS, false); assertEquals(CollectionUtils.subtract(auUrls, auDirs), testExport(true, -1, FilenameTranslation.XLATE_WINDOWS, true)); }
From source file:org.lockss.servlet.ServletUtil.java
public static void layoutAuPropsTable(LockssServlet servlet, Composite comp, Collection configParamDescrs, Collection defKeys, Configuration initVals, Collection noEditKeys, boolean isNew, Collection editKeys, boolean editable) { Table tbl = new Table(AUPROPS_TABLE_BORDER, AUPROPS_TABLE_ATTRIBUTES); tbl.newRow();// w w w. j a va 2s . c o m tbl.newCell(AUPROPS_CELL_ATTRIBUTES); tbl.add("Archival Unit Definition"); layoutAuPropRows(servlet, tbl, configParamDescrs.iterator(), defKeys, initVals, isNew ? CollectionUtils.subtract(defKeys, noEditKeys) : null); tbl.newRow(); if (editKeys.isEmpty()) { if (!isNew && editable) { // nothing } } else { tbl.newRow(); tbl.newCell(AUPROPS_CELL_ATTRIBUTES); tbl.add("Other Parameters"); layoutAuPropRows(servlet, tbl, configParamDescrs.iterator(), editKeys, initVals, editable ? editKeys : null); } comp.add(tbl); }
From source file:org.mule.tck.logging.TestAppender.java
private String difference(Set<Expectation> expected, Set<Expectation> actual) { StringBuilder builder = new StringBuilder(); addCollection(builder, CollectionUtils.subtract(actual, expected), "Not expected but received:"); addCollection(builder, CollectionUtils.subtract(expected, actual), "Expected but not received:"); return builder.toString(); }
From source file:org.o3project.odenos.remoteobject.rest.servlet.SubscriptionsServlet.java
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(); // this "obj" separated for casting warning avoidance. Object obj = session.getAttribute(Attributes.SUBSCRIPTION_TABLE); @SuppressWarnings("unchecked") Map<String, Set<String>> origTable = (Map<String, Set<String>>) obj; if (origTable == null) { this.logger.debug("A Subscription Table is not found. /{}", session.getId()); resp.setStatus(HttpServletResponse.SC_NOT_FOUND); return;/*from w w w . j a va2s . c om*/ } String reqBody = IOUtils.toString(req.getReader()); Map<String, Set<String>> reqTable = this.deserialize(reqBody); if (reqTable == null) { this.logger.debug("Failed to deserialize the request body. /{}", reqBody); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Map<String, Collection<String>> addedMap = new HashMap<String, Collection<String>>(); Map<String, Collection<String>> removedMap = new HashMap<String, Collection<String>>(); for (Entry<String, Set<String>> reqEntry : reqTable.entrySet()) { String objectId = reqEntry.getKey(); Set<String> reqEvents = reqEntry.getValue(); Set<String> origEvents = origTable.get(objectId); if (origEvents == null) { // All events are unregistered yet. addedMap.put(objectId, reqEvents); origTable.put(objectId, reqEvents); continue; } // generating diff. @SuppressWarnings("unchecked") Collection<String> added = (Collection<String>) CollectionUtils.subtract(reqEvents, origEvents); addedMap.put(objectId, added); @SuppressWarnings("unchecked") Collection<String> removed = (Collection<String>) CollectionUtils.subtract(origEvents, reqEvents); removedMap.put(objectId, removed); } session.setAttribute(Attributes.SUBSCRIPTION_TABLE, reqTable); RESTTranslator translator = (RESTTranslator) req.getServletContext() .getAttribute(Attributes.REST_TRANSLATOR); translator.modifyDistributionSetting(this.subscriptionId, addedMap, removedMap); resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write(toJsonStringFrom(reqTable)); }
From source file:org.obiba.onyx.quartz.editor.locale.LabelsPanel.java
public void onModelChange(AjaxRequestTarget target) { LocaleProperties localeProperties = (LocaleProperties) getDefaultModelObject(); final ListMultimap<Locale, KeyValue> elementLabels = localeProperties .getElementLabels(elementModel.getObject()); Locale userLocale = Session.get().getLocale(); @SuppressWarnings("unchecked") Collection<Locale> removedLocales = CollectionUtils.subtract(tabByLocale.keySet(), localeProperties.getLocales()); List<ITab> tabs = tabbedPanel.getTabs(); for (Locale locale : removedLocales) { ITab tabToRemove = tabByLocale.get(locale); int selectedTabIndex = tabbedPanel.getSelectedTab(); ITab selectedTab = tabs.get(selectedTabIndex); tabs.remove(tabToRemove);/*ww w . j av a 2 s .co m*/ tabByLocale.remove(locale); if (tabToRemove != selectedTab) { for (int i = 0; i < tabs.size(); i++) { ITab tab = tabs.get(i); if (selectedTab == tab) { tabbedPanel.setSelectedTab(i); break; } } } else { tabbedPanel.setSelectedTab(0); } } for (final Locale locale : localeProperties.getLocales()) { if (!tabByLocale.containsKey(locale)) { AbstractTab tab = new AbstractTab(new Model<String>(locale.getDisplayLanguage(userLocale))) { @Override public Panel getPanel(String panelId) { return new InputPanel(panelId, new ListModel<KeyValue>(elementLabels.get(locale)), null); } }; ITab panelCachingTab = new PanelCachingTab(tab); tabByLocale.put(locale, panelCachingTab); tabs.add(panelCachingTab); if (tabs.size() == 1) tabbedPanel.setSelectedTab(0); } } tabbedPanel.setVisible(tabs.size() > 0); target.addComponent(tabsContainer); }
From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
public void persist(QuestionnaireBundle bundle) { List<Locale> questionnaireLocales = bundle.getQuestionnaire().getLocales(); @SuppressWarnings("unchecked") Collection<Locale> deletedLocales = CollectionUtils.subtract(bundle.getAvailableLanguages(), questionnaireLocales);/*from w w w . j ava 2s .co m*/ for (Locale localeToDelete : deletedLocales) { bundle.deleteLanguage(localeToDelete); } Map<Locale, Properties> localePropertiesMap = toLocalePropertiesMap(bundle.getQuestionnaire()); if (localePropertiesMap.entrySet().isEmpty()) { for (Locale locale : questionnaireLocales) { bundle.updateLanguage(locale, new Properties()); } } else { for (Map.Entry<Locale, Properties> entry : localePropertiesMap.entrySet()) { bundle.updateLanguage(entry.getKey(), entry.getValue()); } } }
From source file:org.obiba.onyx.quartz.editor.questionnaire.QuestionnairePanel.java
public QuestionnairePanel(String id, final IModel<Questionnaire> model, boolean newQuestionnaire) { super(id, model); final Questionnaire questionnaire = model.getObject(); add(CSSPackageResource.getHeaderContribution(QuestionnairePanel.class, "QuestionnairePanel.css")); feedbackPanel = new FeedbackPanel("content"); feedbackWindow = new FeedbackWindow("feedback"); feedbackWindow.setOutputMarkupId(true); add(feedbackWindow);//from w w w . j ava 2 s . co m Form<Questionnaire> form = new Form<Questionnaire>("form", model); add(form); TextField<String> name = new TextField<String>("name", new PropertyModel<String>(form.getModel(), "name")); name.setLabel(new ResourceModel("Name")); name.setEnabled(newQuestionnaire); name.add(new RequiredFormFieldBehavior()); name.add(new PatternValidator(QuartzEditorPanel.ELEMENT_NAME_PATTERN)); name.add(new AbstractValidator<String>() { @Override protected void onValidate(final IValidatable<String> validatable) { boolean isNewName = Iterables.all(questionnaireBundleManager.bundles(), new Predicate<QuestionnaireBundle>() { @Override public boolean apply(QuestionnaireBundle input) { return !input.getName().equals(validatable.getValue()); } }); if (!isNewName && !validatable.getValue().equals(questionnaire.getName())) { error(validatable, "NameAlreadyExist"); } } }); form.add(name).add(new SimpleFormComponentLabel("nameLabel", name)) .add(new HelpTooltipPanel("nameHelp", new ResourceModel("Name.Tooltip"))); TextField<String> version = new TextField<String>("version", new PropertyModel<String>(form.getModel(), "version")); version.setLabel(new ResourceModel("Version")); version.add(new RequiredFormFieldBehavior()); form.add(version).add(new SimpleFormComponentLabel("versionLabel", version)); CheckBox commentable = new CheckBox("commentable", new PropertyModel<Boolean>(questionnaire, "commentable")); commentable.setLabel(new ResourceModel("Commentable")); form.add(commentable); form.add(new SimpleFormComponentLabel("commentableLabel", commentable)); form.add(new HelpTooltipPanel("commentableHelp", new ResourceModel("Commentable.Tooltip"))); QuestionnaireFinder.getInstance(questionnaire).buildQuestionnaireCache(); guessUIType(questionnaire); RadioGroup<String> uiType = new RadioGroup<String>("uiType", new PropertyModel<String>(form.getModel(), "uiType")); uiType.setLabel(new ResourceModel("UIType")); uiType.setRequired(true); form.add(uiType); Radio<String> standardUiType = new Radio<String>("standard", new Model<String>(Questionnaire.STANDARD_UI)); standardUiType.setLabel(new ResourceModel("UIType.standard")); uiType.add(standardUiType).add(new SimpleFormComponentLabel("standardLabel", standardUiType)); Radio<String> simplifiedUiType = new Radio<String>("simplified", new Model<String>(Questionnaire.SIMPLIFIED_UI)); simplifiedUiType.setLabel(new ResourceModel("UIType.simplified")); uiType.add(simplifiedUiType).add(new SimpleFormComponentLabel("simplifiedLabel", simplifiedUiType)); form.add(new HelpTooltipPanel("uiHelp", new ResourceModel("UIType.Tooltip"))); form.add(new HelpTooltipPanel("labelsHelp", new ResourceModel("LanguagesProperties.Tooltip"))); Map<String, IModel<String>> labelsTooltips = new HashMap<String, IModel<String>>(); labelsTooltips.put("label", new ResourceModel("Questionnaire.Tooltip.label")); labelsTooltips.put("description", new ResourceModel("Questionnaire.Tooltip.description")); labelsTooltips.put("labelNext", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelPrevious", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelStart", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelFinish", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelInterrupt", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelResume", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelCancel", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); localePropertiesModel = new Model<LocaleProperties>( newQuestionnaire ? LocaleProperties.createForNewQuestionnaire(questionnaire) : localePropertiesUtils.load(questionnaire, questionnaire)); final LabelsPanel labelsPanel = new LabelsPanel("labels", localePropertiesModel, model, feedbackPanel, feedbackWindow, labelsTooltips, null); form.add(labelsPanel); final Locale userLocale = Session.get().getLocale(); IChoiceRenderer<Locale> renderer = new IChoiceRenderer<Locale>() { @Override public String getIdValue(Locale locale, int index) { return locale.toString(); } @Override public Object getDisplayValue(Locale locale) { return locale.getDisplayLanguage(userLocale); } }; IModel<List<Locale>> localeChoices = new LoadableDetachableModel<List<Locale>>() { @Override protected List<Locale> load() { List<Locale> locales = new ArrayList<Locale>(); for (String language : Locale.getISOLanguages()) { locales.add(new Locale(language)); } Collections.sort(locales, new Comparator<Locale>() { @Override public int compare(Locale locale1, Locale locale2) { return locale1.getDisplayLanguage(userLocale) .compareTo(locale2.getDisplayLanguage(userLocale)); } }); return locales; } }; Palette<Locale> localesPalette = new Palette<Locale>("languages", new PropertyModel<List<Locale>>(model.getObject(), "locales"), localeChoices, renderer, 5, false) { @Override protected Recorder<Locale> newRecorderComponent() { Recorder<Locale> recorder = super.newRecorderComponent(); recorder.setLabel(new ResourceModel("Languages")); recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { LocaleProperties localeProperties = localePropertiesModel.getObject(); Collection<Locale> selectedLocales = getModelCollection(); @SuppressWarnings("unchecked") Collection<Locale> removedLocales = CollectionUtils.subtract(localeProperties.getLocales(), selectedLocales); for (Locale locale : removedLocales) { localeProperties.removeLocale(questionnaire, locale); } for (Locale locale : selectedLocales) { if (!localeProperties.getLocales().contains(locale)) { localeProperties.addLocale(questionnaire, locale); } } labelsPanel.onModelChange(target); } }); return recorder; } }; form.add(localesPalette); form.add(new SaveCancelPanel("saveCancel", form) { @Override protected void onSave(AjaxRequestTarget target, Form<?> form1) { try { if (questionnaire.getLocales().isEmpty()) { error(new StringResourceModel("LanguagesRequired", QuestionnairePanel.this, null) .getString()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); return; } prepareSave(target, questionnaire); questionnairePersistenceUtils.persist(questionnaire, localePropertiesModel.getObject()); QuestionnairePanel.this.onSave(target, questionnaire); } catch (Exception e) { log.error("Cannot persist questionnaire", e); error("Cannot persist questionnaire: " + e.getMessage()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } } @Override protected void onCancel(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { QuestionnairePanel.this.onCancel(target); } @Override protected void onError(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } }); }
From source file:org.objectstyle.cayenne.modeler.action.ImportEOModelAction.java
/** * Adds DataMap into the project./*from w ww .j a v a2s .c o m*/ */ protected void addDataMap(DataMap map, DataMap currentMap) { ProjectController mediator = getProjectController(); if (currentMap != null) { // merge with existing map... have to memorize map state before and after // to do the right events Collection originalOE = new ArrayList(currentMap.getObjEntities()); Collection originalDE = new ArrayList(currentMap.getDbEntities()); currentMap.mergeWithDataMap(map); map = currentMap; // postprocess changes Collection newOE = new ArrayList(currentMap.getObjEntities()); Collection newDE = new ArrayList(currentMap.getDbEntities()); EntityEvent entityEvent = new EntityEvent(Application.getFrame(), null); Collection addedOE = CollectionUtils.subtract(newOE, originalOE); Iterator it = addedOE.iterator(); while (it.hasNext()) { Entity e = (Entity) it.next(); entityEvent.setEntity(e); entityEvent.setId(EntityEvent.ADD); mediator.fireObjEntityEvent(entityEvent); } Collection removedOE = CollectionUtils.subtract(originalOE, newOE); it = removedOE.iterator(); while (it.hasNext()) { Entity e = (Entity) it.next(); entityEvent.setEntity(e); entityEvent.setId(EntityEvent.REMOVE); mediator.fireObjEntityEvent(entityEvent); } Collection addedDE = CollectionUtils.subtract(newDE, originalDE); it = addedDE.iterator(); while (it.hasNext()) { Entity e = (Entity) it.next(); entityEvent.setEntity(e); entityEvent.setId(EntityEvent.ADD); mediator.fireDbEntityEvent(entityEvent); } Collection removedDE = CollectionUtils.subtract(originalDE, newDE); it = removedDE.iterator(); while (it.hasNext()) { Entity e = (Entity) it.next(); entityEvent.setEntity(e); entityEvent.setId(EntityEvent.REMOVE); mediator.fireDbEntityEvent(entityEvent); } mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(Application.getFrame(), map, mediator.getCurrentDataDomain(), mediator.getCurrentDataNode())); } else { // fix DataMap name, as there maybe a map with the same name already DataDomain domain = mediator.getCurrentDataDomain(); map.setName(NamedObjectFactory.createName(DataMap.class, domain, map.getName())); // side effect of this operation is that if a node was created, this DataMap // will be linked with it... mediator.addDataMap(Application.getFrame(), map); } }