List of usage examples for com.google.common.collect ImmutableSet size
int size();
From source file:dagger.internal.codegen.ModuleValidator.java
/** * Validates modules included in a given module or installed in a given component. * * <p>Checks that the referenced modules are non-generic types annotated with {@code @Module} or * {@code @ProducerModule}./* w w w . j a va 2 s . c om*/ * * <p>If the referenced module is in the {@linkplain #addKnownModules(Collection) known modules * set} and has errors, reports an error at that module's inclusion. * * @param annotatedType the annotated module or component * @param annotation the annotation specifying the referenced modules ({@code @Component}, * {@code @ProductionComponent}, {@code @Subcomponent}, {@code @ProductionSubcomponent}, * {@code @Module}, or {@code @ProducerModule}) * @param validModuleKinds the module kinds that the annotated type is permitted to include */ ValidationReport<TypeElement> validateReferencedModules(TypeElement annotatedType, AnnotationMirror annotation, ImmutableSet<ModuleDescriptor.Kind> validModuleKinds) { ValidationReport.Builder<TypeElement> subreport = ValidationReport.about(annotatedType); ImmutableSet<? extends Class<? extends Annotation>> validModuleAnnotations = validModuleKinds.stream() .map(ModuleDescriptor.Kind::moduleAnnotation).collect(toImmutableSet()); for (AnnotationValue includedModule : getModules(annotatedType, annotation)) { asType(includedModule).accept(new SimpleTypeVisitor8<Void, Void>() { @Override protected Void defaultAction(TypeMirror mirror, Void p) { reportError("%s is not a valid module type.", mirror); return null; } @Override public Void visitDeclared(DeclaredType t, Void p) { TypeElement module = MoreElements.asType(t.asElement()); if (!t.getTypeArguments().isEmpty()) { reportError(REFERENCED_MODULE_MUST_NOT_HAVE_TYPE_PARAMS, module.getQualifiedName()); } if (!isAnyAnnotationPresent(module, validModuleAnnotations)) { reportError(REFERENCED_MODULE_NOT_ANNOTATED, module.getQualifiedName(), (validModuleAnnotations.size() > 1 ? "one of " : "") + validModuleAnnotations .stream().map(otherClass -> "@" + otherClass.getSimpleName()) .collect(joining(", "))); } else if (knownModules.contains(module) && !validate(module).isClean()) { reportError("%s has errors", module.getQualifiedName()); } return null; } private void reportError(String format, Object... args) { subreport.addError(String.format(format, args), annotatedType, annotation, includedModule); } }, null); } return subreport.build(); }
From source file:org.elasticsearch.search.facet.terms.ints.TermsIntOrdinalsFacetCollector.java
public TermsIntOrdinalsFacetCollector(String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.smartFieldMappers(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms int facet collector on it"); }/*from w ww . j av a 2 s. com*/ // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.INT) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of int type, can't run terms int facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TIntHashSet(excluded.size()); for (BytesRef s : excluded) { this.excluded.add(Integer.parseInt(s.utf8ToString())); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().getIndexReader().leaves().size()); }
From source file:org.elasticsearch.search.facet.terms.ip.TermsIpOrdinalsFacetCollector.java
public TermsIpOrdinalsFacetCollector(String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<String> excluded) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.smartFieldMappers(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms long facet collector on it"); }//from w w w . j a va 2 s .c o m // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.LONG) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of long type, can't run terms long facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TLongHashSet(excluded.size()); for (String s : excluded) { this.excluded.add(Long.parseLong(s)); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().getIndexReader().leaves().size()); }
From source file:org.elasticsearch.search.facet.terms.longs.TermsLongOrdinalsFacetCollector.java
public TermsLongOrdinalsFacetCollector(String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.smartFieldMappers(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms long facet collector on it"); }/* w w w . j a v a 2 s . co m*/ // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.LONG) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of long type, can't run terms long facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TLongHashSet(excluded.size()); for (BytesRef s : excluded) { this.excluded.add(Long.parseLong(s.utf8ToString())); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().getIndexReader().leaves().size()); }
From source file:org.elasticsearch.search.facet.terms.bytes.TermsByteOrdinalsFacetCollector.java
public TermsByteOrdinalsFacetCollector(String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.smartFieldMappers(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms byte facet collector on it"); }//from www . j a v a 2 s .c o m // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.BYTE) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of byte type, can't run terms byte facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TByteHashSet(excluded.size()); for (BytesRef s : excluded) { this.excluded.add(Byte.parseByte(s.utf8ToString())); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().getIndexReader().leaves().size()); }
From source file:org.elasticsearch.search.facet.terms.shorts.TermsShortOrdinalsFacetCollector.java
public TermsShortOrdinalsFacetCollector(String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.smartFieldMappers(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms short facet collector on it"); }// www . j ava 2 s .c o m // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.SHORT) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of short type, can't run terms short facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TShortHashSet(excluded.size()); for (BytesRef s : excluded) { this.excluded.add(Short.parseShort(s.utf8ToString())); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().getIndexReader().leaves().size()); }
From source file:org.elasticsearch.search.facet.terms.floats.TermsFloatOrdinalsFacetCollector.java
public TermsFloatOrdinalsFacetCollector(String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.smartFieldMappers(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms float facet collector on it"); }//from w ww . jav a 2s . c om // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.FLOAT) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of float type, can't run terms float facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TFloatHashSet(excluded.size()); for (BytesRef s : excluded) { this.excluded.add(Float.parseFloat(s.utf8ToString())); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().getIndexReader().leaves().size()); }
From source file:org.elasticsearch.search.facet.terms.doubles.TermsDoubleOrdinalsFacetCollector.java
public TermsDoubleOrdinalsFacetCollector(String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.smartFieldMappers(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms double facet collector on it"); }//from w ww .ja v a2 s .com // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.DOUBLE) { throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] is not of double type, can't run terms double facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TDoubleHashSet(excluded.size()); for (BytesRef s : excluded) { this.excluded.add(Double.parseDouble(s.utf8ToString())); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().getIndexReader().leaves().size()); }
From source file:dagger2.internal.codegen.BindingGraphValidator.java
/** * Validates that among the dependencies are at most one scoped dependency, * that there are no cycles within the scoping chain, and that singleton * components have no scoped dependencies. *//* www . j a v a 2 s .co m*/ private void validateDependencyScopes(BindingGraph subject, Builder<BindingGraph> reportBuilder) { ComponentDescriptor descriptor = subject.componentDescriptor(); Optional<AnnotationMirror> scope = subject.componentDescriptor().scope(); ImmutableSet<TypeElement> scopedDependencies = scopedTypesIn(descriptor.dependencies()); if (scope.isPresent()) { // Dagger 1.x scope compatibility requires this be suppress-able. if (scopeCycleValidationType.diagnosticKind().isPresent() && isTypeOf(Singleton.class, scope.get().getAnnotationType())) { // Singleton is a special-case representing the longest lifetime, and therefore // @Singleton components may not depend on scoped components if (!scopedDependencies.isEmpty()) { StringBuilder message = new StringBuilder( "This @Singleton component cannot depend on scoped components:\n"); appendIndentedComponentsList(message, scopedDependencies); reportBuilder.addItem(message.toString(), scopeCycleValidationType.diagnosticKind().get(), descriptor.componentDefinitionType(), descriptor.componentAnnotation()); } } else if (scopedDependencies.size() > 1) { // Scoped components may depend on at most one scoped component. StringBuilder message = new StringBuilder(ErrorMessages.format(scope.get())).append(' ') .append(descriptor.componentDefinitionType().getQualifiedName()) .append(" depends on more than one scoped component:\n"); appendIndentedComponentsList(message, scopedDependencies); reportBuilder.addItem(message.toString(), descriptor.componentDefinitionType(), descriptor.componentAnnotation()); } else { // Dagger 1.x scope compatibility requires this be suppress-able. if (!scopeCycleValidationType.equals(ValidationType.NONE)) { validateScopeHierarchy(descriptor.componentDefinitionType(), descriptor.componentDefinitionType(), reportBuilder, new ArrayDeque<Equivalence.Wrapper<AnnotationMirror>>(), new ArrayDeque<TypeElement>()); } } } else { // Scopeless components may not depend on scoped components. if (!scopedDependencies.isEmpty()) { StringBuilder message = new StringBuilder(descriptor.componentDefinitionType().getQualifiedName()) .append(" (unscoped) cannot depend on scoped components:\n"); appendIndentedComponentsList(message, scopedDependencies); reportBuilder.addItem(message.toString(), descriptor.componentDefinitionType(), descriptor.componentAnnotation()); } } }
From source file:dagger2.internal.codegen.BindingGraphValidator.java
/** * Validates that the set of bindings resolved is consistent with the type of the binding, and * returns true if the bindings are valid. */// w w w .j a v a 2 s. c o m private boolean validateResolvedBinding(Deque<ResolvedRequest> path, ResolvedBindings resolvedBinding, Builder<BindingGraph> reportBuilder) { if (resolvedBinding.bindings().isEmpty()) { reportMissingBinding(path, reportBuilder); return false; } ImmutableSet.Builder<ProvisionBinding> provisionBindingsBuilder = ImmutableSet.builder(); ImmutableSet.Builder<ProductionBinding> productionBindingsBuilder = ImmutableSet.builder(); ImmutableSet.Builder<MembersInjectionBinding> membersInjectionBindingsBuilder = ImmutableSet.builder(); for (Binding binding : resolvedBinding.bindings()) { if (binding instanceof ProvisionBinding) { provisionBindingsBuilder.add((ProvisionBinding) binding); } if (binding instanceof ProductionBinding) { productionBindingsBuilder.add((ProductionBinding) binding); } if (binding instanceof MembersInjectionBinding) { membersInjectionBindingsBuilder.add((MembersInjectionBinding) binding); } } ImmutableSet<ProvisionBinding> provisionBindings = provisionBindingsBuilder.build(); ImmutableSet<ProductionBinding> productionBindings = productionBindingsBuilder.build(); ImmutableSet<MembersInjectionBinding> membersInjectionBindings = membersInjectionBindingsBuilder.build(); switch (resolvedBinding.bindingKey().kind()) { case CONTRIBUTION: if (!membersInjectionBindings.isEmpty()) { throw new IllegalArgumentException( "contribution binding keys should never have members injection bindings"); } Set<ContributionBinding> combined = Sets.union(provisionBindings, productionBindings); if (!validateNullability(path.peek().request(), combined, reportBuilder)) { return false; } if (!productionBindings.isEmpty() && doesPathRequireProvisionOnly(path)) { reportProviderMayNotDependOnProducer(path, reportBuilder); return false; } if ((provisionBindings.size() + productionBindings.size()) <= 1) { return true; } ImmutableListMultimap<BindingType, ContributionBinding> bindingsByType = ContributionBinding .bindingTypesFor(Iterables.<ContributionBinding>concat(provisionBindings, productionBindings)); if (bindingsByType.keySet().size() > 1) { reportMultipleBindingTypes(path, reportBuilder); return false; } else if (getOnlyElement(bindingsByType.keySet()).equals(BindingType.UNIQUE)) { reportDuplicateBindings(path, reportBuilder); return false; } break; case MEMBERS_INJECTION: if (!provisionBindings.isEmpty() || !productionBindings.isEmpty()) { throw new IllegalArgumentException( "members injection binding keys should never have contribution bindings"); } if (membersInjectionBindings.size() > 1) { reportDuplicateBindings(path, reportBuilder); return false; } if (membersInjectionBindings.size() == 1) { MembersInjectionBinding binding = getOnlyElement(membersInjectionBindings); if (!validateMembersInjectionBinding(binding, path, reportBuilder)) { return false; } } break; default: throw new AssertionError(); } return true; }