Example usage for com.google.common.collect SetMultimap putAll

List of usage examples for com.google.common.collect SetMultimap putAll

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap putAll.

Prototype

boolean putAll(@Nullable K key, Iterable<? extends V> values);

Source Link

Document

Stores a key-value pair in this multimap for each of values , all using the same key, key .

Usage

From source file:org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirementHelper.java

/**
 * Gets a map in which the keys are the types of different requirements and
 * the values represent a set of requirement values linked to that type.
 *
 * @param providers/*w w w. j  a va2  s .c  o  m*/
 *            The set of analysis requirement provider
 * @return A map with the values keyed by type
 */
public static SetMultimap<String, String> getRequirementValuesMap(
        Iterable<IAnalysisRequirementProvider> providers) {
    SetMultimap<String, String> valuesByType = HashMultimap.create();
    for (IAnalysisRequirementProvider provider : providers) {
        for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
            valuesByType.putAll(requirement.getType(), requirement.getValues());
        }
    }
    return valuesByType;
}

From source file:com.opengamma.strata.pricer.calibration.ImmutableRatesProviderGenerator.java

/**
 * Obtains a generator from an existing provider and definition.
 * //from   w  w  w. ja v  a  2 s.c om
 * @param knownProvider  the underlying known provider
 * @param groupDefn  the curve group definition
 * @return the generator
 */
public static ImmutableRatesProviderGenerator of(ImmutableRatesProvider knownProvider,
        CurveGroupDefinition groupDefn) {

    List<NodalCurveDefinition> curveDefns = new ArrayList<>();
    SetMultimap<CurveName, Currency> discountNames = HashMultimap.create();
    SetMultimap<CurveName, Index> indexNames = HashMultimap.create();

    for (NodalCurveDefinition curveDefn : groupDefn.getCurveDefinitions()) {
        curveDefns.add(curveDefn);
        CurveName curveName = curveDefn.getName();
        // A curve group is guaranteed to include an entry for every definition
        CurveGroupEntry entry = groupDefn.findEntry(curveName).get();
        Set<Currency> ccy = entry.getDiscountCurrencies();
        discountNames.putAll(curveName, ccy);
        indexNames.putAll(curveName, entry.getIndices());
    }
    return new ImmutableRatesProviderGenerator(knownProvider, curveDefns, discountNames, indexNames);
}

From source file:ome.services.blitz.repo.path.FilePathRestrictions.java

/**
 * Minimally adjust a set of rules to include transformations away from Unicode control characters.
 * @param rules a set of rules/*from   www. ja v a2 s  .co m*/
 * @return the given rules with full coverage for preventing control characters
 */
private static FilePathRestrictions includeControlTransformations(FilePathRestrictions rules) {
    final Set<Character> safeCharacters = new HashSet<Character>(rules.safeCharacters.size());
    final Set<Integer> safeCodePoints = new HashSet<Integer>(rules.safeCharacters.size());
    for (final Character safeCharacter : rules.safeCharacters) {
        final int safeCodePoint = FilePathRestrictionInstance.getCodePoint(safeCharacter);
        if (!controlCodePoints.contains(safeCodePoint)) {
            safeCharacters.add(safeCharacter);
            safeCodePoints.add(safeCodePoint);
        }
    }
    final SetMultimap<Integer, Integer> newTransformationMatrix = HashMultimap
            .create(Multimaps.filterValues(rules.transformationMatrix, isNotControlCodePoint));
    for (final int controlCodePoint : controlCodePoints) {
        if (!newTransformationMatrix.containsKey(controlCodePoint)) {
            if (rules.transformationMatrix.containsKey(controlCodePoint)) {
                throw new IllegalArgumentException(
                        "only control character mappings available for Unicode code point " + controlCodePoint);
            }
            newTransformationMatrix.putAll(controlCodePoint, safeCodePoints);
        }
    }
    return combineRules(rules,
            new FilePathRestrictions(newTransformationMatrix, null, null, null, safeCharacters));
}

From source file:com.opengamma.strata.pricer.curve.ImmutableRatesProviderGenerator.java

/**
 * Obtains a generator from an existing provider and definition.
 * // w  ww  .j  a  v a 2  s .co  m
 * @param knownProvider  the underlying known provider
 * @param groupDefn  the curve group definition
 * @param refData  the reference data to use
 * @return the generator
 */
public static ImmutableRatesProviderGenerator of(ImmutableRatesProvider knownProvider,
        CurveGroupDefinition groupDefn, ReferenceData refData) {

    List<NodalCurveDefinition> curveDefns = new ArrayList<>();
    List<CurveMetadata> curveMetadata = new ArrayList<>();
    SetMultimap<CurveName, Currency> discountNames = HashMultimap.create();
    SetMultimap<CurveName, Index> indexNames = HashMultimap.create();

    for (NodalCurveDefinition curveDefn : groupDefn.getCurveDefinitions()) {
        curveDefns.add(curveDefn);
        curveMetadata.add(curveDefn.metadata(knownProvider.getValuationDate(), refData));
        CurveName curveName = curveDefn.getName();
        // A curve group is guaranteed to include an entry for every definition
        CurveGroupEntry entry = groupDefn.findEntry(curveName).get();
        Set<Currency> ccy = entry.getDiscountCurrencies();
        discountNames.putAll(curveName, ccy);
        indexNames.putAll(curveName, entry.getIndices());
    }
    return new ImmutableRatesProviderGenerator(knownProvider, curveDefns, curveMetadata, discountNames,
            indexNames);
}

