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:dk.dma.ais.tracker.ScenarioTracker.java

/**
 * Return all targets involved in this scenario and with a known location (ie. located inside of the bounding box).
 * @return//  w ww .j a v  a2s  .c o  m
 */
public Set<Target> getTargetsHavingPositionUpdates() {
    return Sets.filter(getTargets(), new com.google.common.base.Predicate<Target>() {
        @Override
        public boolean apply(@Nullable Target target) {
            return target.hasPosition();
        }
    });
}

From source file:com.strandls.alchemy.rest.client.stubgenerator.RestProxyGenerator.java

/**
 * @return the rest webservice classes to process.
 * @throws MalformedURLException/*from  w w w .j a va2 s. co m*/
 */
private Set<Class<?>> findServiceClasses() {
    final List<Object> params = new ArrayList<Object>();
    final ClassLoader loader = getClass().getClassLoader();
    if (loader instanceof AntClassLoader) {
        final String[] path = ((AntClassLoader) loader).getClasspath()
                .split(System.getProperty("path.separator"));
        for (final String string : path) {
            try {
                params.add(new URL(string));
            } catch (final MalformedURLException e) {
                try {
                    params.add(new URL("file://" + string));
                } catch (final MalformedURLException e1) {
                    throw new RuntimeException(e1);
                }
            }
        }

    }

    final Reflections reflections = new Reflections(params.toArray(new Object[0]));
    final Set<Class<?>> allRestServices = reflections.getTypesAnnotatedWith(Path.class);
    log("Locating service classes", Project.MSG_ERR);

    final Set<Class<?>> filtered = Sets.filter(allRestServices, new Predicate<Class<?>>() {
        @Override
        public boolean apply(final Class<?> input) {
            return doesMatch(input, includes) && !doesMatch(input, excludes);
        }

        /**
         * Indicates if the input class matches any one of the comma
         * separated regex patterns.
         *
         * <code>null</code> or empty pattern implies no match.
         *
         * @param input
         *            the input class.
         * @param patterns
         *            comma separated list of patterns.
         *
         * @return <code>true</code> if any one of the pattern matches the
         *         canonical name of the class.
         */
        private boolean doesMatch(final Class<?> input, final String patterns) {
            boolean matches = false;
            if (patterns != null) {
                for (final String include : patterns.split("\\s*,\\s*")) {
                    matches |= Pattern.matches(include, input.getCanonicalName());
                }
            }
            return matches;
        }
    });

    for (final Class<?> klass : filtered) {
        log("Will process class: " + klass.getCanonicalName(), Project.MSG_ERR);
    }

    return filtered;
}

From source file:org.tzi.use.uml.sys.MLinkSet.java

/**
 * Selects all links whose link ends at <code>aend</code> connect
 * <code>obj</code> with the given qualifier values.
 * The set is immutable./*  ww  w .  j a  v  a2 s.co  m*/
 *
 * @return An unmodifiable <code>Set</code> of the corresponding links. 
 */
Set<MLink> select(MAssociationEnd aend, MObject obj, List<Value> qualifierValues, boolean excludeDerived) {
    CacheEntry e = new CacheEntry(aend, obj, qualifierValues);
    Set<MLink> res = selectCache.get(e);

    if (res == null)
        return Collections.emptySet();

    if (excludeDerived) {
        return Sets.filter(res, new Predicate<MLink>() {
            public boolean apply(MLink l) {
                return !l.isVirtual();
            }
        });
    } else {
        return Collections.unmodifiableSet(res);
    }
}

From source file:gobblin.runtime.template.InheritingJobTemplate.java

@Override
public Collection<String> getRequiredConfigList() throws SpecNotFoundException, TemplateException {
    ensureTemplatesResolved();//from w  w w .  j a v a 2 s  . com
    Set<String> allRequired = getRequiredConfigListHelper(Sets.<JobTemplate>newHashSet());
    final Config rawConfig = getRawTemplateConfig();

    Set<String> filteredRequired = Sets.filter(allRequired, new Predicate<String>() {
        @Override
        public boolean apply(String input) {
            return !rawConfig.hasPath(input);
        }
    });

    return filteredRequired;
}

From source file:com.facebook.buck.swift.SwiftLibraryDescription.java

