Example usage for com.google.common.collect ImmutableMap builder

List of usage examples for com.google.common.collect ImmutableMap builder

Introduction

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

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Usage

From source file:com.spectralogic.ds3contractcomparator.print.utils.PrinterUtils.java

/**
 * Converts an {@link ImmutableList} of {@link Ds3Param} into an {@link ImmutableMap} of
 * parameter names and {@link Ds3Param}//w w  w  .ja  va2 s  .  c  o  m
 */
public static ImmutableMap<String, Ds3Param> toParamMap(final ImmutableList<Ds3Param> params) {
    if (isEmpty(params)) {
        return ImmutableMap.of();
    }
    final ImmutableMap.Builder<String, Ds3Param> builder = ImmutableMap.builder();
    params.forEach(param -> builder.put(param.getName(), param));
    return builder.build();
}

From source file:ninja.leaping.permissionsex.backend.file.FileSubjectData.java

static FileSubjectData fromNode(ConfigurationNode node)
        throws ObjectMappingException, PermissionsLoadingException {
    ImmutableMap.Builder<Set<Entry<String, String>>, DataEntry> map = ImmutableMap.builder();
    if (node.hasListChildren()) {
        for (ConfigurationNode child : node.getChildrenList()) {
            if (!child.hasMapChildren()) {
                throw new PermissionsLoadingException(t(
                        "Each context section must be of map type! Check that no duplicate nesting has occurred."));
            }/* w w w. ja va 2 s.c o m*/
            Set<Entry<String, String>> contexts = contextsFrom(child);
            DataEntry value = MAPPER.bindToNew().populate(child);
            map.put(contexts, value);
        }
    }
    return new FileSubjectData(map.build());
}

From source file:edu.uci.ics.jung.algorithms.metrics.Metrics.java

