List of usage examples for java.util Set retainAll
boolean retainAll(Collection<?> c);
From source file:architecture.ee.web.community.page.dao.jdbc.JdbcPageDao.java
private List<String> getModifiedPropertyKeys(Map<String, String> oldProps, Map<String, String> newProps) { HashMap<String, String> temp = new HashMap<String, String>(oldProps); Set<String> oldKeys = temp.keySet(); Set<String> newKeys = newProps.keySet(); oldKeys.retainAll(newKeys); List<String> modified = new ArrayList<String>(); for (String key : oldKeys) { log.debug(key + " equals:[" + newProps.get(key) + "]=[" + oldProps.get(key) + "]" + StringUtils.equals(newProps.get(key), oldProps.get(key))); if (!StringUtils.equals(newProps.get(key), oldProps.get(key))) modified.add(key);/*from w w w.j a va 2 s .co m*/ } return modified; }
From source file:org.kuali.kfs.module.endow.report.service.impl.EndowmentReportServiceImpl.java
/** * Retains the kemids that are in common. * //from w w w .ja va2s .co m * @param kemids * @param list */ public void retainCommonKemids(Set<String> kemids, List<String> list) { if (list != null && !list.isEmpty()) { if (kemids.isEmpty()) { kemids.addAll(list); } else { kemids.retainAll(list); } } }
From source file:org.wso2.carbon.analytics.activitydashboard.admin.ActivityDashboardAdminService.java
private Set<String> searchActivities(String username, String timeBasedQuery, ExpressionNode expressionNode, CategoryDrillDownRequest categoryDrillDownRequest) throws ActivityDashboardException { if (expressionNode.getLeftExpression() != null) { if (!(expressionNode instanceof Operation)) { throw new ActivityDashboardException( "This node is having an left expression, " + "but the node is not marked as operation!"); }//ww w . j a v a2s . c o m Operation operation = (Operation) expressionNode; Set<String> leftNodeActivities = searchActivities(username, timeBasedQuery, expressionNode.getLeftExpression(), categoryDrillDownRequest); Set<String> rightNodeActivities = searchActivities(username, timeBasedQuery, expressionNode.getRightExpression(), categoryDrillDownRequest); if (operation.getOperator() == Operation.Operator.OR) { leftNodeActivities.addAll(rightNodeActivities); } else { leftNodeActivities.retainAll(rightNodeActivities); } return leftNodeActivities; } else { Set<String> activities; if (expressionNode instanceof Query) { Query query = (Query) expressionNode; String completeQuery = getFullSearchQuery(query.getQueryString(), timeBasedQuery); activities = getActivityIdsForTable(username, query.getTableName(), completeQuery, categoryDrillDownRequest); validateActivityIdsResultLimit(activities.size()); return activities; } else { throw new ActivityDashboardException( "Invalid search expression provided. " + "The search tree ended with operation type node!"); } } }
From source file:org.mitre.openid.connect.web.DynamicClientRegistrationEndpoint.java
private ClientDetailsEntity validateGrantTypes(ClientDetailsEntity newClient) throws ValidationException { // set default grant types if needed if (newClient.getGrantTypes() == null || newClient.getGrantTypes().isEmpty()) { if (newClient.getScope().contains("offline_access")) { // client asked for offline access newClient.setGrantTypes(Sets.newHashSet("authorization_code", "refresh_token")); // allow authorization code and refresh token grant types by default } else {/*from w w w.ja va 2 s. c o m*/ newClient.setGrantTypes(Sets.newHashSet("authorization_code")); // allow authorization code grant type by default } if (config.isDualClient()) { Set<String> extendedGrandTypes = newClient.getGrantTypes(); extendedGrandTypes.add("client_credentials"); newClient.setGrantTypes(extendedGrandTypes); } } // filter out unknown grant types // TODO: make this a pluggable service Set<String> requestedGrantTypes = new HashSet<>(newClient.getGrantTypes()); requestedGrantTypes.retainAll(ImmutableSet.of("authorization_code", "implicit", "password", "client_credentials", "refresh_token", "urn:ietf:params:oauth:grant_type:redelegate")); // don't allow "password" grant type for dynamic registration if (newClient.getGrantTypes().contains("password")) { // return an error, you can't dynamically register for the password grant throw new ValidationException("invalid_client_metadata", "The password grant type is not allowed in dynamic registration on this server.", HttpStatus.BAD_REQUEST); } // don't allow clients to have multiple incompatible grant types and scopes if (newClient.getGrantTypes().contains("authorization_code")) { // check for incompatible grants if (newClient.getGrantTypes().contains("implicit") || (!config.isDualClient() && newClient.getGrantTypes().contains("client_credentials"))) { // return an error, you can't have these grant types together throw new ValidationException("invalid_client_metadata", "Incompatible grant types requested: " + newClient.getGrantTypes(), HttpStatus.BAD_REQUEST); } if (newClient.getResponseTypes().contains("token")) { // return an error, you can't have this grant type and response type together throw new ValidationException( "invalid_client_metadata", "Incompatible response types requested: " + newClient.getGrantTypes() + " / " + newClient.getResponseTypes(), HttpStatus.BAD_REQUEST); } newClient.getResponseTypes().add("code"); } if (newClient.getGrantTypes().contains("implicit")) { // check for incompatible grants if (newClient.getGrantTypes().contains("authorization_code") || (!config.isDualClient() && newClient.getGrantTypes().contains("client_credentials"))) { // return an error, you can't have these grant types together throw new ValidationException("invalid_client_metadata", "Incompatible grant types requested: " + newClient.getGrantTypes(), HttpStatus.BAD_REQUEST); } if (newClient.getResponseTypes().contains("code")) { // return an error, you can't have this grant type and response type together throw new ValidationException( "invalid_client_metadata", "Incompatible response types requested: " + newClient.getGrantTypes() + " / " + newClient.getResponseTypes(), HttpStatus.BAD_REQUEST); } newClient.getResponseTypes().add("token"); // don't allow refresh tokens in implicit clients newClient.getGrantTypes().remove("refresh_token"); newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } if (newClient.getGrantTypes().contains("client_credentials")) { // check for incompatible grants if (!config.isDualClient() && (newClient.getGrantTypes().contains("authorization_code") || newClient.getGrantTypes().contains("implicit"))) { // return an error, you can't have these grant types together throw new ValidationException("invalid_client_metadata", "Incompatible grant types requested: " + newClient.getGrantTypes(), HttpStatus.BAD_REQUEST); } if (!newClient.getResponseTypes().isEmpty()) { // return an error, you can't have this grant type and response type together throw new ValidationException( "invalid_client_metadata", "Incompatible response types requested: " + newClient.getGrantTypes() + " / " + newClient.getResponseTypes(), HttpStatus.BAD_REQUEST); } // don't allow refresh tokens or id tokens in client_credentials clients newClient.getGrantTypes().remove("refresh_token"); newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS); newClient.getScope().remove(SystemScopeService.OPENID_SCOPE); } if (newClient.getGrantTypes().isEmpty()) { // return an error, you need at least one grant type selected throw new ValidationException("invalid_client_metadata", "Clients must register at least one grant type.", HttpStatus.BAD_REQUEST); } return newClient; }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
private void regenerateByUniques() { byUniques.clear();// ww w. j a va 2 s .co m addUniqueMaps(byUniques); // Get columns from both datasets Set<DatasetColumn> cols = new HashSet<>( dataset1ComboBox.getSelectionModel().getSelectedItem().getColumns()); cols.retainAll(dataset2ComboBox.getSelectionModel().getSelectedItem().getColumns()); byUniques.addAll(cols.stream().sorted().collect(Collectors.toList())); }
From source file:org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.java
private Map<String, Set<String>> resolveSearchRoutingSingleValue(MetaData metaData, @Nullable String routing, String aliasOrIndex) {//from www.ja v a 2 s.c o m Map<String, Set<String>> routings = null; Set<String> paramRouting = null; if (routing != null) { paramRouting = Strings.splitStringByCommaToSet(routing); } ImmutableOpenMap<String, AliasMetaData> indexToRoutingMap = metaData.getAliases().get(aliasOrIndex); if (indexToRoutingMap != null && !indexToRoutingMap.isEmpty()) { // It's an alias for (ObjectObjectCursor<String, AliasMetaData> indexRouting : indexToRoutingMap) { if (!indexRouting.value.searchRoutingValues().isEmpty()) { // Routing alias Set<String> r = new HashSet<>(indexRouting.value.searchRoutingValues()); if (paramRouting != null) { r.retainAll(paramRouting); } if (!r.isEmpty()) { if (routings == null) { routings = newHashMap(); } routings.put(indexRouting.key, r); } } else { // Non-routing alias if (paramRouting != null) { Set<String> r = new HashSet<>(paramRouting); if (routings == null) { routings = newHashMap(); } routings.put(indexRouting.key, r); } } } } else { // It's an index if (paramRouting != null) { routings = ImmutableMap.of(aliasOrIndex, paramRouting); } } return routings; }
From source file:delfos.rs.contentbased.vsm.booleanvsm.symeonidis2007.Symeonidis2007FeatureWeighted.java
@Override protected Collection<Recommendation> recommendOnly(DatasetLoader<? extends Rating> datasetLoader, Symeonidis2007Model model, Symeonidis2007UserProfile userProfile, Collection<Integer> candidateItems) throws UserNotFound, ItemNotFound, CannotLoadRatingsDataset, CannotLoadContentDataset { final RatingsDataset<? extends Rating> ratingsDataset = datasetLoader.getRatingsDataset(); final ContentDataset contentDataset; if (datasetLoader instanceof ContentDatasetLoader) { ContentDatasetLoader contentDatasetLoader = (ContentDatasetLoader) datasetLoader; contentDataset = contentDatasetLoader.getContentDataset(); } else {/*w w w . jav a 2s . co m*/ throw new CannotLoadContentDataset( "The dataset loader is not a ContentDatasetLoader, cannot apply a content-based "); } //Step1: Busco los vecinos ms cercanos. int neighborhoodSize = getNeighborhoodSize(); List<Neighbor> neighbors = getUserNeighbors(model, userProfile); //Step 2: We get the items in the neighborhood ( and perform intersection with candidate items). Set<Integer> itemsNeighborhood = new TreeSet<Integer>(); for (Neighbor neighbor : neighbors.subList(0, Math.min(neighbors.size(), neighborhoodSize))) { Collection<Integer> neighborRated = ratingsDataset.getUserRated(neighbor.getIdNeighbor()); itemsNeighborhood.addAll(neighborRated); } itemsNeighborhood.retainAll(candidateItems); //Step 3: We get the features of each item: I1: {F2}, I3: {F2, F3}, I5: {F1, F2, F3} //Step 4: We ?nd their frequency in the neighborhood:fr(F1)=1, fr(F2)=3, fr(F3)=2 SparseVector<Long> featureFrequency = model.getBooleanFeaturesTransformation().newProfile(); featureFrequency.fill(0); for (int idItem : itemsNeighborhood) { try { Item item = contentDataset.get(idItem); for (Feature feature : item.getFeatures()) { Object featureValue = item.getFeatureValue(feature); long idFeature = model.getBooleanFeaturesTransformation().getFeatureIndex(feature, featureValue); featureFrequency.add(idFeature, 1.0); } } catch (EntityNotFound ex) { ERROR_CODES.ITEM_NOT_FOUND.exit(ex); } } //Step 5: For each item, we add its features frequency ?nding its weight in the neighborhood: w(I1) = 3, w(I3) = 5, w(I5) = 6. Collection<Recommendation> recommendations = new ArrayList<>(); for (int idItem : candidateItems) { try { double itemScore = 0; Item item = contentDataset.get(idItem); for (Feature feature : item.getFeatures()) { Object featureValue = item.getFeatureValue(feature); long idFeature = model.getBooleanFeaturesTransformation().getFeatureIndex(feature, featureValue); itemScore += featureFrequency.get(idFeature); } recommendations.add(new Recommendation(idItem, itemScore)); } catch (EntityNotFound ex) { ERROR_CODES.ITEM_NOT_FOUND.exit(ex); } } return recommendations; }
From source file:ubic.BAMSandAllen.MatrixPairs.MatrixPair.java
public void sameSpace() { DoubleMatrix<String, String> newMatrixB = new DenseDoubleMatrix<String, String>(matrixB.rows(), matrixA.columns());//from w ww. j a va 2s. c om newMatrixB.setColumnNames(matrixA.getColNames()); newMatrixB.setRowNames(matrixB.getRowNames()); for (String matrixAColumn : matrixA.getColNames()) { Set<String> matrixBColumns = convertANametoB(matrixAColumn); // we may still have been mapped to a brain region with no data // requires mapping and matrix data! matrixBColumns.retainAll(matrixB.getColNames()); if (matrixBColumns.size() > 1) log.info("Merging " + matrixBColumns + " into " + matrixAColumn); // merge them all in - all of these B columns gota be put into a single spot in the new Matrix for (String matrixBColumn : matrixBColumns) { // do the averaging into the BAMSRegion int oldIndex = matrixB.getColIndexByName(matrixBColumn); int newIndex = newMatrixB.getColIndexByName(matrixAColumn); // the column of data to be merged double[] matrixColumn = matrixB.getColumn(oldIndex); for (int row = 0; row < matrixColumn.length; row++) { double current = newMatrixB.get(row, newIndex); // average things out double value = current + matrixColumn[row] / ((double) matrixBColumns.size()); newMatrixB.set(row, newIndex, value); } } } matrixB = matrixB.replaceMatrix(newMatrixB); isInSameSpace = true; }
From source file:org.apache.syncope.core.misc.security.AuthDataAccessor.java
protected Set<? extends ExternalResource> getPassthroughResources(final User user) { Set<? extends ExternalResource> result = null; // 1. look for assigned resources, pick the ones whose account policy has authentication resources for (ExternalResource resource : userDAO.findAllResources(user)) { if (resource.getAccountPolicy() != null && !resource.getAccountPolicy().getResources().isEmpty()) { if (result == null) { result = resource.getAccountPolicy().getResources(); } else { result.retainAll(resource.getAccountPolicy().getResources()); }//from w ww .j a v a 2s.c om } } // 2. look for realms, pick the ones whose account policy has authentication resources for (Realm realm : realmDAO.findAncestors(user.getRealm())) { if (realm.getAccountPolicy() != null && !realm.getAccountPolicy().getResources().isEmpty()) { if (result == null) { result = realm.getAccountPolicy().getResources(); } else { result.retainAll(realm.getAccountPolicy().getResources()); } } } return SetUtils.emptyIfNull(result); }
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private void saveReference(boolean mustSupportEvaluation, boolean includeEvaluation) throws FileNotFoundException { Set<ReferenceFormat> formats = mustSupportEvaluation ? ReferenceFormats.REFERENCE_FORMATS.evaluationIncludingFormats : ReferenceFormats.REFERENCE_FORMATS.formats; formats.retainAll(ReferenceFormats.REFERENCE_FORMATS.writeableFormats); ReferenceFormat format = formatChooser(formats); if (format == null) { return;/*from ww w . j a va 2 s.c o m*/ } JFileChooser chooser = new JFileChooser("Save reference. Please choose a file."); chooser.setCurrentDirectory(frame.defaultDirectory); chooser.setFileSelectionMode( format.readsDirectory() ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY); if (format.getFileExtension() != null) { chooser.addChoosableFileFilter( new FilesystemFilter(format.getFileExtension(), format.getDescription())); } else { chooser.setAcceptAllFileFilterUsed(true); } int returnVal = chooser.showSaveDialog(frame); if (returnVal != JFileChooser.APPROVE_OPTION) return; System.out.print("Saving..."); format.writeReference(frame.reference, chooser.getSelectedFile(), includeEvaluation); //frame.loadPositiveNegativeNT(chooser.getSelectedFile()); System.out.println("saving finished."); }