Example usage for com.google.common.collect ImmutableMap.Builder put

List of usage examples for com.google.common.collect ImmutableMap.Builder put

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap.Builder put.

Prototype

public final V put(K k, V v) 

Source Link

Usage

From source file:com.google.devtools.build.lib.skyframe.serialization.ObjectCodecs.java

private static Map<ByteString, ObjectCodec<?>> makeByteStringMappedCodecs(
        Map<String, ObjectCodec<?>> stringMappedCodecs) {
    ImmutableMap.Builder<ByteString, ObjectCodec<?>> result = ImmutableMap.builder();
    for (Entry<String, ObjectCodec<?>> entry : stringMappedCodecs.entrySet()) {
        result.put(ByteString.copyFromUtf8(entry.getKey()), entry.getValue());
    }// w  w  w .  jav  a2  s.c o m
    return result.build();
}

From source file:io.prestosql.plugin.hive.authentication.KerberosAuthentication.java

private static Configuration createConfiguration(String principal, String keytabLocation) {
    ImmutableMap.Builder<String, String> optionsBuilder = ImmutableMap.<String, String>builder()
            .put("useKeyTab", "true").put("storeKey", "true").put("doNotPrompt", "true")
            .put("isInitiator", "true").put("principal", principal).put("keyTab", keytabLocation);

    if (log.isDebugEnabled()) {
        optionsBuilder.put("debug", "true");
    }//from w w w  .  j a v  a2s .c om

    Map<String, String> options = optionsBuilder.build();

    return new Configuration() {
        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            return new AppConfigurationEntry[] { new AppConfigurationEntry(KERBEROS_LOGIN_MODULE,
                    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options) };
        }
    };
}

From source file:org.dishevelled.bio.assembly.gfa2.Edge.java

/**
 * Parse an edge GFA 2.0 record from the specified value.
 *
 * @param value value, must not be null/*from  www . jav  a  2  s.  c o  m*/
 * @return an edge GFA 2.0 record parsed from the specified value
 */
public static Edge valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("E"), "value must start with E");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 9) {
        throw new IllegalArgumentException("value must have at least nine tokens, was " + tokens.size());
    }
    String id = "*".equals(tokens.get(1)) ? null : tokens.get(1);
    Reference source = Reference.valueOf(tokens.get(2));
    Reference target = Reference.valueOf(tokens.get(3));
    Position sourceStart = Position.valueOf(tokens.get(4));
    Position sourceEnd = Position.valueOf(tokens.get(5));
    Position targetStart = Position.valueOf(tokens.get(6));
    Position targetEnd = Position.valueOf(tokens.get(7));
    Alignment alignment = Alignment.valueOf(tokens.get(8));

    ImmutableMap.Builder<String, Tag> tags = ImmutableMap.builder();
    for (int i = 9; i < tokens.size(); i++) {
        Tag tag = Tag.valueOf(tokens.get(i));
        tags.put(tag.getName(), tag);
    }

    return new Edge(id, source, target, sourceStart, sourceEnd, targetStart, targetEnd, alignment,
            tags.build());
}

From source file:com.github.christofluyten.experiment.MeasureGendreau.java

static ImmutableList<ImmutableMap<Property, String>> read(File file) throws IOException {

    final List<String> lines = Files.readLines(file, Charsets.UTF_8);
    final List<Property> header = Property.valueOf(Arrays.asList(lines.get(0).split(",")));

    final ImmutableList.Builder<ImmutableMap<Property, String>> list = ImmutableList.builder();
    for (int i = 1; i < lines.size(); i++) {
        final ImmutableMap.Builder<Property, String> map = ImmutableMap.builder();
        final String[] values = lines.get(i).split(",");
        for (int j = 0; j < header.size(); j++) {
            final Property key = header.get(j);
            map.put(key, values[j]);
        }/*from   w ww .  j  a  va2  s.c o  m*/
        list.add(map.build());
    }
    return list.build();
}

From source file:org.apache.phoenix.pig.util.TypeUtil.java

/**
 * @return map of Phoenix to Pig data types.
 *//*from   w ww .j  a  va  2  s  .  co  m*/
private static ImmutableMap<PDataType, Byte> init() {
    final ImmutableMap.Builder<PDataType, Byte> builder = new Builder<PDataType, Byte>();
    builder.put(PLong.INSTANCE, DataType.LONG);
    builder.put(PVarbinary.INSTANCE, DataType.BYTEARRAY);
    builder.put(PChar.INSTANCE, DataType.CHARARRAY);
    builder.put(PVarchar.INSTANCE, DataType.CHARARRAY);
    builder.put(PDouble.INSTANCE, DataType.DOUBLE);
    builder.put(PFloat.INSTANCE, DataType.FLOAT);
    builder.put(PInteger.INSTANCE, DataType.INTEGER);
    builder.put(PTinyint.INSTANCE, DataType.INTEGER);
    builder.put(PSmallint.INSTANCE, DataType.INTEGER);
    builder.put(PDecimal.INSTANCE, DataType.BIGDECIMAL);
    builder.put(PTime.INSTANCE, DataType.DATETIME);
    builder.put(PTimestamp.INSTANCE, DataType.DATETIME);
    builder.put(PBoolean.INSTANCE, DataType.BOOLEAN);
    builder.put(PDate.INSTANCE, DataType.DATETIME);
    builder.put(PUnsignedDate.INSTANCE, DataType.DATETIME);
    builder.put(PUnsignedDouble.INSTANCE, DataType.DOUBLE);
    builder.put(PUnsignedFloat.INSTANCE, DataType.FLOAT);
    builder.put(PUnsignedInt.INSTANCE, DataType.INTEGER);
    builder.put(PUnsignedLong.INSTANCE, DataType.LONG);
    builder.put(PUnsignedSmallint.INSTANCE, DataType.INTEGER);
    builder.put(PUnsignedTime.INSTANCE, DataType.DATETIME);
    builder.put(PUnsignedTimestamp.INSTANCE, DataType.DATETIME);
    builder.put(PUnsignedTinyint.INSTANCE, DataType.INTEGER);
    return builder.build();
}