/**
 * Returns a <code>Map</code> of nodes to their clustering coefficients. The clustering
 * coefficient cc(v) of a node v is defined as follows:
 *
 * <ul>/* w ww .j ava  2 s.  co m*/
 *   <li><code>degree(v) == {0,1}</code>: 0
 *   <li><code>degree(v) == n, n &gt;= 2</code>: given S, the set of neighbors of <code>v</code>:
 *       cc(v) = (the sum over all w in S of the number of other elements of w that are neighbors
 *       of w) / ((|S| * (|S| - 1) / 2). Less formally, the fraction of <code>v</code>'s neighbors
 *       that are also neighbors of each other.
 * </ul>
 *
 * <p><b>Note</b>: This algorithm treats its argument as an undirected graph; edge direction is
 * ignored.
 *
 * @param graph the graph whose clustering coefficients are to be calculated
 * @param <N> the node type
 * @param <E> the edge type
 * @return the clustering coefficient for each node
 * @see "The structure and function of complex networks, M.E.J. Newman,
 *     aps.arxiv.org/abs/cond-mat/0303516"
 */
public static <N> ImmutableMap<N, Double> clusteringCoefficients(Graph<N> graph) {
    ImmutableMap.Builder<N, Double> coefficients = ImmutableMap.builder();

    for (N v : graph.nodes()) {
        int n = graph.degree(v);
        if (n < 2) {
            coefficients.put(v, new Double(0));
        } else {
            int edgeCount = 0;
            for (N w : graph.adjacentNodes(v)) {
                if (!w.equals(v)) {
                    for (N x : graph.adjacentNodes(v)) {
                        // TODO: replace with hasEdge() once it's ready
                        if (!w.equals(x) && graph.adjacentNodes(w).contains(x)) {
                            edgeCount++;
                        }
                    }
                }
            }
            double possible_edges = (n * (n - 1)) / 2.0;
            coefficients.put(v, new Double(edgeCount / possible_edges));
        }
    }

    return coefficients.build();
}

From source file:ru.codeinside.gses.activiti.forms.types.VariableTypes.java

public VariableTypes() {
    ImmutableMap.Builder<String, VariableType> builder = ImmutableMap.builder();
    builder.put(GsesTypes.STRING.name, new StringType());
    builder.put(GsesTypes.BOOLEAN.name, new BooleanType());
    builder.put(GsesTypes.LONG.name, new LongType());
    builder.put(GsesTypes.ENUM.name, new EnumType());
    builder.put(GsesTypes.DATE.name, new DateType());
    builder.put(GsesTypes.MASKED.name, new MaskedType());
    builder.put(GsesTypes.DICTIONARY.name, new DictionaryType());
    builder.put(GsesTypes.ATTACHMENT.name, new AttachmentType());
    builder.put(GsesTypes.ENCLOSURE.name, new EnclosureType());
    builder.put(GsesTypes.SMEV_REQUEST_ENCLOSURE.name, new StringType());
    builder.put(GsesTypes.SMEV_RESPONSE_ENCLOSURE.name, new StringType());
    builder.put(GsesTypes.JSON.name, new JsonType());
    builder.put(GsesTypes.MULTILINE.name, new MultilineType());
    types = builder.build();//from w  w w  . j a  v  a  2  s. com
}

From source file:com.b2international.snowowl.snomed.api.rest.SnomedReviewRestRequests.java

public static ValidatableResponse createReview(IBranchPath source, IBranchPath target) {
    Map<?, ?> requestBody = ImmutableMap.builder().put("source", source.getPath())
            .put("target", target.getPath()).build();

    return givenAuthenticatedRequest(SnomedApiTestConstants.SCT_API).contentType(ContentType.JSON)
            .body(requestBody).post("/reviews").then();
}

From source file:se.kth.climate.fast.netcdf.aligner.VariableFit.java

public static VariableFit fromDataDescriptors(ImmutableList<DataDescriptor> dds) {
    DataDescriptor firstDD = dds.get(0); // use first descriptor for records as that one has the largest number of records per variable
    ImmutableMap.Builder<String, Long> rfvb = ImmutableMap.builder();
    for (String varName : firstDD.vars) {
        rfvb.put(varName, firstDD.variableSize(varName));
    }/*  w w  w  .j a va 2s .  c  o m*/
    return new VariableFit(rfvb.build(), dds.size(), dds);
}

From source file:com.facebook.buck.jvm.java.JavaPackageFinderSerializer.java

public static ImmutableMap<String, Object> serialize(JavaPackageFinder packageFinder) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();

    if (packageFinder instanceof DefaultJavaPackageFinder) {
        builder.put(TYPE, TYPE_DEFAULT);
        builder.put(PATH_ELEMENTS, ((DefaultJavaPackageFinder) packageFinder).getPathElements().asList());
        builder.put(PATHS_FROM_ROOT, ((DefaultJavaPackageFinder) packageFinder).getPathsFromRoot().asList());
    } else if (packageFinder instanceof ResourcesRootPackageFinder) {
        builder.put(TYPE, TYPE_RESOURCE_ROOT);
        builder.put(RESOURCES_ROOT, ((ResourcesRootPackageFinder) packageFinder).getResourcesRoot().toString());
        builder.put(FALLBACK_FINDER,//from   w  ww. j  a  va  2 s.  com
                serialize(((ResourcesRootPackageFinder) packageFinder).getFallbackFinder()));
    } else {
        throw new RuntimeException(
                String.format("Cannot serialize JavaPackageFinder with class: %s", packageFinder.getClass()));
    }

    return builder.build();
}

From source file:com.haulmont.bali.util.ParamsMap.java

public static Map<String, Object> of(String paramName1, Object paramValue1, String paramName2,
        Object paramValue2) {//from  www.j av a2s.c o m
    ImmutableMap.Builder<String, Object> b = new ImmutableMap.Builder<>();
    put(b, paramName1, paramValue1);
    put(b, paramName2, paramValue2);
    return b.build();
}

From source file:de.ii.xtraplatform.feature.transformer.api.TargetMappingWfs3Register.java

@Override
public Map<Class<?>, String> getMapping() {
    return new ImmutableMap.Builder<Class<?>, String>().put(TargetMappingWfs3.class, "WFS3")
            .put(TargetMappingTestGeneric.class, "GENERIC_PROPERTY")
            .put(TargetMappingTestMicrodata.class, "MICRODATA_PROPERTY")
            .put(TargetMappingTestGeoJson.class, "GEO_JSON_PROPERTY")
            .put(TargetMappingTestMicrodataGeo.class, "MICRODATA_GEOMETRY")
            .put(TargetMappingTestGeoJsonGEO.class, "GEO_JSON_GEOMETRY")

            .build();/*  w  ww  .j  a v  a  2s .  c  o  m*/
}

From source file:co.runrightfast.core.security.crypto.impl.EncryptionServiceImpl.java

public static Map<String, Key> toKeyMap(@NonNull final SecretKeys keys) {
    final ImmutableMap.Builder<String, Key> mapBuilder = ImmutableMap.builder();
    keys.getKeys().entrySet().stream().forEach(entry -> mapBuilder.put(entry.getKey(),
            SerializationUtils.deserialize(entry.getValue().toByteArray())));
    return mapBuilder.build();
}