List of usage examples for com.google.common.collect ImmutableMap.Builder put
public final V put(K k, V v)
From source file:pl.porannajava.javnysejm.support.ReflectionUtils.java
public static Map<String, String> getObjectStringValues(Object object, boolean withId) { ImmutableMap.Builder<String, String> mapBuilder = new ImmutableMap.Builder<>(); if (withId) { // add id field mapBuilder.put("id", getIdFieldStringValue(object)); }//from w ww . jav a2 s. c o m for (Field field : object.getClass().getDeclaredFields()) { field.setAccessible(true); try { Object objectValue = field.get(object); String stringValue = "null"; if (objectValue != null) { if (objectValue.getClass().equals(int[].class)) { stringValue = getIntsArrayStringValue(objectValue); } else if (objectValue.getClass().isArray()) { stringValue = getArrayStringValue(objectValue); } else { stringValue = objectValue.toString(); } } mapBuilder.put(field.getName(), stringValue); } catch (IllegalArgumentException e) { logger.error("field access error", e); } catch (IllegalAccessException e) { logger.error("field access error", e); } } return mapBuilder.build(); }
From source file:io.prestosql.tests.statistics.MetricComparator.java
private static StatsContext buildStatsContext(Plan queryPlan, OutputNode outputNode) { ImmutableMap.Builder<String, Symbol> columnSymbols = ImmutableMap.builder(); for (int columnId = 0; columnId < outputNode.getColumnNames().size(); ++columnId) { columnSymbols.put(outputNode.getColumnNames().get(columnId), outputNode.getOutputSymbols().get(columnId)); }/* w ww . ja va2s . co m*/ return new StatsContext(columnSymbols.build(), queryPlan.getTypes()); }
From source file:org.sonar.plugins.roslynsdk.RoslynSdkConfiguration.java
private static Map<String, String> readPluginProperties(SMInputCursor pluginPropertiesChildren) throws XMLStreamException { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); while (pluginPropertiesChildren.getNext() != null) { builder.put(pluginPropertiesChildren.getLocalName(), pluginPropertiesChildren.getElemStringValue()); }/*from www. j a va 2s. c o m*/ return builder.build(); }
From source file:net.minecrell.quartz.launch.mappings.MappingsParser.java
private static Map<String, ParsedAnnotation> parseAnnotations(List<AnnotationNode> annotationNodes) { if (annotationNodes == null || annotationNodes.isEmpty()) { return Collections.emptyMap(); }/*from w ww. jav a2s . c om*/ ImmutableMap.Builder<String, ParsedAnnotation> builder = ImmutableMap.builder(); for (AnnotationNode annotationNode : annotationNodes) { builder.put(annotationNode.desc, ParsedAnnotation.parse(annotationNode)); } return builder.build(); }
From source file:com.google.auto.factory.processor.Mirrors.java
/** * Returns an annotation value map with {@link String} keys instead of {@link ExecutableElement} * instances.// ww w. j a va 2s . c o m */ static ImmutableMap<String, AnnotationValue> simplifyAnnotationValueMap( Map<? extends ExecutableElement, ? extends AnnotationValue> annotationValueMap) { ImmutableMap.Builder<String, AnnotationValue> builder = ImmutableMap.builder(); for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationValueMap.entrySet()) { builder.put(entry.getKey().getSimpleName().toString(), entry.getValue()); } return builder.build(); }
From source file:org.dishevelled.bio.assembly.gfa2.Header.java
/** * Parse a header GFA 2.0 record from the specified value. * * @param value value, must not be null// w ww .ja va 2 s . c om * @return a header GFA 2.0 record parsed from the specified value */ public static Header valueOf(final String value) { checkNotNull(value); checkArgument(value.startsWith("H"), "header value must start with H"); List<String> tokens = Splitter.on("\t").splitToList(value); ImmutableMap.Builder<String, Tag> tags = ImmutableMap.builder(); for (int i = 1; i < tokens.size(); i++) { Tag tag = Tag.valueOf(tokens.get(i)); tags.put(tag.getName(), tag); } return new Header(tags.build()); }
From source file:com.facebook.buck.core.cell.impl.DefaultCellPathResolver.java
/** * Helper function to precompute the {@link CellName} to Path mapping * * @return Map of cell name to path.// w ww.ja v a 2 s.com */ private static ImmutableMap<CellName, Path> bootstrapPathMapping(Path root, ImmutableMap<String, Path> cellPaths) { ImmutableMap.Builder<CellName, Path> builder = ImmutableMap.builder(); // Add the implicit empty root cell builder.put(CellName.ROOT_CELL_NAME, root); HashSet<Path> seenPaths = new HashSet<>(); ImmutableSortedSet<String> sortedCellNames = ImmutableSortedSet.<String>naturalOrder() .addAll(cellPaths.keySet()).build(); for (String cellName : sortedCellNames) { Path cellRoot = Objects.requireNonNull(cellPaths.get(cellName), "cellName is derived from the map, get() should always return a value."); try { cellRoot = cellRoot.toRealPath().normalize(); } catch (IOException e) { LOG.warn("cellroot [" + cellRoot + "] does not exist in filesystem"); } if (seenPaths.contains(cellRoot)) { continue; } builder.put(CellName.of(cellName), cellRoot); seenPaths.add(cellRoot); } return builder.build(); }
From source file:org.apache.aurora.scheduler.configuration.executor.ExecutorModule.java
private static ExecutorSettings makeExecutorSettings() { try {/*from w w w . ja va 2 s . co m*/ ImmutableMap.Builder<String, ExecutorConfig> configsBuilder = ImmutableMap.builder(); configsBuilder.put(apiConstants.AURORA_EXECUTOR_NAME, makeThermosExecutorConfig()); if (CUSTOM_EXECUTOR_CONFIG.hasAppliedValue()) { configsBuilder.putAll(ExecutorSettingsLoader.read( Files.newBufferedReader(CUSTOM_EXECUTOR_CONFIG.get().toPath(), StandardCharsets.UTF_8))); } return new ExecutorSettings(configsBuilder.build(), POPULATE_DISCOVERY_INFO.get()); } catch (ExecutorSettingsLoader.ExecutorConfigException | IOException e) { throw new IllegalArgumentException("Failed to read executor settings: " + e, e); } }
From source file:com.google.idea.blaze.base.model.primitives.LanguageClass.java
private static ImmutableMap<String, LanguageClass> extensionToClassMap() { ImmutableMap.Builder<String, LanguageClass> result = ImmutableMap.builder(); for (LanguageClass lang : LanguageClass.values()) { for (String ext : lang.recognizedFilenameExtensions) { result.put(ext, lang); }//from w ww.j a v a 2 s . com } return result.build(); }
From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3ElementDiffSimplePrinter.java
/** * Converts an {@link ImmutableList} of {@link Ds3Annotation} into an {@link ImmutableMap} of * annotation names and {@link Ds3Annotation} *///from w w w .j a va 2s .co m private static ImmutableMap<String, Ds3Annotation> toAnnotationMap( final ImmutableList<Ds3Annotation> annotations) { if (isEmpty(annotations)) { return ImmutableMap.of(); } final ImmutableMap.Builder<String, Ds3Annotation> builder = ImmutableMap.builder(); annotations.forEach(annotation -> builder.put(annotation.getName(), annotation)); return builder.build(); }