本文整理汇总了Java中com.google.common.collect.Collections2.filter方法的典型用法代码示例。如果您正苦于以下问题:Java Collections2.filter方法的具体用法?Java Collections2.filter怎么用?Java Collections2.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Collections2
的用法示例。
在下文中一共展示了Collections2.filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SimpleHelpMap
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public SimpleHelpMap(CraftServer server) {
this.helpTopics = new TreeMap<String, HelpTopic>(HelpTopicComparator.topicNameComparatorInstance()); // Using a TreeMap for its explicit sorting on key
this.topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>();
this.server = server;
this.yaml = new HelpYamlReader(server);
Predicate indexFilter = Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class));
if (!yaml.commandTopicsInMasterIndex()) {
indexFilter = Predicates.and(indexFilter, Predicates.not(new IsCommandTopicPredicate()));
}
this.defaultTopic = new IndexHelpTopic("Index", null, null, Collections2.filter(helpTopics.values(), indexFilter), "Use /help [n] to get page n of help.");
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
}
示例2: listAll
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
public static ArrayList<Currency> listAll(Context context, final String filter) {
ArrayList<Currency> list = new ArrayList<>();
for (java.util.Currency currency : java.util.Currency.getAvailableCurrencies()) {
list.add(getCurrency(currency, context));
}
sortList(list);
if (filter != null && filter.length() > 0) {
return new ArrayList<>(Collections2.filter(list, new Predicate<Currency>() {
@Override
public boolean apply(Currency input) {
return input.getName().toLowerCase().contains(filter.toLowerCase()) ||
input.getSymbol().toLowerCase().contains(filter.toLowerCase());
}
}));
} else {
return list;
}
}
示例3: getSourceFiles
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {
ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
CppCompileInfo cppInfo = info.getExtension(CppCompileInfo.cppCompileInfo);
return Collections2.filter(
cppInfo.getSourcesAndHeadersList(),
Predicates.and(
Predicates.not(Predicates.containsPattern("third_party/")),
Predicates.not(Predicates.containsPattern("config/heron-config.h")),
Predicates.not(Predicates.containsPattern(".*pb.h$")),
Predicates.not(Predicates.containsPattern(".*cc_wrapper.sh$")),
Predicates.not(Predicates.containsPattern(".*pb.cc$"))
)
);
}
示例4: setResolvers
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
/**
* Set the registered client information resolvers.
*
* @param newResolvers the client information resolvers to use
*
* @throws ResolverException thrown if there is a problem adding the client information resolvers
*/
public void setResolvers(@Nonnull @NonnullElements final List<? extends ClientInformationResolver> newResolvers)
throws ResolverException {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
if (newResolvers == null || newResolvers.isEmpty()) {
resolvers = Collections.emptyList();
return;
}
resolvers = new ArrayList<>(Collections2.filter(newResolvers, Predicates.notNull()));
}
示例5: setDefaultAuthenticationMethods
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
/**
* Set the default authentication contexts to use, expressed as custom principals.
*
* @param contexts default authentication contexts to use
*/
public void setDefaultAuthenticationMethods(
@Nonnull @NonnullElements final List<Principal> contexts) {
Constraint.isNotNull(contexts, "List of contexts cannot be null");
defaultAuthenticationContexts = new ArrayList<>(Collections2.filter(contexts, Predicates.notNull()));
}
示例6: NameNodeResourceChecker
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
/**
* Create a NameNodeResourceChecker, which will check the edits dirs and any
* additional dirs to check set in <code>conf</code>.
*/
public NameNodeResourceChecker(Configuration conf) throws IOException {
this.conf = conf;
volumes = new HashMap<String, CheckedVolume>();
duReserved = conf.getLong(DFSConfigKeys.DFS_NAMENODE_DU_RESERVED_KEY,
DFSConfigKeys.DFS_NAMENODE_DU_RESERVED_DEFAULT);
Collection<URI> extraCheckedVolumes = Util.stringCollectionAsURIs(conf
.getTrimmedStringCollection(DFSConfigKeys.DFS_NAMENODE_CHECKED_VOLUMES_KEY));
Collection<URI> localEditDirs = Collections2.filter(
FSNamesystem.getNamespaceEditsDirs(conf),
new Predicate<URI>() {
@Override
public boolean apply(URI input) {
if (input.getScheme().equals(NNStorage.LOCAL_URI_SCHEME)) {
return true;
}
return false;
}
});
// Add all the local edits dirs, marking some as required if they are
// configured as such.
for (URI editsDirToCheck : localEditDirs) {
addDirToCheck(editsDirToCheck,
FSNamesystem.getRequiredNamespaceEditsDirs(conf).contains(
editsDirToCheck));
}
// All extra checked volumes are marked "required"
for (URI extraDirToCheck : extraCheckedVolumes) {
addDirToCheck(extraDirToCheck, true);
}
minimumRedundantVolumes = conf.getInt(
DFSConfigKeys.DFS_NAMENODE_CHECKED_VOLUMES_MINIMUM_KEY,
DFSConfigKeys.DFS_NAMENODE_CHECKED_VOLUMES_MINIMUM_DEFAULT);
}
示例7: getNearbyEntities
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
public static <T extends Entity> Collection<? extends T> getNearbyEntities(Location location, Vector range, final Class<T> type) {
Collection<Entity> filtered = Collections2.filter(location.getWorld().getNearbyEntities(location, range.getX(), range.getY(), range.getZ()), new Predicate<Entity>() {
@Override
public boolean apply(Entity entity) {
return type.isInstance(entity);
}
});
return (Collection<? extends T>) filtered;
}
示例8: getRewards
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
private Collection<KillReward> getRewards(@Nullable Event event, ParticipantState victim, DamageInfo damageInfo) {
final DamageQuery query = DamageQuery.attackerDefault(event, victim, damageInfo);
return Collections2.filter(killRewards, new Predicate<KillReward>() {
@Override
public boolean apply(KillReward killReward) {
return killReward.filter.query(query).isAllowed();
}
});
}
示例9: FilteredSchema
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
/**
* Construct a new {@link FilteredSchema} identical to the <var>baseSchema</var>
* in all respects save the removal of the named tables. Note that tables are
* removed regardless of the case of their names.
*
* @param baseSchema base schema to adapt.
* @param removedTables names of tables to remove.
*/
public FilteredSchema(final Schema baseSchema, final String... removedTables) {
super(Collections2.filter(baseSchema.tables(), not(new Predicate<Table>() {
@Override
public boolean apply(Table table) {
// String.CASE_INSENSITIVE_ORDER lets you use case-insensitive .contains(Object)
Set<String> caseInsensitiveSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
Collections.addAll(caseInsensitiveSet, removedTables);
return caseInsensitiveSet.contains(table.getName());
}
})));
}
示例10: execute
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
@Override
protected void execute() {
MeterService service = get(MeterService.class);
Collection<Meter> meters = service.getAllMeters();
if (uri != null) {
DeviceId deviceId = DeviceId.deviceId(uri);
Collection<Meter> devMeters = Collections2.filter(meters,
m -> m.deviceId().equals(deviceId));
printMeters(devMeters);
} else {
printMeters(meters);
}
}
示例11: syncSGRules
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
private void syncSGRules(SecurityGroup sg, Openstack4JNeutron neutron) throws Exception {
final List<? extends SecurityGroupRule> rules = sg.getRules();
List<SecurityGroupRule> expectedList = new ArrayList<>();
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV4)
.direction(CreateOsSecurityGroupTask.INGRESS).build());
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV4)
.direction(CreateOsSecurityGroupTask.EGRESS).build());
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV6)
.direction(CreateOsSecurityGroupTask.INGRESS).build());
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV6)
.direction(CreateOsSecurityGroupTask.EGRESS).build());
ImmutableList.<SecurityGroupRule>builder().addAll(expectedList);
// Filter the missing rules from the expected SG rules
Collection<SecurityGroupRule> missingRules = Collections2.filter(expectedList, expRule -> {
for (SecurityGroupRule osRule : rules) {
if (expRule != null && osRule.getDirection().equals(expRule.getDirection())
&& osRule.getEtherType().equals(expRule.getEtherType()) && osRule.getProtocol() == null) {
return false;
}
}
return true;
});
if (!missingRules.isEmpty()) {
neutron.addSecurityGroupRules(sg, this.ds.getRegion(), missingRules);
}
}
示例12: execute
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
@Override
public void execute(final JobExecutionContext jobExecutionContext) throws JobExecutionException {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
try {
logger.info("Beginning ticket cleanup...");
final Collection<Ticket> ticketsToRemove = Collections2.filter(this.getTickets(), new Predicate<Ticket>() {
@Override
public boolean apply(@Nullable final Ticket ticket) {
if (ticket.isExpired()) {
if (ticket instanceof TicketGrantingTicket) {
logger.debug("Cleaning up expired ticket-granting ticket [{}]", ticket.getId());
logoutManager.performLogout((TicketGrantingTicket) ticket);
deleteTicket(ticket.getId());
} else if (ticket instanceof ServiceTicket) {
logger.debug("Cleaning up expired service ticket [{}]", ticket.getId());
deleteTicket(ticket.getId());
} else {
logger.warn("Unknown ticket type [{} found to clean", ticket.getClass().getSimpleName());
}
return true;
}
return false;
}
});
logger.info("{} expired tickets found and removed.", ticketsToRemove.size());
} catch (final Exception e) {
logger.error(e.getMessage(), e);
}
}
示例13: getSourceFiles
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {
ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
SpawnInfo spawnInfo = info.getExtension(SpawnInfo.spawnInfo);
return Collections2.filter(spawnInfo.getInputFileList(),
Predicates.and(
Predicates.containsPattern(".*/src/.+\\.py[c]{0,1}$"),
Predicates.not(Predicates.containsPattern("third_party/"))
)
);
}
示例14: tokenizeToFilteredMultiset
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
@Override
Collection<String> tokenizeToFilteredMultiset(String input) {
return Collections2.filter(
tokenizer.tokenizeToTransformedMultiset(input),
predicate);
}
示例15: getContent
import com.google.common.collect.Collections2; //导入方法依赖的package包/类
public String getContent() {
final TableBuilder builder = new TableBuilder(FRAGMENT_COLUMNS);
// Use only minor fragments that have complete profiles
// Complete iff the fragment profile has at least one operator profile, and start and end times.
final List<MinorFragmentProfile> complete = new ArrayList<>(
Collections2.filter(major.getMinorFragmentProfileList(), Filters.hasOperatorsAndTimes));
final List<MinorFragmentProfile> incomplete = new ArrayList<>(
Collections2.filter(major.getMinorFragmentProfileList(), Filters.missingOperatorsOrTimes));
Collections.sort(complete, Comparators.minorId);
for (final MinorFragmentProfile minor : complete) {
final ArrayList<OperatorProfile> ops = new ArrayList<>(minor.getOperatorProfileList());
long biggestIncomingRecords = 0;
long biggestBatches = 0;
for (final OperatorProfile op : ops) {
long incomingRecords = 0;
long batches = 0;
for (final StreamProfile sp : op.getInputProfileList()) {
incomingRecords += sp.getRecords();
batches += sp.getBatches();
}
biggestIncomingRecords = Math.max(biggestIncomingRecords, incomingRecords);
biggestBatches = Math.max(biggestBatches, batches);
}
builder.appendCell(new OperatorPathBuilder().setMajor(major).setMinor(minor).build(), null);
builder.appendCell(minor.getEndpoint().getAddress(), null);
builder.appendMillis(minor.getStartTime() - start, null);
builder.appendMillis(minor.getEndTime() - start, null);
builder.appendMillis(minor.getEndTime() - minor.getStartTime(), null);
builder.appendFormattedInteger(biggestIncomingRecords, null);
builder.appendFormattedInteger(biggestBatches, null);
builder.appendTime(minor.getLastUpdate(), null);
builder.appendTime(minor.getLastProgress(), null);
builder.appendBytes(minor.getMaxMemoryUsed(), null);
builder.appendCell(minor.getState().name(), null);
}
for (final MinorFragmentProfile m : incomplete) {
builder.appendCell(major.getMajorFragmentId() + "-" + m.getMinorFragmentId(), null);
builder.appendRepeated(m.getState().toString(), null, NUM_NULLABLE_FRAGMENTS_COLUMNS);
}
return builder.build();
}