List of usage examples for java.util List retainAll
boolean retainAll(Collection<?> c);
From source file:net.sourceforge.vulcan.web.JstlFunctions.java
public static List<String> getAvailableDashboardColumns(PageContext pageContext) { final List<String> availableColumns = getAllDashboardColumns(Keys.DASHBOARD_COLUMNS); availableColumns.addAll(getAvailableMetrics()); final PreferencesDto prefs = (PreferencesDto) pageContext.findAttribute(Keys.PREFERENCES); if (prefs != null && prefs.getDashboardColumns() != null) { // Start with the chosen columns in the chosen order. final List<String> userSorted = new ArrayList<String>(Arrays.asList(prefs.getDashboardColumns())); // Remove any columns that are no longer valid. userSorted.retainAll(availableColumns); // Remove duplicates from set of unselected columns. availableColumns.removeAll(userSorted); // Add the unselected columns to the end of the list. userSorted.addAll(availableColumns); return userSorted; }// w w w . j a v a 2 s .c o m return availableColumns; }
From source file:org.elasticsearch.hadoop.rest.InitializationUtils.java
public static void filterNonDataNodesIfNeeded(Settings settings, Log log) { if (!settings.getNodesDataOnly() || settings.getNodesClientOnly()) { return;/*from w ww.jav a 2s. c o m*/ } RestClient bootstrap = new RestClient(settings); try { String message = "No data nodes with HTTP-enabled available"; List<String> dataNodes = bootstrap.getHttpDataNodes(); if (dataNodes.isEmpty()) { throw new EsHadoopIllegalArgumentException(message); } if (log.isDebugEnabled()) { log.debug(String.format("Found data nodes %s", dataNodes)); } List<String> ddNodes = SettingsUtils.discoveredOrDeclaredNodes(settings); // remove non-data nodes ddNodes.retainAll(dataNodes); if (log.isDebugEnabled()) { log.debug(String.format("Filtered discovered only nodes %s to data-only %s", SettingsUtils.discoveredOrDeclaredNodes(settings), ddNodes)); } if (ddNodes.isEmpty()) { if (settings.getNodesDiscovery()) { message += String.format( "; looks like the data nodes discovered have been removed; is the cluster in a stable state? %s", dataNodes); } else { message += String.format( "; node discovery is disabled and none of nodes specified fits the criterion %s", SettingsUtils.discoveredOrDeclaredNodes(settings)); } throw new EsHadoopIllegalArgumentException(message); } SettingsUtils.setDiscoveredNodes(settings, dataNodes); } finally { bootstrap.close(); } }
From source file:org.elasticsearch.hadoop.rest.InitializationUtils.java
public static void filterNonClientNodesIfNeeded(Settings settings, Log log) { if (!settings.getNodesClientOnly()) { return;/*from w w w .j a v a 2s . c o m*/ } RestClient bootstrap = new RestClient(settings); try { String message = "Client-only routing specified but no client nodes with HTTP-enabled available"; List<String> clientNodes = bootstrap.getHttpClientNodes(); if (clientNodes.isEmpty()) { throw new EsHadoopIllegalArgumentException(message); } if (log.isDebugEnabled()) { log.debug(String.format("Found client nodes %s", clientNodes)); } List<String> ddNodes = SettingsUtils.discoveredOrDeclaredNodes(settings); // remove non-client nodes ddNodes.retainAll(clientNodes); if (log.isDebugEnabled()) { log.debug(String.format("Filtered discovered only nodes %s to client-only %s", SettingsUtils.discoveredOrDeclaredNodes(settings), ddNodes)); } if (ddNodes.isEmpty()) { if (settings.getNodesDiscovery()) { message += String.format( "; looks like the client nodes discovered have been removed; is the cluster in a stable state? %s", clientNodes); } else { message += String.format( "; node discovery is disabled and none of nodes specified fits the criterion %s", SettingsUtils.discoveredOrDeclaredNodes(settings)); } throw new EsHadoopIllegalArgumentException(message); } SettingsUtils.setDiscoveredNodes(settings, ddNodes); } finally { bootstrap.close(); } }
From source file:com.kibana.multitenancy.plugin.kibana.KibanaSeed.java
public static void setDashboards(String user, Set<String> projects, Set<String> roles, Client esClient, String kibanaIndex, String kibanaVersion) { //GET .../.kibana/index-pattern/_search?pretty=true&fields= // compare results to projects; handle any deltas (create, delete?) //check projects for default and remove for (String project : BLACKLIST_PROJECTS) if (projects.contains(project)) { logger.debug("Black-listed project '{}' found. Not adding as an index pattern", project); projects.remove(project);// w ww . j ava2s .co m } Set<String> indexPatterns = getIndexPatterns(user, esClient, kibanaIndex); logger.debug("Found '{}' Index patterns for user", indexPatterns.size()); // Check roles here, if user is a cluster-admin we should add .operations to their project? -- correct way to do this? logger.debug("Checking for '{}' in users roles '{}'", OPERATIONS_ROLES, roles); /*for ( String role : OPERATIONS_ROLES ) if ( roles.contains(role) ) { logger.debug("{} is an admin user", user); projects.add(OPERATIONS_PROJECT); break; }*/ List<String> sortedProjects = new ArrayList<String>(projects); Collections.sort(sortedProjects); if (sortedProjects.isEmpty()) sortedProjects.add(BLANK_PROJECT); logger.debug("Setting dashboards given user '{}' and projects '{}'", user, projects); // If none have been set yet if (indexPatterns.isEmpty()) { create(user, sortedProjects, true, esClient, kibanaIndex, kibanaVersion); //TODO : Currently it is generating wrong search properties when integrated with ES 2.1 //createSearchProperties(user, esClient, kibanaIndex); } else { List<String> common = new ArrayList<String>(indexPatterns); // Get a list of all projects that are common common.retainAll(sortedProjects); sortedProjects.removeAll(common); indexPatterns.removeAll(common); // for any to create (remaining in projects) call createIndices, createSearchmapping?, create dashboard create(user, sortedProjects, false, esClient, kibanaIndex, kibanaVersion); // cull any that are in ES but not in OS (remaining in indexPatterns) remove(user, indexPatterns, esClient, kibanaIndex); common.addAll(sortedProjects); Collections.sort(common); // Set default index to first index in common if we removed the default String defaultIndex = getDefaultIndex(user, esClient, kibanaIndex, kibanaVersion); logger.debug("Checking if '{}' contains '{}'", indexPatterns, defaultIndex); if (indexPatterns.contains(defaultIndex) || StringUtils.isEmpty(defaultIndex)) { logger.debug("'{}' does contain '{}' and common size is {}", indexPatterns, defaultIndex, common.size()); if (common.size() > 0) setDefaultIndex(user, common.get(0), esClient, kibanaIndex, kibanaVersion); } } }
From source file:org.nuxeo.ecm.webapp.bulkedit.BulkEditHelper.java
/** * Returns the common schemas of the {@code docs}. *///from w w w.j a v a 2s . c om public static List<String> getCommonSchemas(List<DocumentModel> docs) { List<String> schemas = null; for (DocumentModel doc : docs) { List<String> docSchemas = Arrays.asList(doc.getSchemas()); if (schemas == null) { // first document schemas = new ArrayList<String>(); schemas.addAll(docSchemas); } else { schemas.retainAll(docSchemas); } } return schemas; }
From source file:net.sf.morph.util.ListOrderedSet.java
/** * Factory method to create an ordered set using the supplied list to retain order. * <p>//www. j av a 2 s . com * A <code>HashSet</code> is used for the set behaviour. * <p> * NOTE: If the list contains duplicates, the duplicates are removed, * altering the specified list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static ListOrderedSet decorate(List list) { if (list == null) { throw new IllegalArgumentException("List must not be null"); } Set set = new HashSet(list); list.retainAll(set); return new ListOrderedSet(set, list); }
From source file:org.nuxeo.ecm.webapp.bulkedit.BulkEditHelper.java
/** * Returns the common layouts of the {@code docs} for the given layout {@code mode}. *///w w w .j a va2s. co m public static List<String> getCommonLayouts(TypeManager typeManager, List<DocumentModel> docs, String mode) { List<String> layouts = null; for (DocumentModel doc : docs) { Type type = typeManager.getType(doc.getType()); List<String> typeLayouts = Arrays.asList(type.getLayouts(mode)); if (layouts == null) { // first document layouts = new ArrayList<String>(); layouts.addAll(typeLayouts); } else { layouts.retainAll(typeLayouts); } } return layouts; }
From source file:main.java.spatialrelex.Evaluator.java
/** * // w w w .jav a2s .c o m * @param fileDocumentObject * @throws java.io.IOException */ public static void setSievesOrder(Map<String, Doc> fileDocumentObject) throws IOException { Map<String, Map<String, List<String>>> extractedMovelinks = combineMovelinkSubparts(); String bestSieve = ""; double bestSievePrecision = 0.0; //repeat for all remaining optional elements for (String relation : SpatialRelation.RELATION_ROLENAME.keySet()) { if (SpatialRelation.ORDERED_SIEVES.contains(relation)) continue; double tp = 0.0; double fp = 0.0; for (String file : fileDocumentObject.keySet()) { Doc document = fileDocumentObject.get(file); Map<String, Map<String, List<String>>> goldMovelinks = document.triggerMoverRoleOtherElements; for (String triggerMover : goldMovelinks.keySet()) { Map<String, List<String>> extractedRoleOtherElements = extractedMovelinks.get(triggerMover); if (extractedRoleOtherElements == null) continue; Map<String, List<String>> roleOtherElements = goldMovelinks.get(triggerMover); if (roleOtherElements != null) { for (String role : roleOtherElements.keySet()) { List<String> otherElements = roleOtherElements.get(role); if (!extractedRoleOtherElements.containsKey(role)) continue; List<String> extractedOtherElements = extractedRoleOtherElements.get(role); List<String> tempList = new ArrayList<>(otherElements); tempList.retainAll(extractedOtherElements); tp += tempList.size(); tempList = new ArrayList<>(extractedOtherElements); tempList.removeAll(otherElements); fp += tempList.size(); } continue; } for (String role : extractedRoleOtherElements.keySet()) { List<String> extractedOtherElements = extractedRoleOtherElements.get(role); fp += extractedOtherElements.size(); } } } double precision = getPrecision(tp, fp); if (precision > bestSievePrecision) { bestSieve = relation; bestSievePrecision = precision; } } SpatialRelation.ORDERED_SIEVES.add(bestSieve); addChosenSieveResults(extractedMovelinks, bestSieve); }
From source file:module.siadap.domain.ExceedingQuotaProposal.java
public static ExceedingQuotaProposal getQuotaProposalFor(final Unit unit, final int year, final Person person, final SiadapUniverse siadapUniverse, final boolean quotasUniverse) { SiadapYearConfiguration configuration = SiadapYearConfiguration.getSiadapYearConfiguration(year); if (configuration == null) { return null; }/*ww w .jav a 2 s. com*/ List<ExceedingQuotaProposal> personQuotaProposal = new ArrayList<ExceedingQuotaProposal>( person.getExceedingQuotasProposalsSet()); List<ExceedingQuotaProposal> exceedingQuotasProposalsForGivenYear = new ArrayList<ExceedingQuotaProposal>( configuration.getExceedingQuotasProposals()); exceedingQuotasProposalsForGivenYear.retainAll(personQuotaProposal); List<ExceedingQuotaProposal> quotaProposalsByPredicate = getQuotaProposalsByPredicate( exceedingQuotasProposalsForGivenYear, new Predicate() { @Override public boolean evaluate(Object arg0) { ExceedingQuotaProposal exceedingQuotaProposal = (ExceedingQuotaProposal) arg0; return (exceedingQuotaProposal.getSiadapUniverse().equals(siadapUniverse) && exceedingQuotaProposal.getWithinOrganizationQuotaUniverse() == quotasUniverse && exceedingQuotaProposal.getUnit().equals(unit) && exceedingQuotaProposal.getSuggestion().equals(person)); } }); if (quotaProposalsByPredicate.size() == 0) { return null; } if (quotaProposalsByPredicate.size() > 1) { throw new SiadapException("siadap.exceedingQuotaProposal.inconsistency.detected"); } return quotaProposalsByPredicate.get(0); }
From source file:com.flexive.shared.content.FxDelta.java
/** * Compare <code>original</code> to <code>compare</code> FxContent. * Both contents should be compacted and empty entries removed for correct results. * Flatstorage entries will only be added to the remove list. * * @param original original content/*from w w w. j ava 2 s. c o m*/ * @param compare content that original is compared against * @return deltas * @throws FxInvalidParameterException on errors * @throws FxNotFoundException on errors */ public static FxDelta processDelta(final FxContent original, final FxContent compare) throws FxNotFoundException, FxInvalidParameterException { List<String> org = original.getAllXPaths("/"); List<String> comp = compare.getAllXPaths("/"); List<FxDeltaChange> updates = null, adds = null, removes = null; //remove all xpaths from comp that are not contained in org => updates List<String> update = new ArrayList<String>(comp); update.retainAll(org); for (String xp : update) { if (xp.endsWith("/")) { //group xp = xp.substring(0, xp.length() - 1); if (!compare.getGroupData(xp).equals(original.getGroupData(xp))) { if (updates == null) updates = new ArrayList<FxDeltaChange>(10); updates.add(new FxDeltaChange(FxDeltaChange.ChangeType.Update, xp, original.getGroupData(xp), compare.getGroupData(xp))); } } else if (!compare.getData(xp).equals(original.getData(xp))) { //property if (updates == null) updates = new ArrayList<FxDeltaChange>(10); final FxPropertyData orgData = original.getPropertyData(xp); updates.add(new FxDeltaChange(FxDeltaChange.ChangeType.Update, xp, orgData, compare.getPropertyData(xp))); } } List<String> add = new ArrayList<String>(comp); add.removeAll(org); for (String xp : add) { if (adds == null) adds = new ArrayList<FxDeltaChange>(10); if (xp.endsWith("/")) { //group xp = xp.substring(0, xp.length() - 1); adds.add(new FxDeltaChange(FxDeltaChange.ChangeType.Add, xp, null, compare.getGroupData(xp))); } else { //property final FxPropertyData pdata = compare.getPropertyData(xp); adds.add(new FxDeltaChange(FxDeltaChange.ChangeType.Add, xp, null, pdata)); } } List<String> rem = new ArrayList<String>(org); rem.removeAll(comp); for (String xp : rem) { if (removes == null) removes = new ArrayList<FxDeltaChange>(10); if (xp.endsWith("/")) { xp = xp.substring(0, xp.length() - 1); final FxGroupData groupData = original.getGroupData(xp); if (!groupData.isEmpty()) { removes.add(new FxDeltaChange(FxDeltaChange.ChangeType.Remove, xp, groupData, null)); } } else { final FxPropertyData propertyData = original.getPropertyData(xp); if (!propertyData.isEmpty()) { removes.add(new FxDeltaChange(FxDeltaChange.ChangeType.Remove, xp, propertyData, null)); } } } return new FxDelta(updates, adds, removes); }