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:org.easyrec.store.dao.core.types.impl.ItemTypeDAOMysqlImpl.java

@LongCacheable
@Override/*from  ww w .j  a va 2  s  .  c o m*/
public Set<String> getTypes(Integer tenantId, Boolean visible) {
    Preconditions.checkNotNull(tenantId, "missing constraints: missing 'tenantId'");

    ResultSetExtractor<Set<String>> rse = new ResultSetExtractor<Set<String>>() {
        public Set<String> extractData(ResultSet rs) {
            Set<String> types = new TreeSet<>();
            try {
                while (rs.next()) {
                    types.add(DaoUtils.getStringIfPresent(rs, DEFAULT_NAME_COLUMN_NAME));
                }
                return types;
            } catch (SQLException e) {
                logger.error("error occured", e);
                throw new RuntimeException(e);
            }
        }
    };

    Object[] args = { tenantId };
    int[] argTypes = { Types.INTEGER };

    StringBuilder sqlQuery = new StringBuilder("SELECT ");
    sqlQuery.append(DEFAULT_NAME_COLUMN_NAME);
    sqlQuery.append(" FROM ");
    sqlQuery.append(DEFAULT_TABLE_NAME);
    sqlQuery.append(" WHERE ");
    sqlQuery.append(DEFAULT_TENANT_COLUMN_NAME);
    sqlQuery.append("=?");

    if (visible != null) {
        sqlQuery.append(" AND ").append(DEFAULT_VISIBLE_COLUMN_NAME).append("=?");

        args = ObjectArrays.concat(args, visible);
        argTypes = Ints.concat(argTypes, new int[] { Types.BIT });
    }

    sqlQuery.append(" ORDER BY ");
    sqlQuery.append(DEFAULT_NAME_COLUMN_NAME);

    Set<String> result = Sets
            .newTreeSet(getJdbcTemplate().queryForList(sqlQuery.toString(), args, argTypes, String.class));

    return Sets.newTreeSet(Sets.filter(result, Predicates.notNull()));
}

From source file:com.datatorrent.stram.webapp.OperatorDiscoverer.java