From source file:org.lealone.cluster.db.ClusterMetaData.java

public static SetMultimap<InetAddress, Token> loadTokens() {
    SetMultimap<InetAddress, Token> tokenMap = HashMultimap.create();
    try {/*from  w w w.j a  va2 s  . com*/
        ResultSet rs = stmt.executeQuery("SELECT peer, tokens FROM " + PEERS_TABLE);
        while (rs.next()) {
            String tokens = rs.getString(2);
            if (tokens != null) {
                List<String> list = Arrays.asList(tokens.split(","));
                InetAddress peer = InetAddress.getByName(rs.getString(1));
                tokenMap.putAll(peer, deserializeTokens(list));
            }
        }
        rs.close();
    } catch (Exception e) {
        handleException(e);
    }
    return tokenMap;
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static Map<String, Set<String>> getPossibleValues(Collection<? extends Element> elements) {
    SetMultimap<String, String> values = LinkedHashMultimap.create();

    for (Element e : elements) {
        e.getProperties().forEach((property, value) -> {
            if (value instanceof Boolean) {
                values.putAll(property, Arrays.asList(Boolean.FALSE.toString(), Boolean.TRUE.toString()));
            } else if (value != null) {
                values.put(property, value.toString());
            }/*www. ja  v  a  2  s.c om*/
        });
    }

    return Multimaps.asMap(values);
}

From source file:omero.cmd.graphs.GraphUtil.java

/**
 * Make a copy of a multimap with the full class names in the keys replaced by the simple class names
 * and the ordering of the values preserved.
 * @param entriesByFullName a multimap//ww w. j av a  2s  .  co  m
 * @return a new multimap with the same contents, except for the package name having been trimmed off each key
 */
static <X> SetMultimap<String, X> trimPackageNames(SetMultimap<String, X> entriesByFullName) {
    final SetMultimap<String, X> entriesBySimpleName = LinkedHashMultimap.create();
    for (final Map.Entry<String, Collection<X>> entriesForOneClass : entriesByFullName.asMap().entrySet()) {
        final String fullClassName = entriesForOneClass.getKey();
        final String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
        final Collection<X> values = entriesForOneClass.getValue();
        entriesBySimpleName.putAll(simpleClassName, values);
    }
    return entriesBySimpleName;
}

From source file:org.apache.cassandra.db.SystemTable.java

/**
 * Return a map of stored tokens to IP addresses
 *
 *//*  ww w .j  a  v a2 s.  c  o m*/
public static SetMultimap<InetAddress, Token> loadTokens() {
    SetMultimap<InetAddress, Token> tokenMap = HashMultimap.create();
    for (UntypedResultSet.Row row : processInternal("SELECT peer, tokens FROM system." + PEERS_CF)) {
        InetAddress peer = row.getInetAddress("peer");
        if (row.has("tokens"))
            tokenMap.putAll(peer, deserializeTokens(row.getSet("tokens", UTF8Type.instance)));
    }

    return tokenMap;
}

From source file:co.cask.cdap.etl.common.SetMultimapCodec.java

@Override
public SetMultimap<K, V> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject obj = json.getAsJsonObject();
    Map<K, Collection<V>> map = context.deserialize(obj.get("map"), mapType);
    SetMultimap<K, V> multimap = HashMultimap.create();
    for (Map.Entry<K, Collection<V>> entry : map.entrySet()) {
        multimap.putAll(entry.getKey(), entry.getValue());
    }// w ww. j a  va  2s. c o m
    return multimap;
}

From source file:com.addthis.hydra.query.MeshFileRefCache.java

/**
 * This method filters the file references to ensure that only valid file references are returned.
 * <p/>//from  w  ww .j  av a 2s  . c o  m
 * The filter checks for two things.
 * <p/>
 * <ol>
 * <li>the last modified date for each file for the same task should be the same, if not it will take the
 * newest file</li>
 * <li>the size of the files should be equal, if not, take the files with the largest known size</li>
 * </ol>
 *
 * @param fileRefDataSet - the original unfiltered file reference set
 * @return - filtered file reference map containing only valid file references
 */
@Nonnull
protected static SetMultimap<Integer, FileReference> filterFileReferences(
        @Nonnull SetMultimap<Integer, FileReference> fileRefDataSet) {
    if (fileRefDataSet.isEmpty()) {
        return fileRefDataSet;
    }
    int baseKeySetSize = fileRefDataSet.keySet().size();
    SetMultimap<Integer, FileReference> filteredFileReferenceSet = HashMultimap.create(baseKeySetSize,
            fileRefDataSet.size() / baseKeySetSize);
    for (Map.Entry<Integer, Collection<FileReference>> entry : fileRefDataSet.asMap().entrySet()) {
        int key = entry.getKey();
        final Collection<FileReference> fileReferences = entry.getValue();
        long mostRecentTime = -1;

        for (FileReference fileReference : fileReferences) {
            if ((mostRecentTime < 0) || (fileReference.lastModified > mostRecentTime)) {
                mostRecentTime = fileReference.lastModified;
            }
        }

        final long mostRecentTimeF = mostRecentTime;
        Predicate<FileReference> isMostRecent = input -> (input != null)
                && (input.lastModified == mostRecentTimeF);

        Collection<FileReference> filteredFileReferences = Collections2.filter(fileReferences, isMostRecent);
        filteredFileReferenceSet.putAll(key, filteredFileReferences);
    }
    return filteredFileReferenceSet;
}