private NameIndexedMap<ImmutableSet<Integer>> makeOptimizedIntSetLookup( Names names, ImmutableSetMultimap<MethodRef, Integer> ref2Ints) { return makeOptimizedLookup(names, ref2Ints.keySet(), ref2Ints::get); }
final Set<ImportTree> unusedImports = new HashSet<>(importedSymbols.keySet()); new TreeSymbolScanner(JavacTrees.instance(state.context), state.getTypes()) .scan(
/** * Given a list of actual elements, a list of expected elements, and a many:many mapping between * actual and expected elements specified as a multimap of indexes into the actual list to * indexes into the expected list, checks that every actual element maps to at least one * expected element and vice versa, and fails if this is not the case. Returns whether the * assertion failed. */ private boolean failIfCandidateMappingHasMissingOrExtra( List<? extends A> actual, List<? extends E> expected, ImmutableSetMultimap<Integer, Integer> mapping, Correspondence.ExceptionStore exceptions) { List<? extends A> extra = findNotIndexed(actual, mapping.keySet()); List<? extends E> missing = findNotIndexed(expected, mapping.inverse().keySet()); if (!missing.isEmpty() || !extra.isEmpty()) { subject.failWithoutActual( facts( simpleFact( lenientFormat( "Not true that %s contains exactly one element that %s each element " + "of <%s>. It %s", subject.actualAsString(), correspondence, expected, describeMissingOrExtra(missing, extra, exceptions)))) .and(exceptions.describeAsAdditionalInfo())); return true; } return false; }
/** * Given a list of actual elements, a list of expected elements, and a many:many mapping between * actual and expected elements specified as a multimap of indexes into an actual list to * indexes into the expected list, checks that every expected element maps to at least one * actual element, and fails if this is not the case. Actual elements which do not map to any * expected elements are ignored. */ private boolean failIfCandidateMappingHasMissing( List<? extends A> actual, List<? extends E> expected, ImmutableSetMultimap<Integer, Integer> mapping, Correspondence.ExceptionStore exceptions) { List<? extends E> missing = findNotIndexed(expected, mapping.inverse().keySet()); if (!missing.isEmpty()) { List<? extends A> extra = findNotIndexed(actual, mapping.keySet()); subject.failWithoutActual( facts( simpleFact( lenientFormat( "Not true that %s contains at least one element that %s each element " + "of <%s>. It %s", subject.actualAsString(), correspondence, expected, describeMissing(missing, extra, exceptions)))) .and(exceptions.describeAsAdditionalInfo())); return true; } return false; }
public void testBuilderOrderKeysBy() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.put("b", 3); builder.put("d", 2); builder.put("a", 5); builder.orderKeysBy(Collections.reverseOrder()); builder.put("c", 4); builder.put("a", 2); builder.put("b", 6); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder(); assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("b")).containsExactly(3, 6).inOrder(); assertFalse(multimap.get("a") instanceof ImmutableSortedSet); assertFalse(multimap.get("x") instanceof ImmutableSortedSet); assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet); }
public void testBuilderOrderKeysAndValuesBy() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.put("b", 3); builder.put("d", 2); builder.put("a", 5); builder.orderKeysBy(Collections.reverseOrder()); builder.orderValuesBy(Collections.reverseOrder()); builder.put("c", 4); builder.put("a", 2); builder.put("b", 6); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder(); assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("b")).containsExactly(6, 3).inOrder(); assertTrue(multimap.get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator()); assertTrue(multimap.get("x") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator()); assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator()); }
public void testBuilderOrderValuesBy() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.put("b", 3); builder.put("d", 2); builder.put("a", 5); builder.orderValuesBy(Collections.reverseOrder()); builder.put("c", 4); builder.put("a", 2); builder.put("b", 6); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder(); assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("b")).containsExactly(6, 3).inOrder(); assertTrue(multimap.get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator()); assertTrue(multimap.get("x") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator()); assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator()); }
public void testBuilderOrderKeysByDuplicates() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.put("bb", 3); builder.put("d", 2); builder.put("a", 5); builder.orderKeysBy( new Ordering<String>() { @Override public int compare(String left, String right) { return left.length() - right.length(); } }); builder.put("cc", 4); builder.put("a", 2); builder.put("bb", 6); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder(); assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder(); assertFalse(multimap.get("a") instanceof ImmutableSortedSet); assertFalse(multimap.get("x") instanceof ImmutableSortedSet); assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet); }
/** Converts a {@link ApiDiff} to a {@link ApiDiffProto.Diff}. */ public Diff toProto() { ApiDiffProto.Diff.Builder builder = ApiDiffProto.Diff.newBuilder(); for (String className : unsupportedClasses()) { builder.addClassDiff( ApiDiffProto.ClassDiff.newBuilder() .setEverythingDiff(ApiDiffProto.EverythingDiff.newBuilder().setClassName(className))); } for (String className : unsupportedMembersByClass().keySet()) { ApiDiffProto.MemberDiff.Builder memberDiff = ApiDiffProto.MemberDiff.newBuilder().setClassName(className); for (ClassMemberKey member : unsupportedMembersByClass().get(className)) { memberDiff.addMember( ApiDiffProto.ClassMember.newBuilder() .setIdentifier(member.identifier()) .setMemberDescriptor(member.descriptor())); } builder.addClassDiff(ApiDiffProto.ClassDiff.newBuilder().setMemberDiff(memberDiff)); } return builder.build(); } }
@Override public Set<Var> keySet() { return unifier.keySet(); }
/** Returns the set of component requirements this creator can set. */ final ImmutableSet<ComponentRequirement> settableRequirements() { return requirementElements().keySet(); }
@Override public ImmutableSet<Experiment> selectExperiments() { List<Experiment> experiments = Lists.newArrayList(); for (Instrumentation instrumentation : instrumentations) { for (VirtualMachine vm : vms) { for (List<String> userParamsChoice : cartesian(userParameters)) { ImmutableMap<String, String> theseUserParams = zip(userParameters.keySet(), userParamsChoice); experiments.add(new Experiment(instrumentation, theseUserParams, vm)); } } } return ImmutableSet.copyOf(experiments); }
private ImmutableConstantChecker(ImmutableSentenceFormModel sentenceModel, ImmutableSetMultimap<SentenceForm, GdlSentence> sentencesByForm) { Preconditions.checkArgument(sentenceModel.getConstantSentenceForms().containsAll(sentencesByForm.keySet())); this.sentenceModel = sentenceModel; this.sentencesByForm = sentencesByForm; }
@SuppressWarnings("unchecked") <T> boolean doRegister(T object) { boolean success = false; final Set<Class<?>> modelSupportedTypes = registry.keySet(); for (final Class<?> modelSupportedType : modelSupportedTypes) { if (modelSupportedType.isAssignableFrom(object.getClass())) { final Collection<Model<?>> assignableModels = registry .get(modelSupportedType); for (final Model<?> m : assignableModels) { success |= ((Model<T>) m).register(object); } } } return success; }
@Override public ImmutableSet<Experiment> selectExperiments() { List<Experiment> experiments = Lists.newArrayList(); for (Instrumentation instrumentation : instrumentations) { for (VirtualMachine vm : vms) { for (List<String> userParamsChoice : cartesian(userParameters)) { ImmutableMap<String, String> theseUserParams = zip(userParameters.keySet(), userParamsChoice); experiments.add(new Experiment(instrumentation, theseUserParams, vm)); } } } return ImmutableSet.copyOf(experiments); }
/** * Returns sets of duplicate bindings. Bindings are duplicates if they bind the same key and are * visible from the same component. Two bindings that differ only in the component that owns them * are not considered to be duplicates, because that means the same binding was "copied" down to a * descendant component because it depends on local multibindings or optional bindings. Hence each * "set" is represented as a multimap from binding element (ignoring component path) to binding. */ private ImmutableSet<ImmutableSetMultimap<BindingElement, Binding>> duplicateBindingSets( BindingGraph bindingGraph) { return groupBindingsByKey(bindingGraph).stream() .flatMap(bindings -> mutuallyVisibleSubsets(bindings).stream()) .map(BindingElement::index) .filter(duplicates -> duplicates.keySet().size() > 1) .collect(toImmutableSet()); }
@Override public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) { // If two unrelated subcomponents have the same duplicate bindings only because they install the // same two modules, then fixing the error in one subcomponent will uncover the second // subcomponent to fix. // TODO(ronshapiro): Explore ways to address such underreporting without overreporting. Set<ImmutableSet<BindingElement>> reportedDuplicateBindingSets = new HashSet<>(); duplicateBindingSets(bindingGraph) .forEach( duplicateBindings -> { // Only report each set of duplicate bindings once, ignoring the installed component. if (reportedDuplicateBindingSets.add(duplicateBindings.keySet())) { reportDuplicateBindings(duplicateBindings, bindingGraph, diagnosticReporter); } }); }
private void checkForInconsistentMapKeyAnnotationTypes( dagger.model.Binding multiboundMapBinding, ImmutableSet<ContributionBinding> contributions, DiagnosticReporter diagnosticReporter) { ImmutableSetMultimap<Equivalence.Wrapper<DeclaredType>, ContributionBinding> contributionsByMapKeyAnnotationType = indexByMapKeyAnnotationType(contributions); if (contributionsByMapKeyAnnotationType.keySet().size() > 1) { diagnosticReporter.reportBinding( ERROR, multiboundMapBinding, inconsistentMapKeyAnnotationTypesErrorMessage( contributionsByMapKeyAnnotationType, multiboundMapBinding.key())); } }
void validateParameters(ImmutableSetMultimap<String, String> parameters) throws InvalidCommandException { for (String paramName : parameters.keySet()) { Parameter parameter = userParameters.get(paramName); if (parameter == null) { throw new InvalidCommandException("unrecognized parameter: " + paramName); } try { parameter.validate(parameters.get(paramName)); } catch (InvalidBenchmarkException e) { // TODO(kevinb): this is weird. throw new InvalidCommandException(e.getMessage()); } } } }
void validateParameters(ImmutableSetMultimap<String, String> parameters) throws InvalidCommandException { for (String paramName : parameters.keySet()) { Parameter parameter = userParameters.get(paramName); if (parameter == null) { throw new InvalidCommandException("unrecognized parameter: " + paramName); } try { parameter.validate(parameters.get(paramName)); } catch (InvalidBenchmarkException e) { // TODO(kevinb): this is weird. throw new InvalidCommandException(e.getMessage()); } } } }