@Override public Collection<String> create(String[] elements) { List<String> list = newArrayList(); for (String element : elements) { list.add((element == null) ? null : "q" + element); } return Collections2.transform(list, REMOVE_FIRST_CHAR); } })
@Override public Collection<TimestampedDatasetVersion> listDeletableVersions(List<TimestampedDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, new Predicate<DatasetVersion>() { @Override public boolean apply(DatasetVersion version) { return ((TimestampedDatasetVersion) version).getDateTime().plus(TimeBasedRetentionPolicy.this.retention) .isBeforeNow(); } })); }
/** * A sensible definition of {@link #toString} in terms of {@link #iterator}. If you override * {@link #iterator}, you may wish to override {@link #toString} to forward to this * implementation. * * @since 7.0 */ protected String standardToString() { return Collections2.toStringImpl(this); }
private <T> Set<T> transform(Predicate<TaskInfo> filter, Function<TaskInfo, T> fun) { lock.readLock().lock(); try { Collection<TaskInfo> filtered = Collections2.filter(taskMetrics, filter); return Sets.newHashSet(Collections2.transform(filtered, fun)); } finally { lock.readLock().unlock(); } }
/** * Set the list of {@link MetadataFilter}s that make up this chain. * * @param newFilters list of {@link MetadataFilter}s that make up this chain */ public void setFilters(@Nonnull @NonnullElements final List<MetadataFilter> newFilters) { Constraint.isNotNull(newFilters, "Filter collection cannot be null"); filters = new ArrayList<>(Collections2.filter(newFilters, Predicates.notNull())); }
final Set<String> workerNodeIds = Sets.newHashSet( workerConfig.getAutoScaler().ipToIdLookup( Lists.newArrayList( Iterables.transform( runner.getLazyWorkers(), new Function<Worker, String>() final Predicate<ImmutableWorkerInfo> isLazyWorker = ProvisioningUtil.createLazyWorkerPredicate(config); final Collection<String> laziestWorkerIps = Collections2.transform( runner.markWorkersLazy(isLazyWorker, excessWorkers), new Function<Worker, String>() .terminate(ImmutableList.copyOf(laziestWorkerIps)); if (terminated != null) { currentlyTerminating.addAll(terminated.getNodeIds());
@Override public Collection<String> create(String[] elements) { List<String> unfiltered = newArrayList(); unfiltered.add("yyy"); unfiltered.addAll(ImmutableList.copyOf(elements)); unfiltered.add("zzz"); unfiltered.add("abc"); return Collections2.filter(Collections2.filter(unfiltered, LENGTH_1), NOT_YYY_ZZZ); } })
private List<LogDetail> parseLogDetails(final String logDetailsString) { if (StringUtils.isBlank(logDetailsString)) return newArrayList(); final HashSet<String> logDetailsStrings = newHashSet(Splitter.on(",").trimResults().omitEmptyStrings().split(logDetailsString)); final HashSet<String> validLogDetailsStrings = newHashSet(transform(newArrayList(LogDetail.values()), logDetail -> logDetail.name().toLowerCase())); final Collection<LogDetail> logDetails = transform(intersection(logDetailsStrings, validLogDetailsStrings), s -> LogDetail.valueOf(s.toUpperCase())); return newArrayList(logDetails.iterator()); } }
@Override public List<TagModelDao> getTagsForObject(final UUID objectId, final ObjectType objectType, final boolean includedDeleted, final InternalTenantContext internalTenantContext) { if (tagStore.get(objectId) == null) { return ImmutableList.<TagModelDao>of(); } return ImmutableList.<TagModelDao>copyOf(Collections2.filter(tagStore.get(objectId), new Predicate<TagModelDao>() { @Override public boolean apply(final TagModelDao input) { return objectType.equals(input.getObjectType()); } })); }
final int currValidWorkers = Collections2.filter(workers, isValidWorker).size(); Lists.newArrayList( Iterables.transform( workers, new Function<ImmutableWorkerInfo, String>() .emit(); workerConfig.getAutoScaler().terminateWithIds(Lists.newArrayList(currentlyProvisioning)); currentlyProvisioning.clear();
public void testToStringImplWithNullEntries() throws Exception { List<String> list = Lists.newArrayList(); list.add("foo"); list.add(null); assertEquals(list.toString(), Collections2.toStringImpl(list)); } }
private List<String> sanitizeAndValidatePermissions(final List<String> permissionsRaw) throws SecurityApiException { if (permissionsRaw == null) { return ImmutableList.<String>of(); final Collection<String> permissions = Collections2.<String>filter(Lists.<String, String>transform(permissionsRaw, new Function<String, String>() { @Override Predicates.<String>notNull()); return ImmutableList.of("*");
@Override public Collection<Permission> resolvePermissionsInRole(String roleId) { final Set<String> permissions = resolveStringPermission(roleId); // copy to avoid reiterating all the time return Sets.newHashSet(Collections2.transform(permissions, new Function<String, Permission>() { @Nullable @Override public Permission apply(@Nullable String input) { return new WildcardPermission(input); } })); }
@SuppressWarnings("unchecked") private Set<List<String>> getCartesianValues(final GString segment) { List<Set<String>> result = new ArrayList<>(segment.getValues().length); for (Object each : segment.getValues()) { if (null == each) { continue; } if (each instanceof Collection) { result.add(Sets.newLinkedHashSet(Collections2.transform((Collection<Object>) each, new Function<Object, String>() { @Override public String apply(final Object input) { return input.toString(); } }))); } else { result.add(Sets.newHashSet(each.toString())); } } return Sets.cartesianProduct(result); }
@Override public List<TagModelDao> getTagsForAccountType(final ObjectType objectType, final boolean includedDeleted, final InternalTenantContext internalTenantContext) { final List<TagModelDao> allTags = getTagsForAccount(includedDeleted, internalTenantContext); return ImmutableList.<TagModelDao>copyOf(Collections2.filter(allTags, new Predicate<TagModelDao>() { @Override public boolean apply(final TagModelDao input) { return input.getObjectType() == objectType; } })); }
private Set<String> findLDAPGroupsForUser(final String userName, final LdapContext ldapCtx) throws NamingException { final NamingEnumeration<SearchResult> foundGroups = ldapCtx.search(searchBase, groupSearchFilter.replace(USERDN_SUBSTITUTION_TOKEN, userName), SUBTREE_SCOPE); if (!foundGroups.hasMoreElements()) { return ImmutableSet.<String>of(); } // There should really only be one entry final SearchResult result = foundGroups.next(); // Extract the name of all the groups final Collection<String> finalGroupsNames = Collections2.<String>filter(extractGroupNamesFromSearchResult(result), Predicates.notNull()); return Sets.newHashSet(finalGroupsNames); }
@Parameterized.Parameters(name = "{index}: metric compression={0}, dimension compression={1}, long encoding={2}, segment write-out medium={3}") public static Collection<Object[]> data() { return Collections2.transform( Sets.cartesianProduct( ImmutableList.of( EnumSet.allOf(CompressionStrategy.class), ImmutableSet.copyOf(CompressionStrategy.noNoneValues()), EnumSet.allOf(CompressionFactory.LongEncodingStrategy.class), SegmentWriteOutMediumFactory.builtInFactories() ) ), new Function<List<?>, Object[]>() { @Nullable @Override public Object[] apply(List<?> input) { return input.toArray(); } } ); }
/** * Set the confirmation methods to use. * * @param methods confirmation methods to use */ public void setMethods(@Nonnull @NonnullElements final Collection<String> methods) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); Constraint.isNotEmpty(methods, "Confirmation method collection cannot be null or empty"); confirmationMethods = new ArrayList<>(Collections2.filter(methods, Predicates.notNull())); }