Example usage for com.google.common.collect Sets filter

List of usage examples for com.google.common.collect Sets filter

Introduction

In this page you can find the example usage for com.google.common.collect Sets filter.

Prototype

@GwtIncompatible("NavigableSet")
@SuppressWarnings("unchecked")
@CheckReturnValue
public static <E> NavigableSet<E> filter(NavigableSet<E> unfiltered, Predicate<? super E> predicate) 

Source Link

Document

Returns the elements of a NavigableSet , unfiltered , that satisfy a predicate.

Usage

From source file:pl.kodujdlapolski.na4lapy.utils.formvalidator.FormValidator.java

private Set<Rule> getErrorFields() {
    return Sets.filter(form, r -> !r.validate());
}

From source file:com.beligum.core.repositories.UserRepository.java

public static User find(final long id) throws PersistenceException {
    try {//from w ww  .  j a  va  2s .  co m
        ArrayList<User> userArrayList = newArrayList(Sets.filter(users, new Predicate<User>() {
            @Override
            public boolean apply(User user) {
                return user.getId() == id;
            }
        }));

        return userArrayList.get(0);
    } catch (Exception e) {
        Logger.error("Caught error while searching a user", e);
        throw new PersistenceException(e);
    }
}

From source file:org.eclipse.sirius.editor.tools.internal.menu.refactoring.RefactoringMenu.java

private Collection generateRefactoringActions(final ISelection selection, final IEditorPart editor) {

    // We first build all candidate Actions
    Set<AbstractEObjectRefactoringAction> allActions = Sets.newLinkedHashSet();
    allActions.add(new MaterializeTemplateRefactoring(editor, selection));

    // We only add to the menu the actions that have a valid selection
    return Sets.filter(allActions, new Predicate<AbstractEObjectRefactoringAction>() {

        public boolean apply(AbstractEObjectRefactoringAction candidateAction) {
            return candidateAction.isSelectionValid();
        }//from  w  ww . ja v a 2s  . com
    });
}

From source file:org.n52.iceland.util.activation.Activatables.java

public static <K, T> Set<K> activatedKeys(Map<K, T> map, ActivationProvider<? super K> provider) {
    return Sets.filter(map.keySet(), asPredicate(provider));
}

From source file:com.pandich.dropwizard.curator.refresh.CuratorRefresherManager.java

private static void initialSetup(final List<Class<? extends CuratorRootConfiguration>> configurationClasses,
        final Refresher<Field> fieldRefresher, final Refresher<Method> methodRefresher) throws Exception {

    for (final Class<? extends CuratorRootConfiguration> configurationClass : configurationClasses) {

        log.debug("configuration class: {}", configurationClass.getSimpleName());

        final Reflections fieldReflections = new Reflections(configurationClass, new FieldAnnotationsScanner());
        for (final Field field : Sets.filter(fieldReflections.getFieldsAnnotatedWith(CuratorInject.class),
                fieldIsValid)) {//  www.j  a v  a2s  .c  o  m
            fieldRefresher.refresh(configurationClass, field);
        }

        final Reflections methodReflections = new Reflections(configurationClass,
                new MethodAnnotationsScanner());
        for (final Method method : Sets.filter(methodReflections.getMethodsAnnotatedWith(CuratorInject.class),
                methodIsValid)) {
            methodRefresher.refresh(configurationClass, method);
        }

    }

    if (log.isDebugEnabled()) {
        for (final Map.Entry<Class, ConcurrentMap<String, PropertySource>> classEntry : fieldRefresher.propertySources) {
            for (final Map.Entry<String, PropertySource> propertyEntry : classEntry.getValue().entrySet()) {
                log.debug("source: {}.{}={}",
                        new Object[] { classEntry.getKey(), propertyEntry.getKey(), propertyEntry.getValue() });
            }
        }
        for (final Map.Entry<Class, ConcurrentMap<String, PropertySource>> classEntry : methodRefresher.propertySources) {
            for (final Map.Entry<String, PropertySource> propertyEntry : classEntry.getValue().entrySet()) {
                log.debug("source: {}.{}({})",
                        new Object[] { classEntry.getKey(), propertyEntry.getKey(), propertyEntry.getValue() });
            }
        }
    }
}

From source file:com.google.enterprise.connector.pusher.AclInheritFromDocidFilter.java

@Override
public Set<String> getPropertyNames(Document source) throws RepositoryException {
    return Sets.union(Sets.filter(source.getPropertyNames(), propsPredicate),
            Sets.<String>newHashSet(SpiConstants.PROPNAME_ACLINHERITFROM));
}

From source file:org.fenixedu.qubdocs.domain.DocumentPrinterConfiguration.java

@Override
public Set<? extends DocumentTemplate> readActiveDocuments() {
    return Sets.filter(readAllDocuments(), DocumentTemplate.filters.active(true));
}

From source file:hu.bme.mit.incqueryd.engine.rete.nodes.TypeInputNode.java

public ChangeSet filter(Predicate<Tuple> predicate) {
    Set<Tuple> remainingTuples = Sets.newHashSet(Sets.filter(tuples, predicate));
    Set<Tuple> removedTuples = Sets.newHashSet(Sets.difference(tuples, remainingTuples));
    tuples = remainingTuples;//from   w  ww.  jav a 2s .  c  o m
    return new ChangeSet(removedTuples, ChangeType.NEGATIVE);
}

From source file:org.eclipse.sirius.diagram.editor.tools.internal.menu.refactoring.DiagramRefactoringMenu.java

private Collection generateRefactoringActions(final ISelection selection, final IEditorPart editor) {

    // We first build all candidate Actions
    Set<AbstractEObjectRefactoringAction> allActions = Sets.newLinkedHashSet();
    allActions.add(new BorderRefactoringAction(editor, selection));
    allActions.add(new EdgeMappingRefactoringAction(editor, selection));

    // We only add to the menu the actions that have a valid selection
    return Sets.filter(allActions, new Predicate<AbstractEObjectRefactoringAction>() {

        public boolean apply(AbstractEObjectRefactoringAction candidateAction) {
            return candidateAction.isSelectionValid();
        }/*from  w w  w  . ja  va  2  s. c  o m*/
    });
}

From source file:dtos.conversion.ConverterModule.java

/**
 * Uses reflections (org.reflections) to load all classes implementing
 * a dto converter./*from   ww w. j a  v  a 2 s.c o  m*/
 * <p>
 * Note: to be able to resolve the transitive dependency DtoConverter - AbstractConverter - Concrete Converter
 * we first need to include the complete conversion package.
 * <p>
 * Afterwards we filter the found converters to only find concrete ones....
 */
@Override
protected void configure() {
    Multibinder<DtoConverter> converterBinder = Multibinder.newSetBinder(binder(), DtoConverter.class);

    for (Class<? extends DtoConverter> converterClass : Sets.filter(findConverters(), new ClassFilter())) {
        converterBinder.addBinding().to(converterClass);
    }
}