List of usage examples for com.google.common.collect Maps asMap
@GwtIncompatible("NavigableMap") public static <K, V> NavigableMap<K, V> asMap(NavigableSet<K> set, Function<? super K, V> function)
From source file:org.pentaho.di.trans.dataservice.serialization.DataServiceMetaStoreUtil.java
public DataServiceMeta getDataServiceByStepName(TransMeta transMeta, String stepName) { Set<Integer> cacheKeys = createCacheKeys(transMeta, stepName); for (Map.Entry<Integer, String> entry : stepCache.getAll(cacheKeys).entrySet()) { String serviceName = entry.getValue(); if (serviceName.isEmpty()) { // Step is marked as not having a Data Service return null; }//from w ww.ja v a 2s .c o m // Check if Data Service is still valid DataServiceMeta dataServiceMeta; try { dataServiceMeta = getDataService(serviceName, transMeta); } catch (MetaStoreException e) { dataServiceMeta = null; } if (dataServiceMeta != null && dataServiceMeta.getStepname().equals(stepName)) { return dataServiceMeta; } else { stepCache.remove(entry.getKey(), serviceName); } } // Look up from embedded metastore for (DataServiceMeta dataServiceMeta : getDataServices(transMeta)) { if (dataServiceMeta.getStepname().equalsIgnoreCase(stepName)) { return dataServiceMeta; } } // Data service not found on step, store negative result in the cache stepCache.putAll(Maps.asMap(cacheKeys, Functions.constant(""))); return null; }
From source file:google.registry.tools.server.ListObjectsAction.java
/** Converts the provided table of data to text, formatted using the provided column widths. */ private List<String> generateFormattedData(ImmutableTable<T, String, String> data, ImmutableMap<String, Integer> columnWidths) { Function<Map<String, String>, String> rowFormatter = makeRowFormatter(columnWidths); List<String> lines = new ArrayList<>(); if (isHeaderRowInUse(data)) { // Add a row of headers (column names mapping to themselves). Map<String, String> headerRow = Maps.asMap(data.columnKeySet(), Functions.<String>identity()); lines.add(rowFormatter.apply(headerRow)); // Add a row of separator lines (column names mapping to '-' * column width). Map<String, String> separatorRow = Maps.transformValues(columnWidths, new Function<Integer, String>() { @Override/* w w w . j a v a 2 s . com*/ public String apply(Integer width) { return Strings.repeat("-", width); } }); lines.add(rowFormatter.apply(separatorRow)); } // Add the actual data rows. for (Map<String, String> row : data.rowMap().values()) { lines.add(rowFormatter.apply(row)); } return lines; }
From source file:org.robotframework.ide.eclipse.main.plugin.launch.local.RobotLaunchConfiguration.java
public void setSuitePaths(final Map<String, List<String>> suitesToCases) throws CoreException { // test case names should be always in lower case final ILaunchConfigurationWorkingCopy launchCopy = asWorkingCopy(); final Map<String, String> suites = Maps.asMap(suitesToCases.keySet(), new Function<String, String>() { @Override//from ww w .j a v a2 s. co m public String apply(final String path) { final List<String> testSuites = new ArrayList<>(); final Iterable<String> temp = filter(suitesToCases.get(path), Predicates.notNull()); for (final String s : temp) { testSuites.add(s.toLowerCase()); } return String.join("::", testSuites); } }); launchCopy.setAttribute(TEST_SUITES_ATTRIBUTE, suites); }
From source file:com.microsoft.azure.management.appservice.implementation.WebAppBaseImpl.java
@SuppressWarnings("unchecked") Observable<FluentT> cacheAppSettingsAndConnectionStrings() { final FluentT self = (FluentT) this; return Observable.zip(listAppSettings(), listConnectionStrings(), listSlotConfigurations(), new Func3<StringDictionaryInner, ConnectionStringDictionaryInner, SlotConfigNamesResourceInner, FluentT>() { @Override/* www.ja v a 2 s. c om*/ public FluentT call(final StringDictionaryInner appSettingsInner, final ConnectionStringDictionaryInner connectionStringsInner, final SlotConfigNamesResourceInner slotConfigs) { cachedAppSettings = new HashMap<>(); cachedConnectionStrings = new HashMap<>(); if (appSettingsInner != null && appSettingsInner.properties() != null) { cachedAppSettings = Maps.asMap(appSettingsInner.properties().keySet(), new Function<String, AppSetting>() { @Override public AppSetting apply(String input) { return new AppSettingImpl(input, appSettingsInner.properties().get(input), slotConfigs.appSettingNames() != null && slotConfigs.appSettingNames().contains(input)); } }); } if (connectionStringsInner != null && connectionStringsInner.properties() != null) { cachedConnectionStrings = Maps.asMap(connectionStringsInner.properties().keySet(), new Function<String, ConnectionString>() { @Override public ConnectionString apply(String input) { return new ConnectionStringImpl(input, connectionStringsInner.properties().get(input), slotConfigs.connectionStringNames() != null && slotConfigs.connectionStringNames().contains(input)); } }); } return self; } }); }
From source file:dagger2.internal.codegen.ComponentGenerator.java
/** * Writes out a builder for a component or subcomponent. * * @param input the component or subcomponent * @param componentApiName the API name of the component we're building (not our impl) * @param componentImplName the implementation name of the component we're building * @param componentWriter the class we're adding this builder to * @param componentContributionFields a map of member selects so we can later use the fields */// ww w.j a v a2s. co m private ClassWriter writeBuilder(BindingGraph input, ClassName componentApiName, ClassName componentImplName, ClassWriter componentWriter, Map<TypeElement, MemberSelect> componentContributionFields) { ClassWriter builderWriter; Optional<BuilderSpec> builderSpec = input.componentDescriptor().builderSpec(); switch (input.componentDescriptor().kind()) { case COMPONENT: case PRODUCTION_COMPONENT: builderWriter = componentWriter.addNestedClass("Builder"); builderWriter.addModifiers(STATIC); // Only top-level components have the factory builder() method. // Mirror the user's builder API type if they had one. MethodWriter builderFactoryMethod = builderSpec.isPresent() ? componentWriter.addMethod(builderSpec.get().builderDefinitionType().asType(), "builder") : componentWriter.addMethod(builderWriter, "builder"); builderFactoryMethod.addModifiers(PUBLIC, STATIC); builderFactoryMethod.body().addSnippet("return new %s();", builderWriter.name()); break; case SUBCOMPONENT: verify(builderSpec.isPresent()); // we only write subcomponent builders if there was a spec builderWriter = componentWriter.addNestedClass(componentApiName.simpleName() + "Builder"); break; default: throw new IllegalStateException(); } builderWriter.addModifiers(FINAL); builderWriter.addConstructor().addModifiers(PRIVATE); if (builderSpec.isPresent()) { builderWriter.addModifiers(PRIVATE); TypeElement builderType = builderSpec.get().builderDefinitionType(); switch (builderType.getKind()) { case CLASS: builderWriter.setSuperType(builderType); break; case INTERFACE: builderWriter.addImplementedType(builderType); break; default: throw new IllegalStateException("not a class or interface: " + builderType); } } else { builderWriter.addModifiers(PUBLIC); } // the full set of types that calling code uses to construct a component instance ImmutableMap<TypeElement, String> componentContributionNames = ImmutableMap .copyOf(Maps.asMap( Sets.union( Sets.union(input.transitiveModules().keySet(), input.componentDescriptor().dependencies()), input.componentDescriptor().executorDependency().asSet()), Functions.compose(CaseFormat.UPPER_CAMEL.converterTo(LOWER_CAMEL), new Function<TypeElement, String>() { @Override public String apply(TypeElement input) { return input.getSimpleName().toString(); } }))); MethodWriter buildMethod; if (builderSpec.isPresent()) { ExecutableElement specBuildMethod = builderSpec.get().buildMethod(); // Note: we don't use the specBuildMethod.getReturnType() as the return type // because it might be a type variable. We make use of covariant returns to allow // us to return the component type, which will always be valid. buildMethod = builderWriter.addMethod(componentApiName, specBuildMethod.getSimpleName().toString()); buildMethod.annotate(Override.class); } else { buildMethod = builderWriter.addMethod(componentApiName, "build"); } buildMethod.addModifiers(PUBLIC); for (Entry<TypeElement, String> entry : componentContributionNames.entrySet()) { TypeElement contributionElement = entry.getKey(); String contributionName = entry.getValue(); FieldWriter builderField = builderWriter.addField(contributionElement, contributionName); builderField.addModifiers(PRIVATE); componentContributionFields.put(contributionElement, MemberSelect.instanceSelect(componentImplName, Snippet.format("builder.%s", builderField.name()))); if (componentCanMakeNewInstances(contributionElement)) { buildMethod.body().addSnippet("if (%s == null) {", builderField.name()) .addSnippet(" this.%s = new %s();", builderField.name(), ClassName.fromTypeElement(contributionElement)) .addSnippet("}"); } else { buildMethod.body().addSnippet("if (%s == null) {", builderField.name()) .addSnippet(" throw new IllegalStateException(\"%s must be set\");", builderField.name()) .addSnippet("}"); } MethodWriter builderMethod; boolean returnsVoid = false; if (builderSpec.isPresent()) { ExecutableElement method = builderSpec.get().methodMap().get(contributionElement); if (method == null) { // no method in the API, nothing to write out. continue; } // If the return type is void, we add a method with the void return type. // Otherwise we use the builderWriter and take advantage of covariant returns // (so that we don't have to worry about setter methods that return type variables). if (method.getReturnType().getKind().equals(TypeKind.VOID)) { returnsVoid = true; builderMethod = builderWriter.addMethod(method.getReturnType(), method.getSimpleName().toString()); } else { builderMethod = builderWriter.addMethod(builderWriter, method.getSimpleName().toString()); } builderMethod.annotate(Override.class); } else { builderMethod = builderWriter.addMethod(builderWriter, contributionName); } // TODO(gak): Mirror the API's visibility. // (Makes no difference to the user since this class is private, // but makes generated code prettier.) builderMethod.addModifiers(PUBLIC); builderMethod.addParameter(contributionElement, contributionName); builderMethod.body().addSnippet("if (%s == null) {", contributionName) .addSnippet(" throw new NullPointerException(%s);", StringLiteral.forValue(contributionName)) .addSnippet("}").addSnippet("this.%s = %s;", builderField.name(), contributionName); if (!returnsVoid) { builderMethod.body().addSnippet("return this;"); } } buildMethod.body().addSnippet("return new %s(this);", componentImplName); return builderWriter; }
From source file:org.pentaho.di.trans.dataservice.serialization.DataServiceMetaStoreUtil.java
static Map<Integer, String> createCacheEntries(DataServiceMeta dataService) { Set<Integer> keys = createCacheKeys(dataService.getServiceTrans(), dataService.getStepname()); return Maps.asMap(keys, Functions.constant(dataService.getName())); }
From source file:org.apache.aurora.scheduler.thrift.ReadOnlySchedulerImpl.java
@Override public Response getJobUpdateDiff(JobUpdateRequest mutableRequest) { IJobUpdateRequest request;/*from w ww . j a va 2s .c o m*/ try { request = IJobUpdateRequest .build(new JobUpdateRequest(mutableRequest).setTaskConfig(configurationManager .validateAndPopulate(ITaskConfig.build(mutableRequest.getTaskConfig())).newBuilder())); } catch (TaskDescriptionException e) { return error(INVALID_REQUEST, e); } IJobKey job = request.getTaskConfig().getJob(); return storage.read(storeProvider -> { if (storeProvider.getCronJobStore().fetchJob(job).isPresent()) { return invalidRequest(NO_CRON); } JobDiff diff = JobDiff.compute(storeProvider.getTaskStore(), job, JobDiff.asMap(request.getTaskConfig(), request.getInstanceCount()), request.getSettings().getUpdateOnlyTheseInstances()); Map<Integer, ITaskConfig> replaced = diff.getReplacedInstances(); Map<Integer, ITaskConfig> replacements = Maps.asMap(diff.getReplacementInstances(), Functions.constant(request.getTaskConfig())); Map<Integer, ITaskConfig> add = Maps.filterKeys(replacements, Predicates.in(Sets.difference(replacements.keySet(), replaced.keySet()))); Map<Integer, ITaskConfig> remove = Maps.filterKeys(replaced, Predicates.in(Sets.difference(replaced.keySet(), replacements.keySet()))); Map<Integer, ITaskConfig> update = Maps.filterKeys(replaced, Predicates.in(Sets.intersection(replaced.keySet(), replacements.keySet()))); return ok( Result.getJobUpdateDiffResult(new GetJobUpdateDiffResult().setAdd(instancesToConfigGroups(add)) .setRemove(instancesToConfigGroups(remove)).setUpdate(instancesToConfigGroups(update)) .setUnchanged(instancesToConfigGroups(diff.getUnchangedInstances())))); }); }
From source file:de.bund.bfr.knime.nls.chart.ChartConfigPanel.java
public void init(String varY, List<String> variablesX, List<String> parameters) { String currentVarX = getVarX(); yBox.removeAllItems();//from w w w. j av a 2 s . co m yBox.addItem(varY); yBox.setSelectedIndex(0); xBox.removeAllItems(); if (variablesX != null && !variablesX.isEmpty()) { variablesX.forEach(x -> xBox.addItem(x)); if (variablesX.contains(currentVarX)) { xBox.setSelectedItem(currentVarX); } else { xBox.setSelectedIndex(0); } } if (outerParameterPanel != null) { outerParameterPanel.removeAll(); parameterPanel = new VariablePanel( Maps.asMap(new LinkedHashSet<>(parameters != null ? parameters : Collections.emptySet()), Functions.constant(new ArrayList<>())), null, null, false, true, true); parameterPanel.addValueListener(e -> fireConfigChanged()); outerParameterPanel.add(parameterPanel, BorderLayout.WEST); Container container = getParent(); while (container != null) { if (container instanceof JPanel) { ((JPanel) container).revalidate(); break; } container = container.getParent(); } } if (outerVariablePanel != null) { outerVariablePanel.removeAll(); variablePanel = new VariablePanel( Maps.asMap(new LinkedHashSet<>(variablesX != null ? variablesX : Collections.emptySet()), Functions.constant(new ArrayList<>())), null, null, false, true, true); variablePanel.setEnabled(getVarX(), false); variablePanel.addValueListener(e -> fireConfigChanged()); outerVariablePanel.add(variablePanel, BorderLayout.WEST); Container container = getParent(); while (container != null) { if (container instanceof JPanel) { ((JPanel) container).revalidate(); break; } container = container.getParent(); } } }
From source file:com.stackframe.sarariman.StackFrameEmployee.java
@Override public Map<Week, Timesheet> getTimesheets() { ContiguousSet<Week> allWeeks = ContiguousSet.create(Range.<Week>all(), Week.discreteDomain); return Maps.asMap(allWeeks, (Week w) -> { return sarariman.getTimesheets().get(StackFrameEmployee.this, w); });// w ww . j a va 2 s . c o m }
From source file:com.stackframe.sarariman.StackFrameEmployee.java
@Override public Map<Task, TaskAssignment> getTaskAssignments() { return Maps.asMap(sarariman.getTasks().getAll(), (Task t) -> { return sarariman.getTaskAssignments().get(StackFrameEmployee.this, t); });//from w w w . j a va 2s. c o m }