Example usage for com.google.common.collect Multimap clear

List of usage examples for com.google.common.collect Multimap clear

Introduction

In this page you can find the example usage for com.google.common.collect Multimap clear.

Prototype

void clear();

Source Link

Document

Removes all key-value pairs from the multimap, leaving it #isEmpty empty .

Usage

From source file:cuchaz.enigma.analysis.EntryRenamer.java

public static <Key, Val> void renameClassesInMultimap(Map<String, String> renames, Multimap<Key, Val> map) {
    // for each key/value pair...
    Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet();
    for (Map.Entry<Key, Val> entry : map.entries()) {
        entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameClassesInThing(renames, entry.getKey()),
                renameClassesInThing(renames, entry.getValue())));
    }//w w  w. j a v  a2  s  . c  o m
    map.clear();
    for (Map.Entry<Key, Val> entry : entriesToAdd) {
        map.put(entry.getKey(), entry.getValue());
    }
}

From source file:cuchaz.enigma.analysis.EntryRenamer.java

public static <Key, Val> void renameMethodsInMultimap(Map<MethodEntry, MethodEntry> renames,
        Multimap<Key, Val> map) {
    // for each key/value pair...
    Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet();
    for (Map.Entry<Key, Val> entry : map.entries()) {
        entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameMethodsInThing(renames, entry.getKey()),
                renameMethodsInThing(renames, entry.getValue())));
    }//ww w. jav a  2  s  .c  om
    map.clear();
    for (Map.Entry<Key, Val> entry : entriesToAdd) {
        map.put(entry.getKey(), entry.getValue());
    }
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CQLKeyValueServices.java

public static void waitForSchemaVersionsToCoalesce(String encapsulatingOperationDescription,
        CQLKeyValueService kvs) {//from w  ww  .j a v a 2s.  c o  m
    PreparedStatement peerInfoQuery = kvs.getPreparedStatement(CassandraConstants.NO_TABLE,
            "select peer, schema_version from system.peers;", kvs.session);
    peerInfoQuery.setConsistencyLevel(ConsistencyLevel.ALL);

    Multimap<UUID, InetAddress> peerInfo = ArrayListMultimap.create();
    long start = System.currentTimeMillis();
    long sleepTime = 100;
    do {
        peerInfo.clear();
        for (Row row : kvs.session.execute(peerInfoQuery.bind()).all()) {
            peerInfo.put(row.getUUID("schema_version"), row.getInet("peer"));
        }

        if (peerInfo.keySet().size() <= 1) { // full schema agreement
            return;
        }
        sleepTime = Math.min(sleepTime * 2, 5000);
    } while (System.currentTimeMillis() < start + CassandraConstants.SECONDS_WAIT_FOR_VERSIONS * 1000);

    StringBuilder sb = new StringBuilder();
    sb.append(String.format(
            "Cassandra cluster cannot come to agreement on schema versions, during operation: %s.",
            encapsulatingOperationDescription));

    for (Entry<UUID, Collection<InetAddress>> versionToPeer : peerInfo.asMap().entrySet()) {
        sb.append(String.format("\nAt schema version %s:", versionToPeer.getKey()));
        for (InetAddress peer : versionToPeer.getValue()) {
            sb.append(String.format("\n\tNode: %s", peer));
        }
    }
    sb.append("\nFind the nodes above that diverge from the majority schema "
            + "(or have schema 'UNKNOWN', which likely means they are down/unresponsive) "
            + "and examine their logs to determine the issue. Fixing the underlying issue and restarting Cassandra "
            + "should resolve the problem. You can quick-check this with 'nodetool describecluster'.");
    throw new IllegalStateException(sb.toString());
}

From source file:org.sonar.server.computation.task.projectanalysis.filemove.FileMoveDetectionStep.java

private static void electMatches(@Nullable List<Match> matches, ElectedMatches electedMatches,
        Multimap<String, Match> matchesPerFileForScore) {
    // no match for this score value, ignore
    if (matches == null) {
        return;//from   ww  w  . ja v a2s  . co m
    }

    List<Match> matchesToValidate = electedMatches.filter(matches);
    if (matchesToValidate.isEmpty()) {
        return;
    }
    if (matchesToValidate.size() == 1) {
        Match match = matchesToValidate.get(0);
        electedMatches.add(match);
    } else {
        matchesPerFileForScore.clear();
        for (Match match : matchesToValidate) {
            matchesPerFileForScore.put(match.getDbKey(), match);
            matchesPerFileForScore.put(match.getReportKey(), match);
        }
        // validate non ambiguous matches (ie. the match is the only match of either the db file and the report file)
        for (Match match : matchesToValidate) {
            int dbFileMatchesCount = matchesPerFileForScore.get(match.getDbKey()).size();
            int reportFileMatchesCount = matchesPerFileForScore.get(match.getReportKey()).size();
            if (dbFileMatchesCount == 1 && reportFileMatchesCount == 1) {
                electedMatches.add(match);
            }
        }
    }
}

