List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:com.facebook.buck.core.rules.knowntypes.KnownBuildRuleTypesTestUtil.java
protected static ImmutableMap<ProcessExecutorParams, FakeProcess> getPythonProcessMap(List<String> paths) { Set<String> uniquePaths = new HashSet<>(paths); ImmutableMap.Builder<ProcessExecutorParams, FakeProcess> processMap = ImmutableMap.builder(); for (Map.Entry<String, String> python : PYTHONS.entrySet()) { for (String path : uniquePaths) { for (String extension : new String[] { "", ".exe", ".EXE" }) { processMap.put(// w ww . j a v a 2 s . c om ProcessExecutorParams.builder() .setCommand(ImmutableList .of(path + File.separator + python.getKey() + extension, "-")) .build(), new FakeProcess(0, "CPython " + python.getValue(), "")); } } } return processMap.build(); }
From source file:org.ulyssis.ipp.snapshot.TeamStates.java
public TeamStates setStateForTeam(int teamNb, TeamState state) { ImmutableMap.Builder<Integer, TeamState> builder = ImmutableMap.builder(); teamNbToState.forEach((myTeamNb, myState) -> { if (teamNb != myTeamNb) { builder.put(myTeamNb, myState); }//from w ww . j ava 2 s.c o m }); builder.put(teamNb, state); return new TeamStates(builder.build()); }
From source file:org.apache.aurora.scheduler.http.Cron.java
/** * Dumps the state of the cron manager.// w w w. j a va 2 s . c om * * @return An HTTP response containing the cron manager's state. */ @GET @Produces(MediaType.APPLICATION_JSON) public Response dumpContents() { ImmutableMap.Builder<String, String> scheduled = ImmutableMap.builder(); for (Map.Entry<IJobKey, CrontabEntry> entry : cronManager.getScheduledJobs().entrySet()) { scheduled.put(JobKeys.canonicalString(entry.getKey()), entry.getValue().toString()); } return Response.ok(ImmutableMap.of("scheduled", scheduled.build())).build(); }
From source file:org.jooby.internal.RouteChain.java
public RouteChain(final RequestImpl req, final ResponseImpl rsp, final List<Route> routes) { this.routes = routes; this.rreq = req; this.rrsp = rsp; // eager decision if we need to wrap a route to get all the attrs within the change. ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); routes.forEach(r -> builder.putAll(r.attributes())); this.hasAttrs = builder.build().size() > 0; }
From source file:org.opendaylight.infrautils.caches.CacheFunction.java
/** * Implementations may wish to override this implementation * if they can provide bulk implementations which avoid 1-by-1 * locking overhead which single get() may incur, which is what * the default implementation does.//from w w w .j ava 2 s .c o m * * @param keys list of keys of cache entries * @return Map of cache keys and values (neither ever null, but may be an Optional) */ default ImmutableMap<K, V> get(Iterable<? extends K> keys) { Builder<K, V> mapBuilder = ImmutableMap.builder(); for (K key : keys) { mapBuilder.put(key, get(key)); } return mapBuilder.build(); }
From source file:com.google.devtools.build.lib.remote.FakeImmutableCacheByteStreamImpl.java
public FakeImmutableCacheByteStreamImpl(Map<Digest, String> contents) { ImmutableMap.Builder<ReadRequest, ReadResponse> b = ImmutableMap.builder(); for (Map.Entry<Digest, String> e : contents.entrySet()) { b.put(ReadRequest.newBuilder()//from w ww . j a v a 2 s .co m .setResourceName("blobs/" + e.getKey().getHash() + "/" + e.getKey().getSizeBytes()).build(), ReadResponse.newBuilder().setData(ByteString.copyFromUtf8(e.getValue())).build()); } cannedReplies = b.build(); numErrors = new HashMap<>(); }
From source file:org.mule.service.soap.interceptor.OutputSoapHeadersInterceptor.java
/** * {@inheritDoc}/* w w w . j a v a 2s. co m*/ */ @Override public void handleMessage(SoapMessage message) throws Fault { ImmutableMap.Builder<String, String> headers = ImmutableMap.builder(); message.getHeaders().stream().filter(header -> header instanceof SoapHeader).map(h -> (SoapHeader) h) .forEach(header -> headers.put(header.getName().getLocalPart(), getHeaderInputStream(header))); message.getExchange().put(MULE_HEADERS_KEY, headers.build()); }
From source file:org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovProcess.java
public MarkovProcess(MarkovModel<T> model, SeedFactory factory) { Map<T, Map<T, Double>> transitionTable = model.getTransitionWeights(); startStateSampler = RouletteWheelSampler.create(model.getStartWeights(), factory); ImmutableMap.Builder<T, Sampler<T>> builder = ImmutableMap.builder(); for (Map.Entry<T, Map<T, Double>> entry : transitionTable.entrySet()) { builder.put(entry.getKey(), RouletteWheelSampler.create(entry.getValue(), factory)); }/*w w w . j a va 2 s . c o m*/ this.transitionSamplers = builder.build(); currentState = null; }
From source file:com.jgaap.backend.DistanceFunctions.java
private static ImmutableMap<String, DistanceFunction> loadDistanceFunctionsMap() { // Load the distance functions dynamically ImmutableMap.Builder<String, DistanceFunction> builder = ImmutableMap.builder(); for (DistanceFunction distanceFunction : DISTANCE_FUNCTIONS) { builder.put(distanceFunction.displayName().toLowerCase().trim(), distanceFunction); }/*from w ww .j a v a2s.com*/ return builder.build(); }
From source file:com.google.googlejavaformat.java.EclipseJavadocFormatter.java
private static String formatJavadocInternal(String input, int indent, JavaFormatterOptions options) { ImmutableMap.Builder<String, String> optionBuilder = ImmutableMap.<String, String>builder(); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, "true"); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(options.indentationMultiplier())); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(options.maxLineLength() - indent)); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(options.maxLineLength())); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_PARAMETER_DESCRIPTION, DefaultCodeFormatterConstants.FALSE); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_NEW_LINE_FOR_PARAMETER, JavaCore.DO_NOT_INSERT);//from w ww . j a v a2 s . c o m optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_LINES_IN_COMMENTS, DefaultCodeFormatterConstants.TRUE); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.TRUE); // Disable indenting root tags for now since it indents more than 4 spaces optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_ROOT_TAGS, DefaultCodeFormatterConstants.FALSE); optionBuilder.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE, DefaultCodeFormatterConstants.FALSE); optionBuilder.put(JavaCore.COMPILER_COMPLIANCE, "1.8"); optionBuilder.put(JavaCore.COMPILER_SOURCE, "1.8"); optionBuilder.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.8"); DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter( new DefaultCodeFormatterOptions(optionBuilder.build())); TextEdit edit = codeFormatter.format(CodeFormatter.K_JAVA_DOC, input, /*offset*/ 0, input.length(), // eclipse doesn't indent comments reliably, so always request no indent and fix it // up later in JavaCommentsHelper /*indent*/ 0, /*lineSeparator*/ null); if (edit == null) { throw new RuntimeException("error formatting javadoc"); } Document document = new Document(input); try { edit.apply(document); } catch (BadLocationException e) { throw new RuntimeException("error formatting javadoc", e); } return document.get(); }