List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.terasology.web.servlet.AboutServlet.java
@GET @Path("home") @Produces(MediaType.TEXT_HTML)//from w w w .j av a2s. c o m public Viewable about() { logger.info("Requested about as HTML"); ImmutableMap<Object, Object> dataModel = ImmutableMap.builder().put("version", VersionInfo.getVersion()) .build(); return new Viewable("/about.ftl", dataModel); }
From source file:org.apache.druid.server.http.ServersResource.java
private static Map<String, Object> makeFullServer(DruidServer input) { return new ImmutableMap.Builder<String, Object>().put("host", input.getHost()) .put("maxSize", input.getMaxSize()).put("type", input.getType().toString()) .put("tier", input.getTier()).put("priority", input.getPriority()) .put("segments", input.getSegments()).put("currSize", input.getCurrSize()).build(); }
From source file:com.facebook.buck.event.listener.BuildThreadStateRenderer.java
private static ImmutableMap<Long, ThreadRenderingInformation> getThreadInformationMap(long currentTimeMs, Map<Long, Optional<? extends LeafEvent>> runningStepsByThread, AccumulatedTimeTracker accumulatedTimeTracker) { ImmutableMap.Builder<Long, ThreadRenderingInformation> threadInformationMapBuilder = ImmutableMap.builder(); Map<Long, Optional<? extends BuildRuleEvent>> buildEventsByThread = accumulatedTimeTracker .getBuildEventsByThread();//w w w. j a va 2 s . c o m ImmutableList<Long> threadIds = ImmutableList.copyOf(buildEventsByThread.keySet()); for (long threadId : threadIds) { Optional<? extends BuildRuleEvent> buildRuleEvent = buildEventsByThread.get(threadId); if (buildRuleEvent == null) { continue; } Optional<BuildTarget> buildTarget = Optional.empty(); if (buildRuleEvent.isPresent()) { buildTarget = Optional.of(buildRuleEvent.get().getBuildRule().getBuildTarget()); } AtomicLong accumulatedTime = null; if (buildTarget.isPresent()) { accumulatedTime = accumulatedTimeTracker.getTime(buildTarget.get()); } long elapsedTimeMs = 0; if (buildRuleEvent.isPresent() && accumulatedTime != null) { elapsedTimeMs = currentTimeMs - buildRuleEvent.get().getTimestamp() + accumulatedTime.get(); } else { buildRuleEvent = Optional.empty(); buildTarget = Optional.empty(); } Optional<? extends LeafEvent> runningStep = runningStepsByThread.get(threadId); if (runningStep == null) { runningStep = Optional.empty(); } threadInformationMapBuilder.put(threadId, new ThreadRenderingInformation(buildTarget, buildRuleEvent, Optional.empty(), Optional.empty(), runningStep, elapsedTimeMs)); } return threadInformationMapBuilder.build(); }
From source file:com.spotify.heroic.metric.bigtable.api.Table.java
public static Table fromPb(com.google.bigtable.admin.v2.Table table) { final Matcher m = TABLE_NAME_PATTERN.matcher(table.getName()); if (!m.matches()) { throw new IllegalArgumentException("Illegal table URI: " + table.getName()); }/*from w w w. ja va2 s .co m*/ final String cluster = m.group(1); final String tableId = m.group(2); final ImmutableMap.Builder<String, ColumnFamily> columnFamilies = ImmutableMap.builder(); for (final Entry<String, com.google.bigtable.admin.v2.ColumnFamily> e : table.getColumnFamilies() .entrySet()) { final ColumnFamily columnFamily = new ColumnFamily(cluster, tableId, e.getKey()); columnFamilies.put(columnFamily.getName(), columnFamily); } return new Table(cluster, tableId, columnFamilies.build()); }
From source file:com.google.javascript.jscomp.GwtProperties.java
/** * Constructs a new {@link GwtProperties} from the given source string. * * @param source To load from.// w w w . j a v a 2s .c om * @return The {@link GwtProperties} object from the source. */ public static GwtProperties load(String source) { String[] lines = source.split("\r?\n"); ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (int i = 0; i < lines.length; ++i) { String line = lines[i]; if (line.isEmpty() || line.startsWith("#") || line.startsWith("!")) { continue; // skip if empty or starts with # or ! } Matcher m = PROP_DEF.matcher(line); if (!m.find()) { continue; } String key = m.group(1); String data = ""; line = line.substring(m.group(0).length()); // remove matched part for (;;) { Matcher lineMatch = PROP_LINE.matcher(line); if (!lineMatch.matches()) { // Should never happen, since PROP_LINE contains .* and no hard requirements. throw new RuntimeException("Properties parser failed on line: " + line); } data += lineMatch.group(1); // add content found // If the line ends with "/", then consume another line if possible. boolean isLastLine = lineMatch.group(2).isEmpty(); if (isLastLine || i + 1 == lines.length) { break; } line = lines[++i]; } builder.put(key, data); } return new GwtProperties(builder.build()); }
From source file:brooklyn.rest.transform.EntityTransformer.java
public static EntitySummary entitySummary(Entity entity) { String applicationUri = "/v1/applications/" + entity.getApplicationId(); String entityUri = applicationUri + "/entities/" + entity.getId(); ImmutableMap.Builder<String, URI> lb = ImmutableMap.<String, URI>builder().put("self", URI.create(entityUri)); if (entity.getParent() != null) lb.put("parent", URI.create(applicationUri + "/entities/" + entity.getParent().getId())); String type = entity.getEntityType().getName(); lb.put("application", URI.create(applicationUri)).put("children", URI.create(entityUri + "/children")) .put("config", URI.create(entityUri + "/config")).put("sensors", URI.create(entityUri + "/sensors")) .put("effectors", URI.create(entityUri + "/effectors")) .put("policies", URI.create(entityUri + "/policies")) .put("activities", URI.create(entityUri + "/activities")) .put("locations", URI.create(entityUri + "/locations")).put("tags", URI.create(entityUri + "/tags")) .put("expunge", URI.create(entityUri + "/expunge")).put("rename", URI.create(entityUri + "/name")) .put("spec", URI.create(entityUri + "/spec")); if (entity.getCatalogItemId() != null) { lb.put("catalog", URI.create( "/v1/catalog/entities/" + WebResourceUtils.getPathFromVersionedId(entity.getCatalogItemId()))); }/*from w ww . j ava2 s . c o m*/ if (entity.getIconUrl() != null) lb.put("iconUrl", URI.create(entityUri + "/icon")); return new EntitySummary(entity.getId(), entity.getDisplayName(), type, entity.getCatalogItemId(), lb.build()); }
From source file:com.ninja_squad.core.jdbc.EnhancedPreparedStatementInvocationHandler.java
private static Map<Method, Invoker> buildInvokers() { try {//from w w w .j a v a2 s . c om ImmutableMap.Builder<Method, Invoker> builder = ImmutableMap.builder(); builder.put( EnhancedPreparedStatement.class.getDeclaredMethod("setNullableInt", int.class, Integer.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setNullableInt(delegate, (Integer) args[0], (Integer) args[1]); } }); builder.put(EnhancedPreparedStatement.class.getDeclaredMethod("setNullableLong", int.class, Long.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setNullableLong(delegate, (Integer) args[0], (Long) args[1]); } }); builder.put(EnhancedPreparedStatement.class.getDeclaredMethod("setNullableBoolean", int.class, Boolean.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setNullableBoolean(delegate, (Integer) args[0], (Boolean) args[1]); } }); builder.put( EnhancedPreparedStatement.class.getDeclaredMethod("setNullableDouble", int.class, Double.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setNullableDouble(delegate, (Integer) args[0], (Double) args[1]); } }); builder.put( EnhancedPreparedStatement.class.getDeclaredMethod("setNullableFloat", int.class, Float.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setNullableFloat(delegate, (Integer) args[0], (Float) args[1]); } }); builder.put(EnhancedPreparedStatement.class.getDeclaredMethod("setNullableByte", int.class, Byte.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setNullableByte(delegate, (Integer) args[0], (Byte) args[1]); } }); builder.put( EnhancedPreparedStatement.class.getDeclaredMethod("setNullableShort", int.class, Short.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setNullableShort(delegate, (Integer) args[0], (Short) args[1]); } }); builder.put(EnhancedPreparedStatement.class.getDeclaredMethod("setEnumAsName", int.class, Enum.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setEnumAsName(delegate, (Integer) args[0], (Enum<?>) args[1]); } }); builder.put( EnhancedPreparedStatement.class.getDeclaredMethod("setEnumAsOrdinal", int.class, Enum.class), new Invoker() { @Override public void invoke(PreparedStatement delegate, Object[] args) throws SQLException { PreparedStatements.setEnumAsOrdinal(delegate, (Integer) args[0], (Enum<?>) args[1]); } }); return builder.build(); } catch (NoSuchMethodException e) { throw new ShouldNeverHappenException(e); } }
From source file:org.janusgraph.diskstorage.es.compat.ES1Compat.java
@Override public ImmutableMap.Builder prepareScript(String script) { return ImmutableMap.builder().put(ES_SCRIPT_KEY, ImmutableMap.of(ES_SCRIPT_KEY, script, ES_LANG_KEY, scriptLang())); }
From source file:org.glowroot.agent.plugin.servlet.DetailCapture.java
static ImmutableMap<String, Object> captureRequestParameters( Map</*@Nullable*/ String, /*@Nullable*/ String /*@Nullable*/[]> requestParameters) { ImmutableList<Pattern> capturePatterns = ServletPluginProperties.captureRequestParameters(); ImmutableList<Pattern> maskPatterns = ServletPluginProperties.maskRequestParameters(); ImmutableMap.Builder<String, Object> map = ImmutableMap.builder(); for (Entry</*@Nullable*/ String, /*@Nullable*/ String /*@Nullable*/[]> entry : requestParameters .entrySet()) {//from w w w . j av a 2s.c o m String name = entry.getKey(); if (name == null) { continue; } // converted to lower case for case-insensitive matching (patterns are lower case) String keyLowerCase = name.toLowerCase(Locale.ENGLISH); if (!matchesOneOf(keyLowerCase, capturePatterns)) { continue; } if (matchesOneOf(keyLowerCase, maskPatterns)) { map.put(name, "****"); continue; } @Nullable String[] values = entry.getValue(); if (values != null) { set(map, name, values); } } return map.build(); }
From source file:com.netflix.spinnaker.orca.batch.ChunkContextAdapter.java
ChunkContextAdapter(ChunkContext chunkContext) { Map<String, Object> entries = new HashMap<>(); entries.putAll(chunkContext.getStepContext().getJobParameters()); entries.putAll(chunkContext.getStepContext().getJobExecutionContext()); entries.putAll(chunkContext.getStepContext().getStepExecutionContext()); inputs = new ImmutableMap.Builder<String, Object>().putAll(entries).build(); }