List of usage examples for com.google.common.collect ImmutableSet size
int size();
From source file:com.twitter.common.args.Args.java
/** * Hydrates configured {@literal @CmdLine} arg fields and selects a desired set with the supplied * {@code filter}.// w w w.ja v a 2 s . c o m * * @param configuration The configuration to find candidate {@literal @CmdLine} arg fields in. * @param filter A predicate to select fields with. * @return The desired hydrated {@literal @CmdLine} arg fields and optional {@literal @Positional} * arg field. */ static ArgsInfo fromConfiguration(Configuration configuration, Predicate<Field> filter) { ImmutableSet<Field> positionalFields = ImmutableSet .copyOf(filterFields(configuration.positionalInfo(), filter)); if (positionalFields.size() > 1) { throw new IllegalArgumentException(String.format( "Found %d fields marked for @Positional Args after applying filter - " + "only 1 is allowed:\n\t%s", positionalFields.size(), Joiner.on("\n\t").join(positionalFields))); } Optional<? extends PositionalInfo<?>> positionalInfo = Optional.fromNullable( Iterables.getOnlyElement(Iterables.transform(positionalFields, TO_POSITIONAL_INFO), null)); Iterable<? extends OptionInfo<?>> optionInfos = Iterables .transform(filterFields(configuration.optionInfo(), filter), TO_OPTION_INFO); return new ArgsInfo(configuration, positionalInfo, optionInfos); }
From source file:com.facebook.buck.distributed.DistBuildUtil.java
/** Checks whether the given target command line arguments match the Stampede project whitelist */ public static boolean doTargetsMatchProjectWhitelist(List<String> commandArgs, ImmutableSet<String> projectWhitelist, BuckConfig buckConfig) { ImmutableSet.Builder<String> buildTargets = new ImmutableSet.Builder<>(); for (String commandArg : commandArgs) { ImmutableSet<String> buildTargetForAliasAsString = AliasConfig.from(buckConfig) .getBuildTargetForAliasAsString(commandArg); if (buildTargetForAliasAsString.size() > 0) { buildTargets.addAll(buildTargetForAliasAsString); } else {//from w ww . j a v a2s . c o m // Target was not an alias if (!commandArg.startsWith("//")) { commandArg = "//" + commandArg; } buildTargets.add(commandArg); } } return doTargetsMatchProjectWhitelist(buildTargets.build(), projectWhitelist); }
From source file:com.google.devtools.build.skyframe.ReverseDepsUtility.java
static ImmutableSet<SkyKey> getReverseDeps(InMemoryNodeEntry entry) { consolidateData(entry);/*from w ww . jav a2 s .c o m*/ // TODO(bazel-team): Unfortunately, we need to make a copy here right now to be on the safe side // wrt. thread-safety. The parents of a node get modified when any of the parents is deleted, // and we can't handle that right now. if (isSingleReverseDep(entry)) { return ImmutableSet.of((SkyKey) entry.getReverseDepsRawForReverseDepsUtil()); } else { @SuppressWarnings("unchecked") List<SkyKey> reverseDeps = (List<SkyKey>) entry.getReverseDepsRawForReverseDepsUtil(); ImmutableSet<SkyKey> set = ImmutableSet.copyOf(reverseDeps); Preconditions.checkState(set.size() == reverseDeps.size(), "Duplicate reverse deps present in %s: %s", reverseDeps, entry); return set; } }
From source file:dagger.internal.codegen.SourceFiles.java
private static String fieldNameForDependency(ImmutableSet<DependencyRequest> dependencyRequests) { // collect together all of the names that we would want to call the provider ImmutableSet<String> dependencyNames = FluentIterable.from(dependencyRequests) .transform(new DependencyVariableNamer()).toSet(); if (dependencyNames.size() == 1) { // if there's only one name, great! use it! return Iterables.getOnlyElement(dependencyNames); } else {//from w ww . j a va 2s . c o m // in the event that a field is being used for a bunch of deps with different names, // add all the names together with "And"s in the middle. E.g.: stringAndS Iterator<String> namesIterator = dependencyNames.iterator(); String first = namesIterator.next(); StringBuilder compositeNameBuilder = new StringBuilder(first); while (namesIterator.hasNext()) { compositeNameBuilder.append("And") .append(CaseFormat.LOWER_CAMEL.to(UPPER_CAMEL, namesIterator.next())); } return compositeNameBuilder.toString(); } }
From source file:org.gradle.internal.ImmutableActionSet.java
private static <T> ImmutableActionSet<T> fromActions(ImmutableSet<Action<? super T>> set) { if (set.isEmpty()) { return empty(); }/*from w w w . j av a2s . c om*/ if (set.size() == 1) { return new SingletonSet<T>(set.iterator().next()); } if (set.size() <= FEW_VALUES) { return new SetWithFewActions<T>(set); } return new SetWithManyActions<T>(set); }
From source file:dagger2.internal.codegen.SourceFiles.java
/** * This method generates names and keys for the framework classes necessary for all of the * bindings. It is responsible for the following: * <ul>//www .ja va 2s . c o m * <li>Choosing a name that associates the binding with all of the dependency requests for this * type. * <li>Choosing a name that is <i>probably</i> associated with the type being bound. * <li>Ensuring that no two bindings end up with the same name. * </ul> * * @return Returns the mapping from {@link BindingKey} to field, sorted by the name of the field. */ static ImmutableMap<BindingKey, FrameworkField> generateBindingFieldsForDependencies( DependencyRequestMapper dependencyRequestMapper, Iterable<? extends DependencyRequest> dependencies) { ImmutableSetMultimap<BindingKey, DependencyRequest> dependenciesByKey = indexDependenciesByKey( dependencies); Map<BindingKey, Collection<DependencyRequest>> dependenciesByKeyMap = dependenciesByKey.asMap(); ImmutableMap.Builder<BindingKey, FrameworkField> bindingFields = ImmutableMap.builder(); for (Entry<BindingKey, Collection<DependencyRequest>> entry : dependenciesByKeyMap.entrySet()) { BindingKey bindingKey = entry.getKey(); Collection<DependencyRequest> requests = entry.getValue(); Class<?> frameworkClass = dependencyRequestMapper.getFrameworkClass(requests.iterator().next()); // collect together all of the names that we would want to call the provider ImmutableSet<String> dependencyNames = FluentIterable.from(requests) .transform(new DependencyVariableNamer()).toSet(); if (dependencyNames.size() == 1) { // if there's only one name, great! use it! String name = Iterables.getOnlyElement(dependencyNames); bindingFields.put(bindingKey, FrameworkField.createWithTypeFromKey(frameworkClass, bindingKey, name)); } else { // in the event that a field is being used for a bunch of deps with different names, // add all the names together with "And"s in the middle. E.g.: stringAndS Iterator<String> namesIterator = dependencyNames.iterator(); String first = namesIterator.next(); StringBuilder compositeNameBuilder = new StringBuilder(first); while (namesIterator.hasNext()) { compositeNameBuilder.append("And") .append(CaseFormat.LOWER_CAMEL.to(UPPER_CAMEL, namesIterator.next())); } bindingFields.put(bindingKey, FrameworkField.createWithTypeFromKey(frameworkClass, bindingKey, compositeNameBuilder.toString())); } } return bindingFields.build(); }
From source file:edu.mit.streamjit.util.bytecode.DeadCodeElimination.java
public static boolean eliminateUselessPhis(BasicBlock block) { boolean changed = false, makingProgress; do {/* www . ja v a 2 s. co m*/ makingProgress = false; for (Instruction i : ImmutableList.copyOf(block.instructions())) { if (!(i instanceof PhiInst)) continue; PhiInst pi = (PhiInst) i; if (Iterables.size(pi.incomingValues()) == 1) { pi.replaceInstWithValue(Iterables.getOnlyElement(pi.incomingValues())); makingProgress = true; continue; } ImmutableSet<Value> phiSources = phiSources(pi); if (phiSources.size() == 1) { pi.replaceInstWithValue(phiSources.iterator().next()); makingProgress = true; continue; } } changed |= makingProgress; } while (makingProgress); return changed; }
From source file:com.facebook.buck.artifact_cache.HttpArtifactCacheBinaryProtocol.java
@VisibleForTesting static byte[] createKeysHeader(ImmutableSet<RuleKey> ruleKeys) throws IOException { try (ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(out)) { data.writeInt(ruleKeys.size()); for (RuleKey ruleKey : ruleKeys) { data.writeUTF(ruleKey.toString()); }/*from w w w .java 2s .c o m*/ return out.toByteArray(); } }
From source file:google.registry.monitoring.metrics.StackdriverWriter.java
@VisibleForTesting static ImmutableList<LabelDescriptor> encodeLabelDescriptors( ImmutableSet<google.registry.monitoring.metrics.LabelDescriptor> labelDescriptors) { List<LabelDescriptor> stackDriverLabelDescriptors = new ArrayList<>(labelDescriptors.size()); for (google.registry.monitoring.metrics.LabelDescriptor labelDescriptor : labelDescriptors) { stackDriverLabelDescriptors.add(new LabelDescriptor().setKey(labelDescriptor.name()) .setDescription(labelDescriptor.description()).setValueType(LABEL_VALUE_TYPE)); }/*w ww. ja v a2 s . c o m*/ return ImmutableList.copyOf(stackDriverLabelDescriptors); }
From source file:google.registry.model.registry.label.DomainLabelMetrics.java
/** Update all three reserved list metrics. */ static void recordReservedListCheckOutcome(String tld, ImmutableSet<MetricsReservedListMatch> matches, double elapsedMillis) { MetricsReservedListMatch mostSevereMatch = null; for (MetricsReservedListMatch match : matches) { reservedListHits.increment(tld, match.reservedListName(), match.reservationType().toString()); if ((mostSevereMatch == null) || (match.reservationType().compareTo(mostSevereMatch.reservationType()) > 0)) { mostSevereMatch = match;//from w w w . ja v a2s . c o m } } String matchCount = String.valueOf(matches.size()); String mostSevereReservedList = matches.isEmpty() ? "(none)" : mostSevereMatch.reservedListName(); String mostSevereReservationType = (matches.isEmpty() ? "(none)" : mostSevereMatch.reservationType()) .toString(); reservedListChecks.increment(tld, matchCount, mostSevereReservedList, mostSevereReservationType); reservedListProcessingTime.record(elapsedMillis, tld, matchCount, mostSevereReservedList, mostSevereReservationType); }