From source file:com.axelor.db.JPA.java

/**
 * Edit an instance of the given model class using the given values.<br>
 * <br>//from   w  w  w  .  j  av  a  2s .c  o  m
 * This is a convenient method to reconstruct model object from a key value
 * map, for example HTTP params.
 * 
 * @param klass
 *            a model class
 * @param values
 *            key value map where key represents a field name
 * @return a JPA managed object of the given model class
 */
public static <T extends Model> T edit(Class<T> klass, Map<String, Object> values) {
    Set<Model> visited = Sets.newHashSet();
    Multimap<String, Long> edited = HashMultimap.create();
    try {
        return _edit(klass, values, visited, edited);
    } finally {
        visited.clear();
        edited.clear();
    }
}

From source file:org.sonar.server.computation.filemove.FileMoveDetectionStep.java

private static ElectedMatches electMatches(Set<String> dbFileKeys, Map<String, File> reportFileSourcesByKey,
        MatchesByScore matchesByScore) {
    ElectedMatches electedMatches = new ElectedMatches(matchesByScore, dbFileKeys, reportFileSourcesByKey);
    Multimap<String, Match> matchesPerFileForScore = ArrayListMultimap.create();
    for (List<Match> matches : matchesByScore) {
        // no match for this score value, ignore
        if (matches == null) {
            continue;
        }//from   www  .  j av  a 2 s . co m

        List<Match> matchesToValidate = electedMatches.filter(matches);
        if (matches.isEmpty()) {
            continue;
        }
        if (matches.size() == 1) {
            Match match = matches.get(0);
            electedMatches.add(match);
        } else {
            matchesPerFileForScore.clear();
            for (Match match : matches) {
                matchesPerFileForScore.put(match.getDbKey(), match);
                matchesPerFileForScore.put(match.getReportKey(), match);
            }
            // validate non ambiguous matches (ie. the match is the only match of either the db file and the report file)
            for (Match match : matchesToValidate) {
                int dbFileMatchesCount = matchesPerFileForScore.get(match.getDbKey()).size();
                int reportFileMatchesCount = matchesPerFileForScore.get(match.getReportKey()).size();
                if (dbFileMatchesCount == 1 && reportFileMatchesCount == 1) {
                    electedMatches.add(match);
                }
            }
        }
    }
    return electedMatches;
}

From source file:fr.letroll.ttorrentandroid.tracker.TrackerService.java

@Nonnull
@VisibleForTesting//from   w  w  w .  j a  va  2 s  . co m
public static Multimap<String, String> parseQuery(String query) {
    Multimap<String, String> params = ArrayListMultimap.create();
    Splitter ampersand = Splitter.on('&').omitEmptyStrings();
    // Splitter equals = Splitter.on('=').limit(2);

    try {
        for (String pair : ampersand.split(query)) {
            String[] keyval = pair.split("[=]", 2);
            if (keyval.length == 1) {
                parseParam(params, keyval[0], null);
            } else {
                parseParam(params, keyval[0], keyval[1]);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        params.clear();
    }
    return params;
}

From source file:eu.esdihumboldt.hale.common.core.service.cleanup.impl.CleanupServiceImpl.java

private <T> Collection<T> take(CleanupContext context, Multimap<CleanupContext, T> elements) {
    switch (context) {
    case APPLICATION:
        // all elements
        Collection<T> res1 = new ArrayList<T>(elements.values());
        elements.clear();
        return res1;
    default:// w  w w  . jav  a2s  .  c  om
        Collection<T> res2 = new ArrayList<T>(elements.get(context));
        elements.removeAll(context);
        return res2;
    }
}

From source file:org.spongepowered.common.registry.SpongeVillagerRegistry.java

@Override
public VillagerRegistry setMutators(Career career, Multimap<Integer, TradeOfferListMutator> generatorMap) {
    checkNotNull(career, "Career cannot be null!");
    checkNotNull(generatorMap, "Generators cannot be null!");
    Multimap<Integer, TradeOfferListMutator> multimap = this.careerGeneratorMap.get(career);
    if (multimap != null) {
        multimap.clear();
    }/*  w  ww .  j a v a2 s  .  c  o  m*/
    multimap = ArrayListMultimap.create(generatorMap);
    this.careerGeneratorMap.put(career, multimap);
    return this;
}

From source file:com.github.haixing_hu.lang.Assignment.java

public static <K, V> Multimap<K, V> assign(@Nullable Multimap<K, V> left,
        @Nullable final Multimap<K, V> right) {
    if (right == null) {
        if (left != null) {
            left.clear();
        }/*from  w ww  . j a  v  a 2s.  co  m*/
    } else {
        if (left == null) {
            left = LinkedHashMultimap.create();
        } else {
            left.clear();
        }
        left.putAll(right);
    }
    return left;
}