List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:org.elasticsearch.action.admin.cluster.snapshots.status.TransportNodesSnapshotsStatus.java
@Override protected NodeSnapshotStatus nodeOperation(NodeRequest request) throws ElasticsearchException { ImmutableMap.Builder<SnapshotId, ImmutableMap<ShardId, SnapshotIndexShardStatus>> snapshotMapBuilder = ImmutableMap .builder();// w w w . ja va 2 s . co m try { String nodeId = clusterService.localNode().id(); for (SnapshotId snapshotId : request.snapshotIds) { ImmutableMap<ShardId, IndexShardSnapshotStatus> shardsStatus = snapshotsService .currentSnapshotShards(snapshotId); if (shardsStatus == null) { continue; } ImmutableMap.Builder<ShardId, SnapshotIndexShardStatus> shardMapBuilder = ImmutableMap.builder(); for (ImmutableMap.Entry<ShardId, IndexShardSnapshotStatus> shardEntry : shardsStatus.entrySet()) { SnapshotIndexShardStatus shardStatus; IndexShardSnapshotStatus.Stage stage = shardEntry.getValue().stage(); if (stage != IndexShardSnapshotStatus.Stage.DONE && stage != IndexShardSnapshotStatus.Stage.FAILURE) { // Store node id for the snapshots that are currently running. shardStatus = new SnapshotIndexShardStatus(shardEntry.getKey(), shardEntry.getValue(), nodeId); } else { shardStatus = new SnapshotIndexShardStatus(shardEntry.getKey(), shardEntry.getValue()); } shardMapBuilder.put(shardEntry.getKey(), shardStatus); } snapshotMapBuilder.put(snapshotId, shardMapBuilder.build()); } return new NodeSnapshotStatus(clusterService.localNode(), snapshotMapBuilder.build()); } catch (Exception e) { throw new ElasticsearchException("failed to load metadata", e); } }
From source file:com.facebook.presto.connector.jmx.JmxDataStreamProvider.java
private RecordSet createRecordSet(Split split, List<ColumnHandle> columns) { checkNotNull(split, "split is null"); checkArgument(split instanceof JmxSplit, "Split must be of type %s, not %s", JmxSplit.class.getName(), split.getClass().getName()); JmxTableHandle tableHandle = ((JmxSplit) split).getTableHandle(); checkNotNull(columns, "columns is null"); checkArgument(!columns.isEmpty(), "must provide at least one column"); ImmutableMap.Builder<String, ColumnType> builder = ImmutableMap.builder(); for (ColumnHandle column : columns) { checkArgument(column instanceof JmxColumnHandle, "column must be of type %s, not %s", JmxColumnHandle.class.getName(), column.getClass().getName()); JmxColumnHandle jmxColumnHandle = (JmxColumnHandle) column; builder.put(jmxColumnHandle.getColumnName(), jmxColumnHandle.getColumnType()); }/*from w ww .j av a 2s .c om*/ ImmutableMap<String, ColumnType> columnTypes = builder.build(); List<List<Object>> rows; try { Map<String, Object> attributes = getAttributes(columnTypes.keySet(), tableHandle); List<Object> row = new ArrayList<>(); // NOTE: data must be produced in the order of the columns parameter. This code relies on the // fact that columnTypes is an ImmutableMap which is an order preserving LinkedHashMap under // the covers. for (Entry<String, ColumnType> entry : columnTypes.entrySet()) { if (entry.getKey().equals("node")) { row.add(nodeId); } else { Object value = attributes.get(entry.getKey()); if (value == null) { row.add(null); } else { switch (entry.getValue()) { case BOOLEAN: if (value instanceof Boolean) { row.add(value); } else { // mbeans can lie about types row.add(null); } break; case LONG: if (value instanceof Number) { row.add(((Number) value).longValue()); } else { // mbeans can lie about types row.add(null); } break; case DOUBLE: if (value instanceof Number) { row.add(((Number) value).doubleValue()); } else { // mbeans can lie about types row.add(null); } break; case STRING: row.add(value.toString()); break; } } } } rows = ImmutableList.of(row); } catch (JMException e) { rows = ImmutableList.of(); } return new InMemoryRecordSet(columnTypes.values(), rows); }
From source file:org.apache.flume.source.MultiportSyslogTCPSource.java
@Override public void configure(Context context) { String portsStr = context.getString(SyslogSourceConfigurationConstants.CONFIG_PORTS); Preconditions.checkNotNull(portsStr, "Must define config " + "parameter for MultiportSyslogTCPSource: ports"); for (String portStr : portsStr.split("\\s+")) { Integer port = Integer.parseInt(portStr); ports.add(port);//from w ww.ja va 2 s .c om } host = context.getString(SyslogSourceConfigurationConstants.CONFIG_HOST); numProcessors = context.getInteger(SyslogSourceConfigurationConstants.CONFIG_NUMPROCESSORS); maxEventSize = context.getInteger(SyslogSourceConfigurationConstants.CONFIG_EVENTSIZE, SyslogUtils.DEFAULT_SIZE); String defaultCharsetStr = context.getString(SyslogSourceConfigurationConstants.CONFIG_CHARSET, SyslogSourceConfigurationConstants.DEFAULT_CHARSET); try { defaultCharset = Charset.forName(defaultCharsetStr); } catch (Exception ex) { throw new IllegalArgumentException( "Unable to parse charset " + "string (" + defaultCharsetStr + ") from port configuration.", ex); } defaultDecoder = new ThreadSafeDecoder(defaultCharset); // clear any previous charset configuration and reconfigure it portCharsets.clear(); { ImmutableMap<String, String> portCharsetCfg = context .getSubProperties(SyslogSourceConfigurationConstants.CONFIG_PORT_CHARSET_PREFIX); for (Map.Entry<String, String> entry : portCharsetCfg.entrySet()) { String portStr = entry.getKey(); String charsetStr = entry.getValue(); Integer port = Integer.parseInt(portStr); Preconditions.checkNotNull(port, "Invalid port number in config"); try { Charset charset = Charset.forName(charsetStr); portCharsets.put(port, new ThreadSafeDecoder(charset)); } catch (Exception ex) { throw new IllegalArgumentException( "Unable to parse charset " + "string (" + charsetStr + ") from port configuration.", ex); } } } batchSize = context.getInteger(SyslogSourceConfigurationConstants.CONFIG_BATCHSIZE, SyslogSourceConfigurationConstants.DEFAULT_BATCHSIZE); portHeader = context.getString(SyslogSourceConfigurationConstants.CONFIG_PORT_HEADER); readBufferSize = context.getInteger(SyslogSourceConfigurationConstants.CONFIG_READBUF_SIZE, SyslogSourceConfigurationConstants.DEFAULT_READBUF_SIZE); if (sourceCounter == null) { sourceCounter = new SourceCounter(getName()); } }
From source file:com.google.devtools.build.lib.skyframe.serialization.ImmutableMapCodec.java
@Override public void serialize(SerializationContext context, ImmutableMap<?, V> map, CodedOutputStream codedOut) throws SerializationException, IOException { codedOut.writeInt32NoTag(map.size()); boolean serializeAsSortedMap = false; if (map instanceof ImmutableSortedMap) { Comparator<?> comparator = ((ImmutableSortedMap<?, ?>) map).comparator(); // In practice the comparator seems to always be Ordering.natural(), but be flexible. serializeAsSortedMap = comparator.equals(Ordering.natural()) || comparator.equals(Comparator.naturalOrder()); }/* ww w .j a va 2 s .c o m*/ codedOut.writeBoolNoTag(serializeAsSortedMap); for (Map.Entry<?, ?> entry : map.entrySet()) { context.serialize(entry.getKey(), codedOut); try { context.serialize(entry.getValue(), codedOut); } catch (SerializationException | IOException e) { throw SerializationException .propagate(String.format("Exception while serializing value of type %s for key '%s'", entry.getValue().getClass().getName(), entry.getKey()), e); } } }
From source file:com.facebook.buck.command.config.AbstractConfigIgnoredByDaemon.java
@Value.Lazy public ImmutableMap<String, ImmutableMap<String, String>> getRawConfigForParser() { ImmutableMap<String, ImmutableSet<String>> ignoredFields = getIgnoreFieldsForDaemonRestart(); ImmutableMap<String, ImmutableMap<String, String>> rawSections = getDelegate().getConfig() .getSectionToEntries();/* www. ja v a2s . c o m*/ // If the raw config doesn't have sections which have ignored fields, then just return it as-is. ImmutableSet<String> sectionsWithIgnoredFields = ignoredFields.keySet(); if (Sets.intersection(rawSections.keySet(), sectionsWithIgnoredFields).isEmpty()) { return rawSections; } // Otherwise, iterate through the config to do finer-grain filtering. ImmutableMap.Builder<String, ImmutableMap<String, String>> filtered = ImmutableMap.builder(); for (Map.Entry<String, ImmutableMap<String, String>> sectionEnt : rawSections.entrySet()) { String sectionName = sectionEnt.getKey(); // If this section doesn't have a corresponding ignored section, then just add it as-is. if (!sectionsWithIgnoredFields.contains(sectionName)) { filtered.put(sectionEnt); continue; } // If none of this section's entries are ignored, then add it as-is. ImmutableMap<String, String> fields = sectionEnt.getValue(); ImmutableSet<String> ignoredFieldNames = ignoredFields.getOrDefault(sectionName, ImmutableSet.of()); if (Sets.intersection(fields.keySet(), ignoredFieldNames).isEmpty()) { filtered.put(sectionEnt); continue; } // Otherwise, filter out the ignored fields. ImmutableMap<String, String> remainingKeys = ImmutableMap .copyOf(Maps.filterKeys(fields, Predicates.not(ignoredFieldNames::contains))); filtered.put(sectionName, remainingKeys); } return MoreMaps.filterValues(filtered.build(), Predicates.not(Map::isEmpty)); }
From source file:eu.eubrazilcc.lvl.storage.dao.LeishmaniaDAO.java
private @Nullable BasicDBObject buildQuery(final @Nullable ImmutableMap<String, String> filter) throws InvalidFilterParseException { BasicDBObject query = null;/*from w w w . j a va 2 s .c o m*/ if (filter != null) { for (final Entry<String, String> entry : filter.entrySet()) { query = parseFilter(entry.getKey(), entry.getValue(), query); } } return query; }
From source file:com.google.auto.value.processor.AutoAnnotationProcessor.java
private ImmutableMap<String, Member> getMembers(Element context, ImmutableMap<String, ExecutableElement> memberMethods, TypeSimplifier typeSimplifier, AnnotationOutput annotationOutput) { ImmutableMap.Builder<String, Member> members = ImmutableMap.builder(); for (Map.Entry<String, ExecutableElement> entry : memberMethods.entrySet()) { ExecutableElement memberMethod = entry.getValue(); String name = memberMethod.getSimpleName().toString(); members.put(name, new Member(processingEnv, context, memberMethod, typeSimplifier, annotationOutput)); }// w w w . j a v a 2 s . co m return members.build(); }
From source file:eu.eubrazilcc.lvl.storage.dao.SandflyDAO.java
private @Nullable BasicDBObject buildQuery(final @Nullable ImmutableMap<String, String> filter) throws InvalidFilterParseException { BasicDBObject query = null;//from w w w . j a v a 2 s . co m if (filter != null) { for (final Entry<String, String> entry : filter.entrySet()) { query = parseFilter(entry.getKey(), entry.getValue(), query); } } // TODO System.err.println("\n\n >> QUERY: " + (query != null ? query.toString() : "NULL") + "\n"); // TODO return query; }
From source file:com.facebook.buck.features.project.intellij.aggregation.AggregationTree.java
private ImmutableMap<Path, AggregationModule> collectModulesToAggregate(IjModuleType rootModuleType, AggregationTreeNode parentNode, ImmutableSet<Path> modulePathsToAggregate) { int aggregationLimit = rootModuleType.getAggregationLimit(projectConfig); ImmutableMap<Path, AggregationModule> modules = modulePathsToAggregate.stream() .collect(ImmutableMap.toImmutableMap(path -> path, path -> parentNode.getChild(path).getModule())); if (aggregationLimit == Integer.MAX_VALUE) { return modules; }/*from ww w.j a va 2 s . c o m*/ ImmutableMap.Builder<Path, AggregationModule> filteredModules = ImmutableMap.builder(); int count = 0; if (parentNode.getModule() != null) { count += parentNode.getModule().getTargets().size(); } for (Map.Entry<Path, AggregationModule> pathWithModule : modules.entrySet()) { int childTargetsSize = pathWithModule.getValue().getTargets().size(); if (count + childTargetsSize > aggregationLimit) { continue; } filteredModules.put(pathWithModule.getKey(), pathWithModule.getValue()); count += childTargetsSize; if (count == aggregationLimit) { break; } } return filteredModules.build(); }
From source file:com.facebook.buck.shell.AbstractGenruleStep.java
@Override public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) { ImmutableMap.Builder<String, String> allEnvironmentVariablesBuilder = ImmutableMap.builder(); addEnvironmentVariables(context, allEnvironmentVariablesBuilder); ImmutableMap<String, String> allEnvironmentVariables = allEnvironmentVariablesBuilder.build(); // Long lists of environment variables can extend the length of the command such that it exceeds // exec()'s ARG_MAX limit. Defend against this by filtering out variables that do not appear in // the command string. String command = getCommandAndExecutionArgs(context).command; ImmutableMap.Builder<String, String> usedEnvironmentVariablesBuilder = ImmutableMap.builder(); for (Map.Entry<String, String> environmentVariable : allEnvironmentVariables.entrySet()) { // We check for the presence of the variable without adornment for $ or %% so it works on both // Windows and non-Windows environments. Eventually, we will require $ in the command string // and modify the command directly rather than using environment variables. String environmentVariableName = environmentVariable.getKey(); if (command.contains(environmentVariableName)) { // I hate this $DEPS variable so much... if ("DEPS".equals(environmentVariableName) && allEnvironmentVariables.containsKey("GEN_DIR")) { usedEnvironmentVariablesBuilder.put("GEN_DIR", allEnvironmentVariables.get("GEN_DIR")); }//from w ww. j av a2s. c o m usedEnvironmentVariablesBuilder.put(environmentVariable); } } return usedEnvironmentVariablesBuilder.build(); }