List of usage examples for com.google.common.collect ImmutableMap values
public ImmutableCollection<V> values()
From source file:com.google.auto.value.processor.AutoAnnotationProcessor.java
private void processMethod(ExecutableElement method) { if (!method.getModifiers().contains(Modifier.STATIC)) { throw abortWithError("@AutoAnnotation method must be static", method); }/*from ww w .ja v a2s. c om*/ TypeElement annotationElement = getAnnotationReturnType(method); TypeMirror annotationTypeMirror = annotationElement.asType(); Set<Class<?>> wrapperTypesUsedInCollections = wrapperTypesUsedInCollections(method); ImmutableMap<String, ExecutableElement> memberMethods = getMemberMethods(annotationElement); Set<TypeMirror> memberTypes = getMemberTypes(memberMethods.values()); Set<TypeMirror> referencedTypes = getReferencedTypes(annotationTypeMirror, method, memberTypes, wrapperTypesUsedInCollections); TypeElement methodClass = (TypeElement) method.getEnclosingElement(); String pkg = TypeSimplifier.packageNameOf(methodClass); TypeSimplifier typeSimplifier = new TypeSimplifier(typeUtils, pkg, referencedTypes, annotationTypeMirror); AnnotationOutput annotationOutput = new AnnotationOutput(typeSimplifier); ImmutableMap<String, AnnotationValue> defaultValues = getDefaultValues(annotationElement); ImmutableMap<String, Member> members = getMembers(method, memberMethods, typeSimplifier, annotationOutput); ImmutableMap<String, Parameter> parameters = getParameters(annotationElement, method, members, typeSimplifier); validateParameters(annotationElement, method, members, parameters, defaultValues); String generatedClassName = generatedClassName(method); AutoAnnotationTemplateVars vars = new AutoAnnotationTemplateVars(); vars.annotationFullName = annotationElement.toString(); vars.annotationName = typeSimplifier.simplify(annotationElement.asType()); vars.className = generatedClassName; vars.imports = typeSimplifier.typesToImport(); vars.generated = typeSimplifier.simplify(getTypeMirror(Generated.class)); vars.arrays = typeSimplifier.simplify(getTypeMirror(Arrays.class)); vars.members = members; vars.params = parameters; vars.pkg = pkg; vars.wrapperTypesUsedInCollections = wrapperTypesUsedInCollections; vars.gwtCompatible = isGwtCompatible(annotationElement); ImmutableMap<String, Integer> invariableHashes = invariableHashes(members, parameters.keySet()); vars.invariableHashSum = 0; for (int h : invariableHashes.values()) { vars.invariableHashSum += h; } vars.invariableHashes = invariableHashes.keySet(); String text = vars.toText(); text = Reformatter.fixup(text); String fullName = fullyQualifiedName(pkg, generatedClassName); writeSourceFile(fullName, text, methodClass); }
From source file:com.spectralogic.ds3autogen.net.NetCodeGenerator.java
/** * Generates the .net code for the types *///from w ww . j a va 2 s. c o m private void generateAllTypes(final ImmutableMap<String, Ds3Type> typeMap) throws IOException, TemplateException { if (isEmpty(typeMap)) { LOG.info("There were no types to generate"); return; } for (final Ds3Type ds3Type : typeMap.values()) { generateType(ds3Type, typeMap); } }
From source file:com.google.devtools.build.lib.skyframe.ToplevelSkylarkAspectFunction.java
@Nullable @Override//from w ww . j ava 2 s . c om public SkyValue compute(SkyKey skyKey, Environment env) throws LoadSkylarkAspectFunctionException, InterruptedException { SkylarkAspectLoadingKey aspectLoadingKey = (SkylarkAspectLoadingKey) skyKey.argument(); String skylarkValueName = aspectLoadingKey.getSkylarkValueName(); SkylarkImport extensionFile = aspectLoadingKey.getSkylarkImport(); // Find label corresponding to skylark file, if one exists. ImmutableMap<String, Label> labelLookupMap; try { labelLookupMap = SkylarkImportLookupFunction.findLabelsForLoadStatements( ImmutableList.of(extensionFile), Label.parseAbsoluteUnchecked("//:empty"), env); } catch (SkylarkImportFailedException e) { env.getListener().handle(Event.error(e.getMessage())); throw new LoadSkylarkAspectFunctionException(new AspectCreationException(e.getMessage())); } if (labelLookupMap == null) { return null; } SkylarkAspect skylarkAspect; Label extensionFileLabel = Iterables.getOnlyElement(labelLookupMap.values()); try { skylarkAspect = AspectFunction.loadSkylarkAspect(env, extensionFileLabel, skylarkValueName); if (skylarkAspect == null) { return null; } if (!skylarkAspect.getParamAttributes().isEmpty()) { throw new AspectCreationException( "Cannot instantiate parameterized aspect " + skylarkAspect.getName() + " at the top level.", extensionFileLabel); } } catch (AspectCreationException e) { throw new LoadSkylarkAspectFunctionException(e); } SkyKey aspectKey = ActionLookupValue.key(AspectValue.createAspectKey(aspectLoadingKey.getTargetLabel(), aspectLoadingKey.getTargetConfiguration(), new AspectDescriptor(skylarkAspect.getAspectClass(), AspectParameters.EMPTY), aspectLoadingKey.getAspectConfiguration())); return env.getValue(aspectKey); }
From source file:org.excalibur.driver.google.compute.GoogleCompute.java
@Override public Instances aggregateInstances() { final Instances instances = new Instances(); ImmutableMap<String, Instance> allComputeInstances = getAllComputeInstances(); for (Instance inst : allComputeInstances.values()) { instances.addInstance(getInstancefromComputeInstance(inst)); }/*from ww w. jav a 2 s . co m*/ return instances; }
From source file:com.facebook.buck.android.AndroidBinaryResourcesGraphEnhancer.java
AndroidBinaryResourcesGraphEnhancementResult enhance(AndroidPackageableCollection packageableCollection) { boolean needsResourceFiltering = resourceFilter.isEnabled() || postFilterResourcesCmd.isPresent() || resourceCompressionMode.isStoreStringsAsAssets() || !locales.isEmpty(); int packageIdOffset = 0; ImmutableSet.Builder<SourcePath> pathToRDotTxtFiles = ImmutableSet.builder(); ImmutableMap.Builder<APKModule, FilteredResourcesProvider> filteredResourcesProviderBuilder = ImmutableMap .builder();//from ww w. j a v a2 s.c om AndroidBinaryResourcesGraphEnhancementResult.Builder resultBuilder = AndroidBinaryResourcesGraphEnhancementResult .builder(); List<SourcePath> apkResourceDependencyList = new ArrayList<>(); for (APKModule module : apkModuleGraph.getAPKModules()) { AndroidPackageableCollection.ResourceDetails resourceDetails = packageableCollection .getResourceDetails().get(module); if (resourceDetails == null) { throw new RuntimeException( String.format("Missing resource details for module %s", module.getName())); } ImmutableSortedSet<BuildRule> resourceRules = getTargetsAsRules( resourceDetails.getResourcesWithNonEmptyResDir()); ImmutableCollection<BuildRule> rulesWithResourceDirectories = ruleFinder .filterBuildRuleInputs(resourceDetails.getResourceDirectories()); InternalFlavor moduleFlavor = InternalFlavor.of(module.getName()); FilteredResourcesProvider filteredResourcesProvider; if (needsResourceFiltering) { ResourcesFilter resourcesFilter = createResourcesFilter(moduleFlavor, resourceDetails, resourceRules, rulesWithResourceDirectories); graphBuilder.addToIndex(resourcesFilter); filteredResourcesProvider = resourcesFilter; resourceRules = ImmutableSortedSet.of(resourcesFilter); } else { filteredResourcesProvider = new IdentityResourcesProvider(resourceDetails.getResourceDirectories()); } filteredResourcesProviderBuilder.put(module, filteredResourcesProvider); AaptOutputInfo aaptOutputInfo; SourcePath manifestPath; if (module.isRootModule()) { manifestPath = createBaseManifestRule(packageableCollection, module); } else { if (!moduleManifestSkeleton.isPresent()) { continue; } AndroidManifest moduleManifestMergeRule = new AndroidManifest( buildTarget.withAppendedFlavors(MANIFEST_MERGE_FLAVOR, moduleFlavor), projectFilesystem, ruleFinder, moduleManifestSkeleton.get(), module, packageableCollection.getAndroidManifestPieces().get(module)); graphBuilder.addToIndex(moduleManifestMergeRule); manifestPath = moduleManifestMergeRule.getSourcePathToOutput(); } switch (aaptMode) { case AAPT1: { // Create the AaptPackageResourcesBuildable. AaptPackageResources aaptPackageResources = createAaptPackageResources( buildTarget.withAppendedFlavors(AAPT_PACKAGE_FLAVOR, moduleFlavor), manifestPath, ImmutableList.copyOf(apkResourceDependencyList), resourceDetails, filteredResourcesProvider); graphBuilder.addToIndex(aaptPackageResources); aaptOutputInfo = aaptPackageResources.getAaptOutputInfo(); apkResourceDependencyList.add(aaptOutputInfo.getPrimaryResourcesApkPath()); } break; case AAPT2: { Aapt2Link aapt2Link = createAapt2Link(packageIdOffset, moduleFlavor, manifestPath, resourceDetails, needsResourceFiltering ? Optional.of(filteredResourcesProvider) : Optional.empty(), ImmutableList.copyOf(apkResourceDependencyList), useProtoFormat); graphBuilder.addToIndex(aapt2Link); if (useProtoFormat) { // also build an ARSC flavor that we can use to as parent dependencies to other // modules Aapt2Link aapt2LinkArsc = createAapt2Link(packageIdOffset, moduleFlavor, manifestPath, resourceDetails, needsResourceFiltering ? Optional.of(filteredResourcesProvider) : Optional.empty(), ImmutableList.copyOf(apkResourceDependencyList), false); graphBuilder.addToIndex(aapt2LinkArsc); apkResourceDependencyList.add(aapt2LinkArsc.getAaptOutputInfo().getPrimaryResourcesApkPath()); } else { apkResourceDependencyList.add(aapt2Link.getAaptOutputInfo().getPrimaryResourcesApkPath()); } aaptOutputInfo = aapt2Link.getAaptOutputInfo(); } break; default: throw new RuntimeException("Unexpected aaptMode: " + aaptMode); } if (module.isRootModule()) { Optional<PackageStringAssets> packageStringAssets = Optional.empty(); if (resourceCompressionMode.isStoreStringsAsAssets()) { // TODO(cjhopman): we should be able to support this in exo-for-resources if (exopackageForResources) { throw new HumanReadableException( "exopackage_modes and resource_compression_mode for android_binary %s are " + "incompatible. Either remove %s from exopackage_modes or disable storing strings " + "as assets.", buildTarget, ExopackageMode.RESOURCES); } packageStringAssets = Optional.of(createPackageStringAssets(resourceRules, rulesWithResourceDirectories, filteredResourcesProvider, aaptOutputInfo)); graphBuilder.addToIndex(packageStringAssets.get()); } resultBuilder.setPackageStringAssets(packageStringAssets); createMergeAndExoResources(packageableCollection, pathToRDotTxtFiles, resultBuilder, aaptOutputInfo, packageStringAssets); // Create a rule that copies the AndroidManifest. This allows the AndroidBinary rule (and // exopackage installation rules) to have a runtime dep on the manifest without having to // have a runtime dep on the full aapt output. ExportFile manifestCopyRule = new ExportFile( originalBuildTarget.withAppendedFlavors(COPY_MANIFEST_FLAVOR), projectFilesystem, ruleFinder, "AndroidManifest.xml", ExportFileDescription.Mode.COPY, aaptOutputInfo.getAndroidManifestXml(), ExportFileDirectoryAction.FAIL); graphBuilder.addToIndex(manifestCopyRule); resultBuilder.setAndroidManifestXml(manifestCopyRule.getSourcePathToOutput()); } else { resultBuilder.putModuleResourceApkPaths(module, aaptOutputInfo.getPrimaryResourcesApkPath()); } resultBuilder.addAaptGeneratedProguardConfigFiles(aaptOutputInfo.getAaptGeneratedProguardConfigFile()); pathToRDotTxtFiles.add(aaptOutputInfo.getPathToRDotTxt()); packageIdOffset++; } Optional<GenerateRDotJava> generateRDotJava = Optional.empty(); ImmutableMap<APKModule, FilteredResourcesProvider> allFilteredResourceProviders = filteredResourcesProviderBuilder .build(); if (allFilteredResourceProviders.values().stream().anyMatch(f -> f.hasResources())) { generateRDotJava = Optional.of(createGenerateRDotJava(pathToRDotTxtFiles.build(), getTargetsAsRules(packageableCollection.getResourceDetails().values().stream() .flatMap(r -> r.getResourcesWithNonEmptyResDir().stream()) .collect(ImmutableList.toImmutableList())), allFilteredResourceProviders.values())); graphBuilder.addToIndex(generateRDotJava.get()); if (shouldBuildStringSourceMap) { graphBuilder .addToIndex(createGenerateStringResources(allFilteredResourceProviders.values().asList())); } } return resultBuilder .setRDotJavaDir(generateRDotJava.map(GenerateRDotJava::getSourcePathToGeneratedRDotJavaSrcFiles)) .build(); }
From source file:com.spectralogic.ds3autogen.java.JavaCodeGenerator.java
/** * Generates the Models described within the Ds3ApiSpec that are being used * by at least one request//from w w w .j ava 2 s . co m * @throws IOException * @throws TemplateException */ private void generateAllModels(final ImmutableMap<String, Ds3Type> types) throws IOException, TemplateException { if (isEmpty(types)) { LOG.info("There were no models to generate"); return; } for (final Ds3Type ds3Type : types.values()) { generateModel(ds3Type); } }
From source file:org.nuxeo.ecm.core.storage.dbs.DBSCachingRepository.java
@Override public List<State> readStates(List<String> ids) { ImmutableMap<String, State> statesMap = cache.getAllPresent(ids); List<String> idsToRetrieve = new ArrayList<>(ids); idsToRetrieve.removeAll(statesMap.keySet()); // Read missing states from repository List<State> states = repository.readStates(idsToRetrieve); // Cache them states.forEach(this::putInCache); // Add previous cached one states.addAll(statesMap.values()); // Sort them// w w w. j a v a 2 s .c om states.sort(Comparator.comparing(state -> state.get(KEY_ID).toString(), Ordering.explicit(ids))); return states; }
From source file:se.sics.caracaldb.global.DefaultPolicy.java
private Pair<ExtremeKMap<Double, Address>, ExtremeKMap<Double, Address>> updateAverages( ImmutableMap<Address, Stats.Report> stats) { ExtremeKMap<Double, Address> xKMemory = new ExtremeKMap<Double, Address>(K); ExtremeKMap<Double, Address> xKCpu = new ExtremeKMap<Double, Address>(K); double totalCpu = 0.0; double totalMemory = 0.0; long totalClusterSize = 0; for (Stats.Report report : stats.values()) { totalCpu += report.cpuUsage;// ww w . j ava2s .c om totalMemory += report.memoryUsage; totalClusterSize += report.averageSize * report.numberOfVNodes; xKMemory.put(report.memoryUsage, report.atHost); xKCpu.put(report.cpuUsage, report.atHost); } double newMemAvg = totalMemory / ((double) stats.size()); double newCpuAvg = totalCpu / ((double) stats.size()); averageHostSize = Stats.floorDiv(totalClusterSize, stats.size()); // Exponential moving average with coefficient ALPHA memoryAvg = ALPHA * newMemAvg + MINUS_ALPHA * memoryAvg; cpuAvg = ALPHA * newCpuAvg + MINUS_ALPHA * cpuAvg; LOG.info("Current cluster stats: Memory: {}%, CPU: {}% -- Moving: Memory: {}%, CPU: {}%", newMemAvg, newCpuAvg, memoryAvg, cpuAvg); return Pair.with(xKMemory, xKCpu); }
From source file:com.facebook.buck.cxx.CxxLibraryDescription.java
/** * Create all build rules needed to generate the static library. * * @return build rule that builds the static library version of this C/C++ library. *//*from w ww . jav a2 s . c om*/ private static BuildRule createStaticLibraryBuildRule(BuildRuleParams params, BuildRuleResolver resolver, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, Arg args, CxxSourceRuleFactory.PicType pic) throws NoSuchBuildTargetException { SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver); SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder); // Create rules for compiling the object files. ImmutableMap<CxxPreprocessAndCompile, SourcePath> objects = CxxDescriptionEnhancer.requireObjects(params, resolver, sourcePathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, pic, args); // Write a build rule to create the archive for this C/C++ library. BuildTarget staticTarget = CxxDescriptionEnhancer.createStaticLibraryBuildTarget(params.getBuildTarget(), cxxPlatform.getFlavor(), pic); if (objects.isEmpty()) { return new NoopBuildRule(new BuildRuleParams(staticTarget, Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()), params.getProjectFilesystem(), params.getCellRoots()), sourcePathResolver); } Path staticLibraryPath = CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(), params.getBuildTarget(), cxxPlatform.getFlavor(), pic, cxxPlatform.getStaticLibraryExtension()); return Archive.from(staticTarget, params, sourcePathResolver, ruleFinder, cxxPlatform, cxxBuckConfig.getArchiveContents(), staticLibraryPath, ImmutableList.copyOf(objects.values())); }
From source file:com.facebook.buck.lua.LuaBinaryDescription.java
private SymlinkTree createSymlinkTree(BuildTarget linkTreeTarget, BuildRuleParams params, BuildRuleResolver resolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, Path root, ImmutableMap<String, SourcePath> components) { return resolver.addToIndex(SymlinkTree.from(params.copyWithChanges(linkTreeTarget, Suppliers.ofInstance(//from w w w . j av a2 s . co m ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(components.values()))), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, root, components)); }