Example usage for com.google.common.collect Iterables removeIf

List of usage examples for com.google.common.collect Iterables removeIf

Introduction

In this page you can find the example usage for com.google.common.collect Iterables removeIf.

Prototype

public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate) 

Source Link

Document

Removes, from an iterable, every element that satisfies the provided predicate.

Usage

From source file:org.artifactory.storage.service.StorageServiceImpl.java

private void filterGlobalRepoIfNeeded(Set<RepoStorageSummary> summaries) {
    if (ConstantValues.disableGlobalRepoAccess.getBoolean()) {
        Iterables.removeIf(summaries, new Predicate<RepoStorageSummary>() {
            @Override//from  w ww  . j ava 2 s .c  om
            public boolean apply(RepoStorageSummary summary) {
                return VirtualRepoDescriptor.GLOBAL_VIRTUAL_REPO_KEY.equals(summary.getRepoKey());
            }
        });
    }
}

From source file:io.motown.operatorapi.viewmodel.ChargingStationEventListener.java

/**
 * Updates the local representation of the charging station authorization list.
 * Tokens in the updatedIdentificationTokens will be removed from the local operator api list.
 *
 * @param chargingStation               the chargingstation.
 * @param updatedLocalAuthorizations    the updated tokens.
 *//*from  w ww. j a  v a 2  s  .  co m*/
private void updateAuthorizationList(final ChargingStation chargingStation,
        final Set<LocalAuthorization> updatedLocalAuthorizations) {
    Set<LocalAuthorization> authorizationList = chargingStation.getLocalAuthorizations();
    Iterables.removeIf(authorizationList, new Predicate<LocalAuthorization>() {
        @Override
        public boolean apply(@Nullable LocalAuthorization identifyingToken) {
            return updatedLocalAuthorizations != null && updatedLocalAuthorizations.contains(identifyingToken);
        }
    });

    authorizationList.addAll(updatedLocalAuthorizations);
}

From source file:org.richfaces.component.AbstractTree.java

@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
    super.broadcast(event);

    if (event instanceof TreeSelectionChangeEvent) {
        TreeSelectionChangeEvent selectionEvent = (TreeSelectionChangeEvent) event;

        final Collection<Object> newSelection = selectionEvent.getNewSelection();

        Collection<Object> selectionCollection = getSelection();

        Iterables.removeIf(selectionCollection, new Predicate<Object>() {
            public boolean apply(Object input) {
                return !newSelection.contains(input);
            }/*from  w w w .jav a2  s. c  om*/

            ;
        });

        if (!newSelection.isEmpty()) {
            Iterables.addAll(selectionCollection, newSelection);
        }
    } else if (event instanceof TreeToggleEvent) {
        TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
        AbstractTreeNode treeNodeComponent = findTreeNodeComponent();

        boolean newExpandedValue = toggleEvent.isExpanded();

        FacesContext context = getFacesContext();
        ValueExpression expression = treeNodeComponent
                .getValueExpression(AbstractTreeNode.PropertyKeys.expanded.toString());
        if (expression != null) {
            ELContext elContext = context.getELContext();
            Exception caught = null;
            FacesMessage message = null;
            try {
                expression.setValue(elContext, newExpandedValue);
            } catch (ELException e) {
                caught = e;
                String messageStr = e.getMessage();
                Throwable result = e.getCause();
                while (null != result && result.getClass().isAssignableFrom(ELException.class)) {
                    messageStr = result.getMessage();
                    result = result.getCause();
                }
                if (null == messageStr) {
                    MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
                    message = messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
                            MessageUtil.getLabel(context, this));
                } else {
                    message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr);
                }
            } catch (Exception e) {
                caught = e;
                MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
                message = messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
                        MessageUtil.getLabel(context, this));
            }
            if (caught != null) {
                assert (message != null);
                UpdateModelException toQueue = new UpdateModelException(message, caught);
                ExceptionQueuedEventContext eventContext = new ExceptionQueuedEventContext(context, toQueue,
                        this, PhaseId.UPDATE_MODEL_VALUES);
                context.getApplication().publishEvent(context, ExceptionQueuedEvent.class, eventContext);
            }
        } else {
            treeNodeComponent.setExpanded(newExpandedValue);
        }
    }
}

From source file:org.opentestsystem.authoring.testauth.publish.SharedPublisherHelper.java