@Override
public boolean hasFlavors(ImmutableSet<Flavor> flavors) {
    ImmutableSet<Flavor> currentUnsupportedFlavors = ImmutableSet
            .copyOf(Sets.filter(flavors, Predicates.not(SUPPORTED_FLAVORS::contains)));
    if (currentUnsupportedFlavors.isEmpty()) {
        return true;
    }/*w w  w  .  j  av  a  2  s .com*/
    return cxxPlatformFlavorDomain.containsAnyOf(flavors);
}

From source file:org.spka.cursus.test.AbstractSPKASeries.java

/**
 * Get all the events up to and and including the specified event
 *///from   ww  w. j  a  v  a2 s .com
protected static Set<Event> getSeriesResultsEvents(Series series, final Event event) {
    return Sets.filter(Sets.newHashSet(series.getEvents()), new Predicate<Event>() {
        @Override
        public boolean apply(@Nonnull Event event_) {
            return (event_.compareTo(event) <= 0);
        }
    });
}

From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java

public Set<Storage> internalEdges() {
    return Sets.filter(allEdges(), Storage::isInternal);
}

From source file:org.voltcore.messaging.SiteFailureMessage.java

public Set<Long> getObservedFailedSites() {
    return Sets.filter(m_failed, not(in(m_survivors)));
}

From source file:org.gradle.plugins.ide.eclipse.EclipsePlugin.java

private void registerEclipseArtifacts() {
    Set<Project> projectsWithEclipse = Sets.filter(project.getRootProject().getAllprojects(),
            HAS_ECLIPSE_PLUGIN);/*from www. j a  v  a 2  s.c  o  m*/
    for (Project project : projectsWithEclipse) {
        registerEclipseArtifacts(project);
    }
}

From source file:com.xebialabs.overtherepy.DirectoryDiff.java

private List<OverthereFile[]> compareDirectory(OverthereFile left, OverthereFile right,
        DirectoryChangeSet changeSet) throws IOException {
    Set<FileWrapper> leftFiles = listFiles(left);
    Set<FileWrapper> rightFiles = listFiles(right);

    //find new files
    Set<FileWrapper> filesAdded = Sets.difference(rightFiles, leftFiles);
    //find removed files
    Set<FileWrapper> filesRemoved = Sets.difference(leftFiles, rightFiles);

    //find changed files
    Set<FileWrapper> potentialChangedFiles = newHashSet(leftFiles);
    potentialChangedFiles.removeAll(filesRemoved);

    //filter out directories
    Map<FileWrapper, FileWrapper> rightFilesIndex = newHashMap();
    for (FileWrapper file : rightFiles) {
        rightFilesIndex.put(file, file);
    }//from  w w  w  .ja  va 2  s. co  m

    Set<FileWrapper> filesChanged = newHashSet();
    for (FileWrapper potentialChangedFile : Sets.filter(potentialChangedFiles, FileWrapperPredicates.FILE)) {
        HashCode leftHash = hash(potentialChangedFile.getFile(), hashFunction);
        FileWrapper rightFile = rightFilesIndex.get(potentialChangedFile);
        HashCode rightHash = hash(rightFile.getFile(), hashFunction);
        if (!leftHash.equals(rightHash)) {
            filesChanged.add(rightFile);
        }
    }

    Function<FileWrapper, OverthereFile> unwrapFunction = new Function<FileWrapper, OverthereFile>() {
        @Override
        public OverthereFile apply(final FileWrapper input) {
            return input.getFile();
        }
    };

    changeSet.getRemoved().addAll(Collections2.transform(filesRemoved, unwrapFunction));
    changeSet.getAdded().addAll(Collections2.transform(filesAdded, unwrapFunction));
    changeSet.getChanged().addAll(Collections2.transform(filesChanged, unwrapFunction));

    Set<FileWrapper> potentialChangedDirectories = Sets.filter(potentialChangedFiles,
            FileWrapperPredicates.DIRECTORY);
    List<OverthereFile[]> directoriesStillToCheck = newArrayList();
    for (FileWrapper potentialChangedDirectory : potentialChangedDirectories) {
        directoriesStillToCheck.add(new OverthereFile[] { potentialChangedDirectory.getFile(),
                rightFilesIndex.get(potentialChangedDirectory).getFile() });
    }
    return directoriesStillToCheck;
}