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:dynamicrefactoring.domain.metadata.classifications.xml.imp.PluginClassificationsCatalog.java

/**
 * Devuelve todas las clasificaciones que son de usuario, es decir, que se
 * pueden editar.//from  w w w  .  ja  v a 2 s  .  co  m
 * 
 * @return devuelve las clasificaciones del catalogo que son de usuario y
 *         por tanto se pueden editar
 */
private Set<Classification> getUserClassifications() {
    return Sets.filter(getAllClassifications(), new Predicate<Classification>() {

        @Override
        public boolean apply(Classification arg0) {
            return arg0.isEditable();
        }

    });
}

From source file:org.apache.whirr.Cluster.java

public Instance getInstanceMatching(Predicate<Instance> predicate) {
    return Iterables.getOnlyElement(Sets.filter(instances, predicate));
}

From source file:com.google.gerrit.server.account.AccountControl.java

private Set<AccountGroup.UUID> groupsOf(IdentifiedUser user) {
    return new HashSet<>(
            Sets.filter(user.getEffectiveGroups().getKnownGroups(), new Predicate<AccountGroup.UUID>() {
                @Override/*from  ww  w  .j a  v  a  2  s  . c om*/
                public boolean apply(AccountGroup.UUID in) {
                    return !SystemGroupBackend.isSystemGroup(in);
                }
            }));
}

From source file:gov.nih.nci.firebird.selenium2.pages.investigator.protocol.registration.SignedDocumentsTableHelper.java

private Set<AbstractRegistrationForm> getExpectedForms(AbstractRegistration registration) {
    return Sets.filter(registration.getForms(), new Predicate<AbstractRegistrationForm>() {
        @Override//from   w ww  .  jav a  2s  . co m
        public boolean apply(AbstractRegistrationForm form) {
            return form.isSignable();
        }
    });
}

From source file:org.apache.whirr.Cluster.java

public Set<Instance> getInstancesMatching(Predicate<Instance> predicate) {
    return Sets.filter(instances, predicate);
}

From source file:org.apache.whirr.Cluster.java

public void removeInstancesMatching(Predicate<Instance> predicate) {
    instances = Sets.filter(instances, Predicates.not(predicate));
}

From source file:com.android.ide.common.rendering.LayoutLibrary.java