private List<TestComputationRule> buildTestComputationRulesForLevelRules(
        final List<ScoringRule> scoringRuleList, final List<BlueprintElement> blueprintElementList) {
    final List<TestComputationRule> testComputationRuleList = Lists.newArrayList();
    if (Iterables.any(scoringRuleList, LEVEL_TYPE_FILTER)) {

        // construct each leaf node into a separate scoring rule
        final List<ScoringRule> levelScoringRules = Lists
                .newArrayList(Iterables.filter(scoringRuleList, LEVEL_TYPE_FILTER));
        for (final ScoringRule scoringRule : levelScoringRules) {
            final int i = 1;
            // winnow blueprintElement list down to matching levels only
            Iterables.removeIf(blueprintElementList,
                    Predicates.not(LEVEL_FILTER.getInstance(scoringRule.getBlueprintReferenceId())));
            // transform every leaf node bp element into a scoring rule mimicking this scoringRule
            testComputationRuleList.addAll(Lists.transform(blueprintElementList,
                    LEAF_NODE_LEVEL_SCORING_RULE_TRANSFORMER.getInstance(scoringRule, i)));
        }/*  w ww.j a  v  a  2  s.c  o  m*/
    }
    return testComputationRuleList;
}

From source file:org.artifactory.repo.index.MavenIndexerServiceImpl.java

private Set<? extends RepoDescriptor> calcSpecificRepoForIndexing(@Nullable final List<String> repoKeys) {
    Set<RepoBaseDescriptor> excludedRepos = Sets.newHashSet();
    excludedRepos.addAll(repositoryService.getLocalRepoDescriptors());
    excludedRepos.addAll(repositoryService.getRemoteRepoDescriptors());
    excludedRepos.addAll(getAllVirtualReposExceptGlobal());
    if ((repoKeys != null) && !repoKeys.isEmpty()) {
        Iterables.removeIf(excludedRepos, new Predicate<RepoBaseDescriptor>() {
            @Override//  ww  w  .  j a va 2s .  c  o  m
            public boolean apply(@Nullable RepoBaseDescriptor repoBaseDescriptor) {
                if (repoBaseDescriptor == null) {
                    return false;
                }
                return repoKeys.contains(repoBaseDescriptor.getKey());
            }
        });
    }

    return excludedRepos;
}

From source file:it.f2informatica.core.gateway.mysql.ConsultantRepositoryGatewayMySQL.java

private void removeLanguagesThatMustNotBeInDBAnymore(Consultant consultant,
        final List<LanguageModel> languageModels) {
    Iterables.removeIf(consultant.getLanguages(), new Predicate<Language>() {
        @Override//from www.j a  v  a  2  s .c  o m
        public boolean apply(Language language) {
            LanguageModel languageModel = mysqlLanguageToModelConverter.convert(language);
            return !languageModels.contains(languageModel);
        }
    });
}

From source file:it.f2informatica.core.gateway.mysql.ConsultantRepositoryGatewayMySQL.java

private void removeLanguagesThatAlreadyExistInDB(final String consultantId,
        List<LanguageModel> languageModels) {
    Iterables.removeIf(languageModels, new Predicate<LanguageModel>() {
        @Override/* w w  w . j av  a2s  . c om*/
        public boolean apply(LanguageModel languageModel) {
            List<LanguageModel> languages = mysqlLanguageToModelConverter
                    .convertList(languageRepository.findByConsultantId(Long.parseLong(consultantId)));
            return languages.contains(languageModel);
        }
    });
}

From source file:org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.java

private Iterable<URL> sanitizeCP(Iterable<URL> baseClassPathForScanning) {
    /*//ww  w  .  j  av  a2 s.  c  om
    If Brooklyn is being run via apache daemon[1], and the classpath contains the contents of an empty folder,
    (e.g. xxx:lib/patch/*:xxx) the classpath will be incorrectly expanded to include a zero-length string
    (e.g. xxx::xxx), which is then interpreted by {@link org.reflections.Reflections#scan} as the root of the
    file system. See [2], line 90+. This needs to be removed, lest we attempt to scan the entire filesystem
            
    [1]: http://commons.apache.org/proper/commons-daemon/
    [2]: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/arguments.c?view=markup&pathrev=1196468
     */
    Iterables.removeIf(baseClassPathForScanning, new Predicate<URL>() {
        @Override
        public boolean apply(@Nullable URL url) {
            return Strings.isEmpty(url.getFile()) || "/".equals(url.getFile());
        }
    });
    return baseClassPathForScanning;
}

From source file:it.f2informatica.core.gateway.mysql.ConsultantRepositoryGatewayMySQL.java

private void removeSkillsThatMustNotBeInDBAnymore(Consultant consultant, final Set<String> skills) {
    Iterables.removeIf(consultant.getSkills(), new Predicate<Skill>() {
        @Override//w  w  w.  ja va 2  s  . com
        public boolean apply(Skill skill) {
            return !skills.contains(skill.getId().getSkill());
        }
    });
}

From source file:it.f2informatica.core.gateway.mysql.ConsultantRepositoryGatewayMySQL.java

private void removeSkillsThatAlreadyExistInDB(final Set<String> skills) {
    Iterables.removeIf(skills, new Predicate<String>() {
        @Override/*from  w ww  .  j av  a2  s  . co  m*/
        public boolean apply(String skill) {
            return skillRepository.findByIdSkill(skill) != null;
        }
    });
}