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.apple.toolchain.impl.AppleToolchainDiscovery.java
/** * Given a path to an Xcode developer directory, walks through the toolchains and builds a map of * (identifier: path) pairs of the toolchains inside. *///from w w w. j a v a 2 s . c o m public static ImmutableMap<String, AppleToolchain> discoverAppleToolchains(Optional<Path> developerDir, ImmutableList<Path> extraDirs) throws IOException { ImmutableMap.Builder<String, AppleToolchain> toolchainIdentifiersToToolchainsBuilder = ImmutableMap .builder(); HashSet<Path> toolchainPaths = new HashSet<Path>(extraDirs); if (developerDir.isPresent()) { Path toolchainsDir = developerDir.get().resolve("Toolchains"); LOG.debug("Searching for Xcode toolchains under %s", toolchainsDir); toolchainPaths.add(toolchainsDir); } for (Path toolchains : toolchainPaths) { if (!Files.exists(toolchains)) { LOG.debug("Skipping toolchain search path %s that does not exist", toolchains); continue; } LOG.debug("Searching for Xcode toolchains in %s", toolchains); try (DirectoryStream<Path> toolchainStream = Files.newDirectoryStream(toolchains, "*.xctoolchain")) { for (Path toolchainPath : ImmutableSortedSet.copyOf(toolchainStream)) { LOG.debug("Getting identifier for for Xcode toolchain under %s", toolchainPath); addIdentifierForToolchain(toolchainPath, toolchainIdentifiersToToolchainsBuilder); } } } return toolchainIdentifiersToToolchainsBuilder.build(); }
From source file:google.registry.util.XmlToEnumMapper.java
private XmlToEnumMapper(T[] enumValues) { ImmutableMap.Builder<String, T> mapBuilder = new ImmutableMap.Builder<>(); for (T value : enumValues) { try {// ww w .j av a 2s . c o m XmlEnumValue xmlAnnotation = value.getDeclaringClass().getField(value.name()) .getAnnotation(XmlEnumValue.class); checkArgumentNotNull(xmlAnnotation, "Cannot map enum value to xml name: " + value); String xmlName = xmlAnnotation.value(); mapBuilder = mapBuilder.put(xmlName, value); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } } map = mapBuilder.build(); }
From source file:org.ros.internal.message.new_style.ServiceMessageDefinition.java
public Map<String, String> toHeader() { Preconditions.checkNotNull(md5Checksum); return new ImmutableMap.Builder<String, String>().put(ConnectionHeaderFields.TYPE, type) .put(ConnectionHeaderFields.MD5_CHECKSUM, md5Checksum).build(); }
From source file:com.google.devtools.build.xcode.zip.ZipFiles.java
/** * Returns the external file attributes of each entry as a mapping from the entry name to the * 32-bit value. As long as the attributes are generated by a Unix host, this includes the POSIX * file permissions in the upper two bytes. Entries not generated by a Unix host are not included * in the result./*from w w w . jav a 2 s . c o m*/ */ public static Map<String, Integer> unixExternalFileAttributes(Path zipFile) throws IOException { // Field descriptions in comments were taken from this document: // http://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT ImmutableMap.Builder<String, Integer> attributes = new ImmutableMap.Builder<>(); try (SeekableByteChannel input = Files.newByteChannel(zipFile)) { // The data we care about is toward the end of the file, after the compressed data for each // file. We begin by looking for the start of the end of central directory record, which is // marked by the signature 0x06054b50 // // This contains the centralDirectoryStartOffset value, which tells us where to seek to find // the first central directory entry. Each such entry is marked by the signature 0x02014b50 // and appear in sequence, one entry for each file in the .zip. // // The central directory entry contains many values, including the file name, the external // file attributes, and the version made by value. If the version made by indicates a Unix // host (0x03??), we include the external file attributes in the returned map. long offset = input.size() - 4; while (offset >= 0) { input.position(offset); int signature = readBytes(4, input); if (signature == 0x06054b50) { break; } else if (signature == 0x06064b50) { throw new IOException("Zip64 format not supported: " + zipFile); } offset--; } if (offset < 0) { throw new IOException(); } // Read end of central directory structure input.position(input.position() + 2 // number of this disk + 2 // number of the disk with the start of the central directory ); int entryCount = readBytes(2, input); input.position(input.position() + 2 // total number of entries in the central directory ); input.position(input.position() + 4 // size of the central directory ); int centralDirectoryStartOffset = readBytes(4, input); if (0xffffffff == centralDirectoryStartOffset) { throw new IOException("Zip64 format not supported."); } input.position(centralDirectoryStartOffset); int entriesFound = 0; // Read each central directory entry while ((entriesFound < entryCount) && (readBytes(4, input) == 0x02014b50)) { int versionMadeBy = readBytes(2, input); input.position(input.position() + 2 // version needed to extract + 2 // general purpose bit flag + 2 // compression method + 2 // last mod file time + 2 // last mod file date + 4 // crc-32 + 4 // compressed size + 4 // uncompressed size ); int filenameLength = readBytes(2, input); int extraFieldLength = readBytes(2, input); int fileCommentLength = readBytes(2, input); input.position(input.position() + 2 // disk number start + 2 // internal file attributes ); int externalFileAttributes = readBytes(4, input); input.position(input.position() + 4 // relative offset of local header ); ByteBuffer filenameBuffer = ByteBuffer.allocate(filenameLength); if (filenameLength != input.read(filenameBuffer)) { throw new IOException(String.format( "Could not read file name (length %d) in central directory record", filenameLength)); } input.position(input.position() + extraFieldLength + fileCommentLength); entriesFound++; if ((versionMadeBy >> 8) == 3) { // Zip made by a Unix host - the external file attributes are POSIX permissions. String filename = new String(filenameBuffer.array(), StandardCharsets.UTF_8); attributes.put(filename, externalFileAttributes); } } if (entriesFound != entryCount) { System.err.printf( "WARNING: Expected %d entries in central directory record in '%s', but found %d\n", entryCount, zipFile, entriesFound); } } return attributes.build(); }
From source file:io.airlift.event.client.JsonEventSerializer.java
@Inject public JsonEventSerializer(Set<EventTypeMetadata<?>> eventTypes) { checkNotNull(eventTypes, "eventTypes is null"); ImmutableMap.Builder<Class<?>, JsonSerializer<?>> map = ImmutableMap.builder(); for (EventTypeMetadata<?> eventType : eventTypes) { map.put(eventType.getEventClass(), new EventJsonSerializer<>(eventType)); }// w w w. ja v a 2 s . c o m this.serializers = map.build(); }
From source file:io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.java
@Override public Map<String, Object> build() { final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.putAll(super.build()); ofNullable(threshold).map(x -> builder.put("threshold", x)); return builder.build(); }
From source file:com.microsoft.thrifty.schema.Typedef.java
Typedef(TypedefElement element, Map<NamespaceScope, String> namespaces) { super(element.newName(), namespaces); this.element = element; ImmutableMap.Builder<String, String> annotationBuilder = ImmutableMap.builder(); AnnotationElement anno = element.annotations(); if (anno != null) { annotationBuilder.putAll(anno.values()); }//from w w w . j a v a 2 s . c om this.annotations = annotationBuilder.build(); }
From source file:org.jooby.rx.ExecSchedulerHook.java
public ExecSchedulerHook(final Map<String, Executor> executors) { // we don't want eager initialization of Schedulers this.schedulers = Lazy.of(() -> { ImmutableMap.Builder<String, Scheduler> schedulers = ImmutableMap.builder(); executors.forEach((k, e) -> schedulers.put(k, Schedulers.from(e))); return schedulers.build(); });/*from w w w . j av a2s . com*/ }
From source file:org.codice.ddf.catalog.ui.metacard.impl.AbstractSplitter.java
@Override public final Map<String, Object> getProperties() { return new ImmutableMap.Builder<String, Object>().put(Constants.SERVICE_ID, getId()) .put(ServicePropertiesConstants.MIME_TYPE, new ArrayList<>(getMimeTypes())) .putAll(getAdditionalProperties()).build(); }
From source file:edu.cmu.lti.oaqa.baseqa.answer.yesno.scorers.YesNoScorer.java
static ImmutableMap<String, Double> aggregateFeatures(Collection<? extends Number> values, String keyword) { ImmutableMap.Builder<String, Double> features = ImmutableMap.builder(); features.put(keyword + "-sum", values.stream().mapToDouble(Number::doubleValue).sum()); features.put(keyword + "-avg", values.stream().mapToDouble(Number::doubleValue).average().orElse(0)); features.put(keyword + "-max", values.stream().mapToDouble(Number::doubleValue).max().orElse(0)); features.put(keyword + "-min", values.stream().mapToDouble(Number::doubleValue).min().orElse(0)); return features.build(); }