public Set<String> getOperatorClasses(String parent, String searchTerm) throws ClassNotFoundException {
    if (CollectionUtils.isEmpty(operatorClassNames)) {
        loadOperatorClass();/*  ww  w .ja v  a 2 s  .  c  o m*/
    }
    if (parent == null) {
        parent = Operator.class.getName();
    } else {
        if (!typeGraph.isAncestor(Operator.class.getName(), parent)) {
            throw new IllegalArgumentException("Argument must be a subclass of Operator class");
        }
    }

    Set<String> filteredClass = Sets.filter(operatorClassNames, new Predicate<String>() {
        @Override
        public boolean apply(String className) {
            OperatorClassInfo oci = classInfo.get(className);
            return oci == null || !oci.tags.containsKey("@omitFromUI");
        }
    });

    if (searchTerm == null && parent.equals(Operator.class.getName())) {
        return filteredClass;
    }

    if (searchTerm != null) {
        searchTerm = searchTerm.toLowerCase();
    }

    Set<String> result = new HashSet<String>();
    for (String clazz : filteredClass) {
        if (parent.equals(Operator.class.getName()) || typeGraph.isAncestor(parent, clazz)) {
            if (searchTerm == null) {
                result.add(clazz);
            } else {
                if (clazz.toLowerCase().contains(searchTerm)) {
                    result.add(clazz);
                } else {
                    OperatorClassInfo oci = classInfo.get(clazz);
                    if (oci != null) {
                        if (oci.comment != null && oci.comment.toLowerCase().contains(searchTerm)) {
                            result.add(clazz);
                        } else {
                            for (Map.Entry<String, String> entry : oci.tags.entrySet()) {
                                if (entry.getValue().toLowerCase().contains(searchTerm)) {
                                    result.add(clazz);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}

From source file:org.apache.jackrabbit.oak.plugins.document.LastRevRecoveryAgent.java

/**
 * Determines the last committed modification to the given document by
 * a {@code clusterId}.//  w  w  w  .  j  av a 2s.c  om
 *
 * @param doc a document.
 * @param clusterId clusterId for which the last committed modification is
 *                  looked up.
 * @return the commit revision of the last modification by {@code clusterId}
 *          to the given document.
 */
@CheckForNull
private Revision determineLastModification(NodeDocument doc, int clusterId) {
    ClusterPredicate cp = new ClusterPredicate(clusterId);

    Revision lastModified = null;
    for (String property : Sets.filter(doc.keySet(), PROPERTY_OR_DELETED)) {
        Map<Revision, String> valueMap = doc.getLocalMap(property);
        // collect committed changes of this cluster node
        for (Map.Entry<Revision, String> entry : filterKeys(valueMap, cp).entrySet()) {
            Revision rev = entry.getKey();
            if (doc.isCommitted(rev)) {
                lastModified = Utils.max(lastModified, doc.getCommitRevision(rev));
                break;
            }
        }
    }
    return lastModified;
}

From source file:org.apache.tephra.hbase.txprune.HBaseTransactionPruningPlugin.java

private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
        SortedSet<byte[]> transactionalRegions) {
    return Sets.filter(transactionalRegions, new Predicate<byte[]>() {
        @Override//from   w ww.  jav  a  2s . c  om
        public boolean apply(byte[] region) {
            return existingTables.contains(HRegionInfo.getTable(region));
        }
    });
}

From source file:org.voltcore.agreement.AgreementSeeker.java

/**
 * Is the given hsid considered dead by anyone in my survivor set?
 * @param hsid a site hsid/*from w w  w .  j a v a  2s. com*/
 * @return a subset of my survivor set that considers the given site dead
 */
public Set<Long> forWhomSiteIsDead(long hsid) {
    ImmutableSet.Builder<Long> isb = ImmutableSet.builder();
    Set<Long> deadBy = m_dead.get(hsid);
    if (!deadBy.isEmpty() && m_survivors.contains(hsid)
            && m_strategy == ArbitrationStrategy.MATCHING_CARDINALITY) {
        isb.addAll(Sets.filter(deadBy, amongSurvivors));
    }
    return isb.build();
}

From source file:org.gradle.plugins.ide.idea.model.IdeaModule.java

private Set<File> existing(Set<File> files) {
    return Sets.filter(files, new Predicate<File>() {
        @Override// www  . j a v  a  2s  . c  o  m
        public boolean apply(File file) {
            return file.exists();
        }
    });
}

From source file:gov.nih.nci.firebird.data.InvestigatorProfile.java

/**
 * get credentials of the specified type.
 *
 * @param type type to match.//from  ww  w .j a  va2s  .c  om
 * @return credentials matching the specified type.
 */
public SortedSet<AbstractCredential<?>> getCredentials(final CredentialType type) {
    return getSortedSet(Sets.filter(getCredentials(), new Predicate<AbstractCredential<?>>() {
        @Override
        public boolean apply(AbstractCredential<?> credential) {
            return type.equals(credential.getType());
        }
    }));
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.refresh.SequenceCanonicalSynchronizerAdapter.java

private Set<ISequenceEvent> getEventEndsAfterUpperRange(SequenceDiagram sequenceDiagram, Lifeline lifeline,
        int upperRange, Set<ISequenceEvent> sequenceEventToIgnores) {
    Set<ISequenceEvent> eventEndsAfterUpperRange = new TreeSet<ISequenceEvent>(new RangeComparator());
    Set<ISequenceEvent> allSequenceEventsInUpperRange = new SequenceDiagramQuery(sequenceDiagram)
            .getAllSequenceEventsUpperThan(upperRange);
    allSequenceEventsInUpperRange.removeAll(sequenceEventToIgnores);
    eventEndsAfterUpperRange.addAll(/*w w  w  .ja v  a 2  s  .  c  o  m*/
            Sets.filter(allSequenceEventsInUpperRange, Predicates.not(Predicates.instanceOf(Lifeline.class))));
    return eventEndsAfterUpperRange;
}

From source file:dagger2.internal.codegen.ComponentGenerator.java

/** Returns true if the graph has any dependents that can't be automatically constructed. */
private boolean requiresUserSuppliedDependents(BindingGraph input) {
    Set<TypeElement> allDependents = Sets.union(
            Sets.union(input.transitiveModules().keySet(), input.componentDescriptor().dependencies()),
            input.componentDescriptor().executorDependency().asSet());
    Set<TypeElement> userRequiredDependents = Sets.filter(allDependents, new Predicate<TypeElement>() {
        @Override/*ww w  .ja v  a  2s . c om*/
        public boolean apply(TypeElement input) {
            return !Util.componentCanMakeNewInstances(input);
        }
    });
    return !userRequiredDependents.isEmpty();
}

From source file:edu.harvard.med.screensaver.ui.screens.ScreenDetailViewer.java

public UISelectOneEntityBean<AdministratorUser> getPinTransferApprovedBy() {
    if (_pinTransferApprovedBy == null) {
        Set<AdministratorUser> candidateApprovers = Sets.filter(
                ImmutableSortedSet.orderedBy(ScreensaverUserComparator.<AdministratorUser>getInstance())
                        .addAll(getDao().findAllEntitiesOfType(AdministratorUser.class, true,
                                ScreensaverUser.roles.castToSubtype(AdministratorUser.class)))
                        .build(),/*  w w w  . j a va2  s  .c om*/
                new Predicate<AdministratorUser>() {
                    public boolean apply(AdministratorUser u) {
                        return u.getScreensaverUserRoles().contains(ScreensaverUserRole.SCREENS_ADMIN);
                    }
                });
        // note: we must reload 'performedBy', since it can otherwise be a proxy, which will not allow us to cast it to AdministratorUser
        AdministratorUser defaultSelection = getEntity().getPinTransferApprovalActivity() == null ? null
                : (AdministratorUser) getDao()
                        .reloadEntity(getEntity().getPinTransferApprovalActivity().getPerformedBy());
        _pinTransferApprovedBy = new UISelectOneEntityBean<AdministratorUser>(candidateApprovers,
                defaultSelection, true, getDao()) {
            @Override
            public String makeLabel(AdministratorUser a) {
                return a.getFullNameLastFirst();
            }
        };
    }
    return _pinTransferApprovedBy;
}