List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:com.facebook.buck.cxx.AbstractPrebuiltCxxLibraryGroupDescription.java
/** * @return the link args formed from the user-provided shared link line after resolving library * macro references./*from w ww.ja va2 s. c o m*/ */ private Iterable<Arg> getSharedLinkArgs(BuildTarget target, SourcePathResolver pathResolver, ImmutableMap<String, SourcePath> libs, ImmutableList<String> args) { ImmutableList.Builder<Arg> builder = ImmutableList.builder(); for (String arg : args) { Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO, REL_LIB_MACRO), arg); if (libRef.isPresent()) { SourcePath lib = libs.get(libRef.get().getSecond()); if (lib == null) { throw new HumanReadableException( "%s: library \"%s\" (in \"%s\") must refer to keys in the `sharedLibs` parameter", target, libRef.get().getSecond(), arg); } Arg libArg; if (libRef.get().getFirst().equals(LIB_MACRO)) { libArg = new SourcePathArg(pathResolver, lib); } else if (libRef.get().getFirst().equals(REL_LIB_MACRO)) { if (!(lib instanceof PathSourcePath)) { throw new HumanReadableException("%s: can only link prebuilt DSOs without sonames", target); } libArg = new RelativeLinkArg((PathSourcePath) lib); } else { throw new IllegalStateException(); } builder.add(libArg); } else { builder.add(new StringArg(arg)); } } return builder.build(); }
From source file:com.facebook.buck.doctor.UserInput.java
public boolean confirm(String question) throws IOException { ImmutableMap<String, Boolean> supportedResponses = ImmutableMap.of("", true, "y", true, "yes", true, "no", false, "n", false); for (;;) {//from ww w . ja v a 2 s. c o m output.println(); output.println(question + " (Y/n)?"); output.flush(); String line = reader.readLine(); // Stdin was closed. if (line == null) { return false; } String response = line.trim().toLowerCase(); if (supportedResponses.containsKey(response)) { return supportedResponses.get(response); } else { output.println("Please answer 'y' or 'n'."); } } }
From source file:com.facebook.buck.core.build.engine.buildinfo.BuildInfoRecorder.java
public BuildInfoRecorder(BuildTarget buildTarget, ProjectFilesystem projectFilesystem, BuildInfoStore buildInfoStore, Clock clock, BuildId buildId, ImmutableMap<String, String> environment) { this.buildTarget = buildTarget; this.pathToMetadataDirectory = BuildInfo.getPathToArtifactMetadataDirectory(buildTarget, projectFilesystem); this.projectFilesystem = projectFilesystem; this.buildInfoStore = buildInfoStore; this.clock = clock; this.buildId = buildId; this.artifactExtraData = ImmutableMap.<String, String>builder() .put("artifact_data", Optional.ofNullable(environment.get(BUCK_CACHE_DATA_ENV_VAR)).orElse("null")) .build();//w ww . j av a2 s .c o m this.metadataToWrite = new LinkedHashMap<>(); this.buildMetadata = new LinkedHashMap<>(); this.pathsToOutputs = new HashSet<>(); }
From source file:com.isotrol.impe3.pms.core.obj.PortalConfigurationObject.java
PortalConfiguration get(ImpeIAModel model) { checkState(!isError(), "Invalid configuration state"); final PortalConfigurationBuilder<?> cb = definition.builder(); final ImmutableMap<String, Item> parameters = definition.getParameters(); for (Entry<String, Object> ecv : values.entrySet()) { final String name = ecv.getKey(); final Class<?> type = parameters.get(name).getType(); final Object value = ecv.getValue(); try {//from w ww . j a va 2s . c o m if (Category.class == type) { cb.set(name, checkNotNull(model.getCategories().get((UUID) value))); } else if (ContentType.class == type) { cb.set(name, checkNotNull(model.getContentTypes().get((UUID) value))); } else { cb.set(name, value); } } catch (RuntimeException e) { Loggers.pms().error(LOG_PREFIX + "Error setting parameter [{}]", logArgs(name)); throw e; } } try { return cb.get(); } catch (RuntimeException e) { Loggers.pms().error(LOG_PREFIX + "Unable to build configuration", logArgs(null)); throw e; } }
From source file:org.apache.calcite.rel.rules.AggregateProjectPullUpConstantsRule.java
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final RelNode input = call.rel(1); assert !aggregate.indicator : "predicate ensured no grouping sets"; final int groupCount = aggregate.getGroupCount(); if (groupCount == 1) { // No room for optimization since we cannot convert from non-empty // GROUP BY list to the empty one. return;//from w w w . j a v a 2 s . co m } final RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder(); final RelMetadataQuery mq = RelMetadataQuery.instance(); final RelOptPredicateList predicates = mq.getPulledUpPredicates(aggregate.getInput()); if (predicates == null) { return; } final ImmutableMap<RexNode, RexNode> constants = ReduceExpressionsRule.predicateConstants(RexNode.class, rexBuilder, predicates); final NavigableMap<Integer, RexNode> map = new TreeMap<>(); for (int key : aggregate.getGroupSet()) { final RexInputRef ref = rexBuilder.makeInputRef(aggregate.getInput(), key); if (constants.containsKey(ref)) { map.put(key, constants.get(ref)); } } // None of the group expressions are constant. Nothing to do. if (map.isEmpty()) { return; } if (groupCount == map.size()) { // At least a single item in group by is required. // Otherwise "GROUP BY 1, 2" might be altered to "GROUP BY ()". // Removing of the first element is not optimal here, // however it will allow us to use fast path below (just trim // groupCount). map.remove(map.navigableKeySet().first()); } ImmutableBitSet newGroupSet = aggregate.getGroupSet(); for (int key : map.keySet()) { newGroupSet = newGroupSet.clear(key); } final int newGroupCount = newGroupSet.cardinality(); // If the constants are on the trailing edge of the group list, we just // reduce the group count. final RelBuilder relBuilder = call.builder(); relBuilder.push(input); if (map.navigableKeySet().first() == newGroupCount) { // Clone aggregate calls. final List<AggregateCall> newAggCalls = new ArrayList<>(); for (AggregateCall aggCall : aggregate.getAggCallList()) { newAggCalls.add( aggCall.adaptTo(input, aggCall.getArgList(), aggCall.filterArg, groupCount, newGroupCount)); } relBuilder.aggregate(relBuilder.groupKey(newGroupSet, false, null), newAggCalls); } else { // Create the mapping from old field positions to new field // positions. final Permutation mapping = new Permutation(input.getRowType().getFieldCount()); mapping.identity(); // Ensure that the first positions in the mapping are for the new // group columns. for (int i = 0, groupOrdinal = 0, constOrdinal = newGroupCount; i < groupCount; ++i) { if (map.containsKey(i)) { mapping.set(i, constOrdinal++); } else { mapping.set(i, groupOrdinal++); } } // Adjust aggregate calls for new field positions. final List<AggregateCall> newAggCalls = new ArrayList<>(); for (AggregateCall aggCall : aggregate.getAggCallList()) { final int argCount = aggCall.getArgList().size(); final List<Integer> args = new ArrayList<>(argCount); for (int j = 0; j < argCount; j++) { final Integer arg = aggCall.getArgList().get(j); args.add(mapping.getTarget(arg)); } final int filterArg = aggCall.filterArg < 0 ? aggCall.filterArg : mapping.getTarget(aggCall.filterArg); newAggCalls.add(aggCall.adaptTo(relBuilder.peek(), args, filterArg, groupCount, newGroupCount)); } // Aggregate on projection. relBuilder.aggregate(relBuilder.groupKey(newGroupSet, false, null), newAggCalls); } // Create a projection back again. List<Pair<RexNode, String>> projects = new ArrayList<>(); int source = 0; for (RelDataTypeField field : aggregate.getRowType().getFieldList()) { RexNode expr; final int i = field.getIndex(); if (i >= groupCount) { // Aggregate expressions' names and positions are unchanged. expr = relBuilder.field(i - map.size()); } else if (map.containsKey(i)) { // Re-generate the constant expression in the project. expr = map.get(i); } else { // Project the aggregation expression, in its original // position. expr = relBuilder.field(source); ++source; } projects.add(Pair.of(expr, field.getName())); } relBuilder.project(Pair.left(projects), Pair.right(projects)); // inverse call.transformTo(relBuilder.build()); }
From source file:org.apache.flume.source.SNMPQuerySource.java
@Override public void configure(Context context) { ImmutableMap<String, String> parameters; String baseString = "oid"; boolean notFound = true; int i = 0;//from w ww .j a v a2 s . c o m parameters = context.getParameters(); logger.info("v1"); logger.info("parameters: " + parameters); pdu = new PDU(); do { i++; if (!parameters.containsKey(baseString + i)) { notFound = false; } else { logger.info("parameter: " + parameters.get(baseString + i)); pdu.add(new VariableBinding(new OID(parameters.get(baseString + i)))); } } while (notFound); bindAddress = context.getString("host"); bindPort = context.getInteger("port", DEFAULT_PORT); delayQuery = context.getInteger("delay", DEFAULT_DELAY); }
From source file:org.gradle.internal.component.external.model.maven.RealisedMavenModuleResolveMetadataSerializationHelper.java
private Map<String, ConfigurationMetadata> readMavenConfigurationsAndDerivedVariants(Decoder decoder, DefaultMavenModuleResolveMetadata metadata) throws IOException { ImmutableMap<String, Configuration> configurationDefinitions = metadata.getConfigurationDefinitions(); boolean derivedVariants = decoder.readBoolean(); int configurationsCount = decoder.readSmallInt(); Map<String, ConfigurationMetadata> configurations = Maps.newHashMapWithExpectedSize(configurationsCount); for (int i = 0; i < configurationsCount; i++) { String configurationName = decoder.readString(); Configuration configuration = configurationDefinitions.get(configurationName); ImmutableSet<String> hierarchy = LazyToRealisedModuleComponentResolveMetadataHelper .constructHierarchy(configuration, configurationDefinitions); ImmutableAttributes attributes = getAttributeContainerSerializer().read(decoder); ImmutableCapabilities capabilities = readCapabilities(decoder); RealisedConfigurationMetadata configurationMetadata = new RealisedConfigurationMetadata( metadata.getId(), configurationName, configuration.isTransitive(), configuration.isVisible(), hierarchy, RealisedMavenModuleResolveMetadata.getArtifactsForConfiguration(metadata.getId(), configurationName), ImmutableList.<ExcludeMetadata>of(), attributes, capabilities); ImmutableList.Builder<ModuleDependencyMetadata> builder = ImmutableList.builder(); int dependenciesCount = decoder.readSmallInt(); for (int j = 0; j < dependenciesCount; j++) { byte dependencyType = decoder.readByte(); switch (dependencyType) { case GRADLE_DEPENDENCY_METADATA: builder.add(readDependencyMetadata(decoder)); break; case MAVEN_DEPENDENCY_METADATA: MavenDependencyDescriptor mavenDependencyDescriptor = readMavenDependency(decoder); ModuleDependencyMetadata dependencyMetadata = RealisedMavenModuleResolveMetadata.contextualize( configurationMetadata, metadata.getId(), mavenDependencyDescriptor, metadata.isImprovedPomSupportEnabled()); builder.add(dependencyMetadata.withReason(decoder.readNullableString())); break; case IVY_DEPENDENCY_METADATA: throw new IllegalStateException("Unexpected Ivy dependency for Maven module"); default: throw new IllegalStateException("Unknown dependency type " + dependencyType); }//from ww w. j av a 2 s. c o m } ImmutableList<ModuleDependencyMetadata> dependencies = builder.build(); configurationMetadata.setDependencies(dependencies); configurations.put(configurationName, configurationMetadata); if (derivedVariants) { if (configurationName.equals("compile")) { ConfigurationMetadata compileDerivedVariant = RealisedMavenModuleResolveMetadata .withUsageAttribute(configurationMetadata, Usage.JAVA_API, metadata.getAttributesFactory(), attributes, metadata.getObjectInstantiator()); configurations.put(COMPILE_DERIVED_VARIANT_NAME, compileDerivedVariant); } else if (configurationName.equals("runtime")) { ConfigurationMetadata runtimeDerivedVariant = RealisedMavenModuleResolveMetadata .withUsageAttribute(configurationMetadata, Usage.JAVA_RUNTIME, metadata.getAttributesFactory(), attributes, metadata.getObjectInstantiator()); configurations.put(RUNTIME_DERIVED_VARIANT_NAME, runtimeDerivedVariant); } } } return configurations; }
From source file:com.facebook.buck.versions.AbstractVersionedTargetGraphBuilder.java
/** * @return the {@link BuildTarget} to use in the resolved target graph, formed by adding a flavor * generated from the given version selections. *///from w ww. j av a2 s . c o m protected final Optional<BuildTarget> getTranslateBuildTarget(TargetNode<?> node, ImmutableMap<BuildTarget, Version> selectedVersions) { BuildTarget originalTarget = node.getBuildTarget(); node = resolveVersions(node, selectedVersions); BuildTarget newTarget = node.getBuildTarget(); if (TargetGraphVersionTransformations.isVersionPropagator(node)) { VersionInfo info = getVersionInfo(node); Collection<BuildTarget> versionedDeps = info.getVersionDomain().keySet(); TreeMap<BuildTarget, Version> versions = new TreeMap<>(); for (BuildTarget depTarget : versionedDeps) { versions.put(depTarget, selectedVersions.get(depTarget)); } if (!versions.isEmpty()) { Flavor versionedFlavor = ParallelVersionedTargetGraphBuilder.getVersionedFlavor(versions); newTarget = node.getBuildTarget().withAppendedFlavors(versionedFlavor); } } return newTarget.equals(originalTarget) ? Optional.empty() : Optional.of(newTarget); }
From source file:org.opendaylight.sxp.route.core.RouteReactorImpl.java
/** * Add all unchanged {@link RoutingDefinition} into provided {@link List} * * @param routingDifference contains configuration changes * @param outcomingRouteDefinitions where result will be stored *//* w w w . jav a 2 s .c om*/ private void collectUnchanged(final MapDifference<IpAddress, RoutingDefinition> routingDifference, final List<RoutingDefinition> outcomingRouteDefinitions) { final SxpClusterRoute sxpClusterRouteOper = datastoreAccess.readSynchronous( SxpClusterRouteManager.SXP_CLUSTER_ROUTE_CONFIG_PATH, LogicalDatastoreType.OPERATIONAL); final ImmutableMap<IpAddress, RoutingDefinition> routingDefinitionMap = Optional .ofNullable(sxpClusterRouteOper).map(SxpClusterRoute::getRoutingDefinition) .map((routingDefinitions -> Maps.uniqueIndex(routingDefinitions, RoutingDefinition::getIpAddress))) .orElse(ImmutableMap.of()); routingDifference.entriesInCommon().forEach((virtualIface, routingDefinition) -> { final RoutingDefinition routingDef = routingDefinitionMap.get(virtualIface); if (routingDef != null) { outcomingRouteDefinitions.add(routingDef); } else { LOG.debug("Missing unchainged routing definition in current DS/operational: {}", routingDefinition); } }); }
From source file:io.fabric8.jube.apimaster.ApiMasterService.java
/** * Lets ensure that the "kubernetes" and "kubernetes-ro" services are defined so that folks can access the core * REST API via kubernetes services/*w w w.j a v a 2 s . com*/ */ protected void ensureModelHasKubernetesServices(String hostName, String port) { ImmutableMap<String, Service> serviceMap = model.getServiceMap(); Service service = null; try { service = serviceMap.get(ServiceIDs.KUBERNETES_SERVICE_ID); if (service == null) { service = createService(hostName, port); service.setId(ServiceIDs.KUBERNETES_SERVICE_ID); service.setSelector(createKubernetesServiceLabels()); createService(service); } service = serviceMap.get(ServiceIDs.KUBERNETES_RO_SERVICE_ID); if (service == null) { service = createService(hostName, port); service.setId(ServiceIDs.KUBERNETES_RO_SERVICE_ID); service.setSelector(createKubernetesServiceLabels()); createService(service); } service = serviceMap.get(ServiceIDs.FABRIC8_CONSOLE_SERVICE_ID); if (service == null) { service = createService(hostName, port); service.setId(ServiceIDs.FABRIC8_CONSOLE_SERVICE_ID); service.setSelector(createFabric8ConsoleServiceLabels()); createService(service); } } catch (Exception e) { LOG.error("Failed to create service " + service + ". " + e, e); } }