From source file:org.apache.beam.sdk.transforms.windowing.PaneInfo.java

private static void register(ImmutableMap.Builder<Byte, PaneInfo> builder, PaneInfo info) {
    builder.put(info.encodedByte, info);
}

From source file:com.facebook.buck.io.PathListing.java

/**
 * Lists paths in descending modified time order,
 * excluding any paths which bring the number of files over {@code maxNumPaths}
 * or over {@code totalSizeFilter} bytes in size.
 *//* ww w.  j  av  a2  s. c o m*/
public static ImmutableSortedSet<Path> listMatchingPathsWithFilters(Path pathToGlob, String globPattern,
        PathModifiedTimeFetcher pathModifiedTimeFetcher, FilterMode filterMode,
        Optional<Integer> maxPathsFilter, Optional<Long> totalSizeFilter) throws IOException {

    // Fetch the modification time of each path and build a map of
    // (path => modification time) pairs.
    ImmutableMap.Builder<Path, FileTime> pathFileTimesBuilder = ImmutableMap.builder();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathToGlob, globPattern)) {
        for (Path path : stream) {
            try {
                pathFileTimesBuilder.put(path, pathModifiedTimeFetcher.getLastModifiedTime(path));
            } catch (NoSuchFileException e) {
                // Ignore the path.
                continue;
            }
        }
    }
    ImmutableMap<Path, FileTime> pathFileTimes = pathFileTimesBuilder.build();

    ImmutableSortedSet<Path> paths = ImmutableSortedSet.copyOf(Ordering.natural()
            // Order the keys of the map (the paths) by their values (the file modification times).
            .onResultOf(Functions.forMap(pathFileTimes))
            // If two keys of the map have the same value, fall back to key order.
            .compound(Ordering.natural())
            // Use descending order.
            .reverse(), pathFileTimes.keySet());

    paths = applyNumPathsFilter(paths, filterMode, maxPathsFilter);
    paths = applyTotalSizeFilter(paths, filterMode, totalSizeFilter);
    return paths;
}

From source file:com.google.api.server.spi.request.RestServletRequestParamReader.java

private static ImmutableMap<String, Class<?>> getParameterMap(EndpointMethod method)
        throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    ImmutableMap.Builder<String, Class<?>> builder = ImmutableMap.builder();
    List<String> parameterNames = getParameterNames(method);
    for (int i = 0; i < parameterNames.size(); i++) {
        String parameterName = parameterNames.get(i);
        if (parameterName != null) {
            builder.put(parameterName, method.getParameterClasses()[i]);
        }// w w w .j  a  va2s. co  m
    }
    return builder.build();
}

From source file:org.glowroot.agent.plugin.servlet.DetailCapture.java

private static void set(ImmutableMap.Builder<String, Object> map, String name, @Nullable String[] values) {
    if (values == null) {
        return;/*from   ww w  .jav  a 2  s . c  om*/
    }
    if (values.length == 1) {
        String value = values[0];
        if (value != null) {
            map.put(name, value);
        }
    } else {
        List</*@Nullable*/ String> list = new ArrayList</*@Nullable*/ String>(values.length);
        Collections.addAll(list, values);
        map.put(name, list);
    }
}

From source file:com.addthis.cronus.internal.TimePeriod.java

private static ImmutableMap<Pattern, String> buildReplacements(String description) {
    ImmutableMap.Builder<Pattern, String> builder = ImmutableMap.builder();
    switch (description) {
    case "dayOfWeek":
        DayOfWeek[] days = DayOfWeek.values();
        for (int i = 0; i < days.length; i++) {
            String needle = days[i].getDisplayName(TextStyle.SHORT, Locale.ENGLISH);
            builder.put(Pattern.compile(Pattern.quote(needle), Pattern.CASE_INSENSITIVE),
                    Integer.toString(i + 1));
        }//from ww w  .j  a  v  a  2s .  c  o  m
        break;
    case "month":
        Month[] months = Month.values();
        for (int i = 0; i < months.length; i++) {
            String needle = months[i].getDisplayName(TextStyle.SHORT, Locale.ENGLISH);
            builder.put(Pattern.compile(Pattern.quote(needle), Pattern.CASE_INSENSITIVE),
                    Integer.toString(i + 1));
        }
        break;
    }
    return builder.build();
}