/**
 * Loads the layoutlib.jar file located at the given path and returns a {@link LayoutLibrary}
 * object representing the result./* w w w. jav a2  s .co m*/
 * <p>
 * If loading failed {@link #getStatus()} will reflect this, and {@link #mBridge} will
 * be null.
 *
 * @param layoutLibJarOsPath the path of the jar file
 * @param log an optional log file.
 * @return a {@link LayoutLibrary} object always.
 */
public static LayoutLibrary load(String layoutLibJarOsPath, ILogger log, String toolName) {

    LoadStatus status = LoadStatus.LOADING;
    String message = null;
    Bridge bridge = null;
    ILayoutBridge legacyBridge = null;
    ClassLoader classLoader = null;

    try {
        // get the URL for the file.
        File f = new File(layoutLibJarOsPath);
        if (f.isFile() == false) {
            if (log != null) {
                log.error(null, "layoutlib.jar is missing!"); //$NON-NLS-1$
            }
        } else {
            URL[] urls;
            // TODO: The icu jar has to be in the same location as layoutlib.jar. Get rid of
            // this dependency.
            File icu4j = new File(f.getParent(), FN_ICU_JAR);
            if (icu4j.isFile()) {
                urls = new URL[2];
                urls[1] = SdkUtils.fileToUrl(icu4j);
            } else {
                urls = new URL[1];
            }
            urls[0] = SdkUtils.fileToUrl(f);

            final Set<String> jarClasses = Sets.filter(getJarClasses(urls), new Predicate<String>() {
                @Override
                public boolean apply(String input) {
                    // Filter kxml classes (so we use the ones in studio) and the inner classes. The inner classes will be filtered by
                    // using the parent class name.
                    return !input.startsWith("org.xmlpull.v1") && !input.contains("$");
                }
            });
            classLoader = new FilteredClassLoader(LayoutLibrary.class.getClassLoader(), jarClasses);

            // create a class loader. Because this jar reference interfaces
            // that are in the editors plugin, it's important to provide
            // a parent class loader.
            classLoader = new URLClassLoader(urls, classLoader);

            // load the class
            Class<?> clazz = classLoader.loadClass(CLASS_BRIDGE);
            if (clazz != null) {
                // instantiate an object of the class.
                Constructor<?> constructor = clazz.getConstructor();
                if (constructor != null) {
                    Object bridgeObject = constructor.newInstance();
                    if (bridgeObject instanceof Bridge) {
                        bridge = (Bridge) bridgeObject;
                    } else if (bridgeObject instanceof ILayoutBridge) {
                        legacyBridge = (ILayoutBridge) bridgeObject;
                    }
                }
            }

            if (bridge == null && legacyBridge == null) {
                status = LoadStatus.FAILED;
                message = "Failed to load " + CLASS_BRIDGE; //$NON-NLS-1$
                if (log != null) {
                    log.error(null, "Failed to load " + //$NON-NLS-1$
                            CLASS_BRIDGE + " from " + //$NON-NLS-1$
                            layoutLibJarOsPath);
                }
            } else {
                // mark the lib as loaded, unless it's overridden below.
                status = LoadStatus.LOADED;

                // check the API, only if it's not a legacy bridge
                if (bridge != null) {
                    int api = bridge.getApiLevel();
                    if (api > Bridge.API_CURRENT) {
                        status = LoadStatus.FAILED;
                        message = String.format(
                                "This version of the rendering library is more recent than your version of %1$s. Please update %1$s",
                                toolName);
                    }
                }
            }
        }
    } catch (Throwable t) {
        status = LoadStatus.FAILED;
        Throwable cause = t;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        message = "Failed to load the LayoutLib: " + cause.getMessage();
        // log the error.
        if (log != null) {
            log.error(t, message);
        }
    }

    return new LayoutLibrary(bridge, legacyBridge, classLoader, status, message);
}

From source file:com.nomsic.sid.Sid.java

/**
 * //from   w  w  w. j  a  v a  2 s.c  o  m
 * @param thresholdSq
 * @return
 * @throws IOException
 */
public List<Match> getMatches(final double thresholdSq) throws IOException {

    if (recordSets == null) {
        Preconditions.checkNotNull(recordFile);
        FieldRecordProcessor processor = new FieldRecordProcessor();
        processor.setIgnoreFirstLine(ignoreFirstLine);
        recordSets = Files.readLines(recordFile, Charset.defaultCharset(), processor);
    }

    @SuppressWarnings("unchecked")
    Map<SortedSet<String>, Integer> recordSetCardinalityMap = CollectionUtils.getCardinalityMap(recordSets);

    buildRecordSimsetMap(recordSetCardinalityMap);
    buildRecordFieldCountMap();

    Set<Match> matches = computeMatches();
    matches = Sets.filter(matches, new Predicate<Match>() {
        @Override
        public boolean apply(Match m) {
            return m.getSimilarityIndex() > thresholdSq;
        }
    });
    ArrayList<Match> matchList = Lists.newArrayList();
    matchList.addAll(matches);
    Collections.sort(matchList, new Comparator<Match>() {
        @Override
        public int compare(Match o1, Match o2) {
            return o2.getSimilarityIndex().compareTo(o1.getSimilarityIndex());
        }
    });
    return matchList;
}

From source file:npanday.resolver.DefaultNPandayArtifactResolver.java

private void addContributeArtifactsToDependenciesCache(Set<Artifact> artifacts) {
    if (artifacts == null || artifacts.isEmpty()) {
        return;//  w ww .ja v a  2 s  .c om
    }

    Set<Artifact> resolvedArtifacts = Sets.filter(artifacts, new Predicate<Artifact>() {
        public boolean apply(@Nullable Artifact artifact) {
            return artifact != null && artifact.isResolved() && artifact.getFile() != null
                    && artifact.getFile().exists();
        }
    });

    customDependenciesCache.addAll(resolvedArtifacts);
}

From source file:co.cask.cdap.data2.transaction.stream.AbstractStreamFileAdmin.java

@Override
public void configureGroups(QueueName name, Map<Long, Integer> groupInfo) throws Exception {
    Preconditions.checkArgument(name.isStream(), "The {} is not stream.", name);
    Preconditions.checkArgument(!groupInfo.isEmpty(), "Consumer group information must not be empty.");

    LOG.info("Configure groups for {}: {}", name, groupInfo);

    StreamConfig config = StreamUtils.ensureExists(this, name.getSimpleName());
    StreamConsumerStateStore stateStore = stateStoreFactory.create(config);
    try {//from   ww w  .j av a 2s.  co  m
        Set<StreamConsumerState> states = Sets.newHashSet();
        stateStore.getAll(states);

        // Remove all groups that are no longer exists. The offset information in that group can be discarded.
        Set<StreamConsumerState> removeStates = Sets.newHashSet();
        for (StreamConsumerState state : states) {
            if (!groupInfo.containsKey(state.getGroupId())) {
                removeStates.add(state);
            }
        }

        // For each groups, compute the new file offsets if needed
        Set<StreamConsumerState> newStates = Sets.newHashSet();
        for (Map.Entry<Long, Integer> entry : groupInfo.entrySet()) {
            final long groupId = entry.getKey();

            // Create a view of old states which match with the current groupId only.
            mutateStates(groupId, entry.getValue(), Sets.filter(states, new Predicate<StreamConsumerState>() {
                @Override
                public boolean apply(StreamConsumerState state) {
                    return state.getGroupId() == groupId;
                }
            }), newStates, removeStates);
        }

        // Save the states back
        if (!newStates.isEmpty()) {
            stateStore.save(newStates);
            LOG.info("Configure groups new states: {} {}", groupInfo, newStates);
        }
        if (!removeStates.isEmpty()) {
            stateStore.remove(removeStates);
            LOG.info("Configure groups remove states: {} {}", groupInfo, removeStates);
        }

    } finally {
        stateStore.close();
    }

    // Also configure the old stream if it exists
    if (oldStreamAdmin.exists(name.toURI().toString())) {
        oldStreamAdmin.configureGroups(name, groupInfo);
    }
}