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

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

Introduction

In this page you can find the example usage for com.google.common.collect Multimap 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.crypto.sse.IEX2Lev.java

public static IEX2Lev setup(List<byte[]> keys, Multimap<String, String> lookup,
        Multimap<String, String> lookup2, int bigBlock, int smallBlock, int dataSize)
        throws InterruptedException, ExecutionException, IOException {

    // Instantiation of the object that contains Global MM, Local MMs and
    // the dictionary
    RR2Lev[] localMultiMap = new RR2Lev[lookup.keySet().size()];
    Multimap<String, Integer> dictionaryForMM = ArrayListMultimap.create();

    Printer.debugln("Number of (w, id) pairs " + lookup.size());

    Printer.debugln("Number of keywords " + lookup.keySet().size());

    BufferedWriter writer = new BufferedWriter(new FileWriter("logs.txt", true));

    writer.write("\n *********************Stats******* \n");
    writer.write("\n Number of (w, id) pairs " + lookup2.size());
    writer.write("\n Number of keywords " + lookup.keySet().size());

    int counter = 0;

    ///////////////////// Computing Filtering Factor and exact needed data
    ///////////////////// size/////////////////////////////

    HashMap<Integer, Integer> histogram = new HashMap<Integer, Integer>();
    Printer.debugln("Number of documents " + lookup2.keySet().size());
    for (String keyword : lookup.keySet()) {
        if (histogram.get(lookup.get(keyword).size()) != null) {
            int tmp = histogram.get(lookup.get(keyword).size());
            histogram.put(lookup.get(keyword).size(), tmp + 1);
        } else {// ww  w  .j a va 2  s .  c  o  m
            histogram.put(lookup.get(keyword).size(), 1);
        }

        if (dataSize < lookup.get(keyword).size()) {
            dataSize = lookup.get(keyword).size();
        }

    }

    // Construction of the global multi-map
    Printer.debugln("\nBeginning of Global MM creation \n");

    long startTime1 = System.nanoTime();

    IEX2Lev disj2 = new IEX2Lev(RR2Lev.constructEMMParGMM(keys.get(0), lookup, bigBlock, smallBlock, dataSize),
            localMultiMap, dictionaryForMM);

    long endTime1 = System.nanoTime();

    writer.write("\n Time of MM global setup time #(w, id)/#DB " + (endTime1 - startTime1) / lookup2.size());
    writer.close();

    numberPairs = numberPairs + lookup.size();

    // Construction of the local multi-map

    Printer.debugln("Start of Local Multi-Map construction");

    long startTime = System.nanoTime();

    for (String keyword : lookup.keySet()) {

        // Stats for keeping track with the evaluation

        for (int j = 0; j < 100; j++) {

            if (counter == (int) ((j + 1) * lookup.keySet().size() / 100)) {
                BufferedWriter writer2 = new BufferedWriter(new FileWriter("temp-logs.txt", true));
                writer2.write("\n Number of local multi-maps created" + j + " %");
                writer2.close();

                break;
            }
        }

        // Filter setting optional. For a setup without any filtering set
        // filterParameter to 0
        if (((double) lookup.get(keyword).size() / TextExtractPar.maxTupleSize > filterParameter)) {

            // Stats
            Printer.debugln("Keyword in LMM " + keyword);
            BufferedWriter writer3 = new BufferedWriter(new FileWriter("words-logs.txt", true));
            writer3.write("\n Keyword in LMM " + keyword);
            writer3.close();

            for (int j = 0; j < 10; j++) {

                if (counter == (int) ((j + 1) * lookup.keySet().size() / 10)) {
                    Printer.statsln("Number of total keywords processed equals " + j + "0 % \n");
                    break;
                }
            }

            // First computing V_w. Determine Doc identifiers

            Set<String> VW = new TreeSet<String>();
            for (String idDoc : lookup.get(keyword)) {
                VW.addAll(lookup2.get(idDoc));
            }

            Multimap<String, String> secondaryLookup = ArrayListMultimap.create();

            // here we are only interested in documents in the intersection
            // between "keyword" and "word"
            for (String word : VW) {
                // Filter setting optional. For a setup without any
                // filtering set filterParameter to 0
                if (((double) lookup.get(word).size() / TextExtractPar.maxTupleSize > filterParameter)) {
                    Collection<String> l1 = new ArrayList<String>(lookup.get(word));
                    Collection<String> l2 = new ArrayList<String>(lookup.get(keyword));
                    l1.retainAll(l2);
                    secondaryLookup.putAll(word, l1);
                }
            }

            // End of VW construction
            RR2Lev.counter = 0;
            // dataSize = (int) filterParameter;
            disj2.getLocalMultiMap()[counter] = RR2Lev.constructEMMParGMM(
                    CryptoPrimitives.generateCmac(keys.get(0), keyword), secondaryLookup, bigBlock, smallBlock,
                    dataSize);
            byte[] key3 = CryptoPrimitives.generateCmac(keys.get(1), 3 + keyword);
            numberPairs = numberPairs + secondaryLookup.size();
            dictionaryForMM.put(new String(key3), counter);

        }
        counter++;

    }

    long endTime = System.nanoTime();

    Printer.statsln("Time to construct LMM " + (endTime - startTime) / 1000000000);

    disj2.setDictionaryForMM(dictionaryForMM);
    return disj2;

}

From source file:org.crypto.sse.IEXRH2Lev.java

public static IEXRH2Lev setup(List<byte[]> keys, Multimap<String, String> lookup,
        Multimap<String, String> lookup2, int bigBlock, int smallBlock, int dataSize)
        throws InterruptedException, ExecutionException, IOException {

    // Instantiation of the object that contains Global MM, Local MMs and
    // the dictionary
    RH2Lev[] localMultiMap = new RH2Lev[lookup.keySet().size()];
    Multimap<String, Integer> dictionaryForMM = ArrayListMultimap.create();

    Printer.debugln("Number of (w, id) pairs " + lookup.size());

    Printer.debugln("Number of keywords " + lookup.keySet().size());

    Printer.debugln("Maximum size of |DB(w)| " + TextExtractPar.maxTupleSize);

    BufferedWriter writer = new BufferedWriter(new FileWriter("logs.txt", true));

    writer.write("\n *********************Stats******* \n");

    writer.write("\n Number of (w, id) pairs " + lookup2.size());
    writer.write("\n Number of keywords " + lookup.keySet().size());

    int counter = 0;

    ///////////////////// Computing Filtering Factor and exact needed data
    ///////////////////// size/////////////////////////////

    HashMap<Integer, Integer> histogram = new HashMap<Integer, Integer>();
    Printer.debugln("Number of documents " + lookup2.keySet().size());
    for (String keyword : lookup.keySet()) {
        if (histogram.get(lookup.get(keyword).size()) != null) {
            int tmp = histogram.get(lookup.get(keyword).size());
            histogram.put(lookup.get(keyword).size(), tmp + 1);
        } else {/*from w ww.ja  v  a2 s  .co  m*/
            histogram.put(lookup.get(keyword).size(), 1);
        }

        if (dataSize < lookup.get(keyword).size()) {
            dataSize = lookup.get(keyword).size();
        }

    }

    // Construction of the global multi-map
    Printer.debugln("\nBeginning of Global MM creation \n");

    long startTime1 = System.nanoTime();

    IEXRH2Lev disj2 = new IEXRH2Lev(
            RH2Lev.constructEMMParGMM(keys.get(0), lookup, bigBlock, smallBlock, dataSize), localMultiMap,
            dictionaryForMM);

    long endTime1 = System.nanoTime();

    writer.write("\n Time of MM global setup time #(w, id)/#DB " + (endTime1 - startTime1) / lookup2.size());
    writer.close();

    numberPairs = numberPairs + lookup.size();

    // Construction of the local multi-map

    Printer.debugln("Start of Local Multi-Map construction");

    long startTime = System.nanoTime();

    for (String keyword : lookup.keySet()) {

        // Stats for keeping track with the evaluation

        for (int j = 0; j < 100; j++) {

            if (counter == (int) ((j + 1) * lookup.keySet().size() / 100)) {
                BufferedWriter writer2 = new BufferedWriter(new FileWriter("temp-logs.txt", true));
                writer2.write("\n Number of local multi-maps created" + j + " %");
                writer2.close();

                break;
            }
        }

        // Filter setting optional. For a setup without any filtering set
        // filterParameter to 0
        if (((double) lookup.get(keyword).size() / TextExtractPar.maxTupleSize > filterParameter)) {

            // Stats
            Printer.debugln("Keyword in LMM " + keyword);
            BufferedWriter writer3 = new BufferedWriter(new FileWriter("words-logs.txt", true));
            writer3.write("\n Keyword in LMM " + keyword);
            writer3.close();

            for (int j = 0; j < 10; j++) {

                if (counter == (int) ((j + 1) * lookup.keySet().size() / 10)) {
                    Printer.statsln("Number of total keywords processed equals " + j + "0 % \n");
                    break;
                }
            }

            // First computing V_w. Determine Doc identifiers

            Set<String> VW = new TreeSet<String>();
            for (String idDoc : lookup.get(keyword)) {
                VW.addAll(lookup2.get(idDoc));
            }

            Multimap<String, String> secondaryLookup = ArrayListMultimap.create();

            // here we are only interested in documents in the intersection
            // between "keyword" and "word"
            for (String word : VW) {
                // Filter setting optional. For a setup without any
                // filtering set filterParameter to 0
                if (((double) lookup.get(word).size() / TextExtractPar.maxTupleSize > filterParameter)) {
                    Collection<String> l1 = new ArrayList<String>(lookup.get(word));
                    Collection<String> l2 = new ArrayList<String>(lookup.get(keyword));
                    l1.retainAll(l2);
                    secondaryLookup.putAll(word, l1);
                }
            }

            // End of VW construction
            RH2Lev.counter = 0;

            // dataSize = (int) filterParameter;
            EMM2Lev.eval = 4 + keyword;
            EMM2Lev.lmm = true;

            disj2.getLocalMultiMap()[counter] = RH2Lev.constructEMMParGMM(
                    CryptoPrimitives.generateCmac(keys.get(0), keyword), secondaryLookup, bigBlock, smallBlock,
                    dataSize);
            byte[] key3 = CryptoPrimitives.generateCmac(keys.get(1), 3 + keyword);
            numberPairs = numberPairs + secondaryLookup.size();
            dictionaryForMM.put(new String(key3), counter);

        }
        counter++;

    }

    long endTime = System.nanoTime();

    Printer.statsln("Time to construct LMM " + (endTime - startTime) / 1000000000);

    disj2.setDictionaryForMM(dictionaryForMM);
    return disj2;

}

From source file:android.security.cts.SELinuxPolicyRule.java

public static SELinuxPolicyRule readRule(XmlPullParser xpp) throws IOException, XmlPullParserException {
    List<String> source_types = new ArrayList<String>();
    List<String> target_types = new ArrayList<String>();
    Multimap<String, String> obj_classes = HashMultimap.create();
    xpp.require(XmlPullParser.START_TAG, null, "avc_rule");
    String ruleName = xpp.getAttributeValue(null, "name");
    String ruleType = xpp.getAttributeValue(null, "type");
    while (xpp.next() != XmlPullParser.END_TAG) {
        if (xpp.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }/* w ww .j  av  a  2  s.c o  m*/
        String name = xpp.getName();
        if (name.equals("type")) {
            if (xpp.getAttributeValue(null, "type").equals("source")) {
                source_types.add(readType(xpp));
            } else if (xpp.getAttributeValue(null, "type").equals("target")) {
                target_types.add(readType(xpp));
            } else {
                skip(xpp);
            }
        } else if (name.equals("obj_class")) {
            String obj_name = xpp.getAttributeValue(null, "name");
            List<String> perms = readObjClass(xpp);
            obj_classes.putAll(obj_name, perms);
        } else {
            skip(xpp);
        }
    }
    return new SELinuxPolicyRule(source_types, target_types, obj_classes, ruleName, ruleType);
}

From source file:cuchaz.enigma.translation.Translator.java

default <K extends Translatable, V extends Translatable> Multimap<K, V> translate(Multimap<K, V> translatable) {
    Multimap<K, V> result = HashMultimap.create(translatable.size(), 1);
    for (Map.Entry<K, Collection<V>> entry : translatable.asMap().entrySet()) {
        result.putAll(translate(entry.getKey()), translate(entry.getValue()));
    }//from w  w  w.  j av  a 2 s. co m
    return result;
}

From source file:com.eucalyptus.cloudwatch.common.internal.domain.alarms.AlarmManager.java

private static Map<String, Collection<String>> buildAccountIdToAlarmNamesMap(@Nullable final String accountId,
        @Nullable final Collection<String> alarmNames) {
    final Multimap<String, String> alarmNamesMultimap = HashMultimap.create();
    if (alarmNames != null) {
        if (accountId != null) {
            alarmNamesMultimap.putAll(accountId, alarmNames); // An ARN is also a valid name
        }//from   www  .  j  a va 2  s . c  om
        CollectionUtils.putAll(
                Optional.presentInstances(Iterables.transform(alarmNames,
                        CloudWatchResourceName.asArnOfType(CloudWatchResourceName.Type.alarm))),
                alarmNamesMultimap, CloudWatchResourceName.toNamespace(), CloudWatchResourceName.toName());
    }
    return alarmNamesMultimap.asMap();
}

From source file:com.imaginarycode.minecraft.bungeejson.impl.httpserver.HttpServerHandler.java

private <K, V> Multimap<K, V> createMultimapFromMap(Map<K, List<V>> map) {
    Multimap<K, V> multimap = HashMultimap.create();
    for (Map.Entry<K, List<V>> entry : map.entrySet()) {
        multimap.putAll(entry.getKey(), entry.getValue());
    }/* w  ww. ja  v a 2 s  . c  om*/
    return multimap;
}

From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java

public static NoteMap parseCommentsFromNotes(Repository repo, String refName, RevWalk walk, Change.Id changeId,
        Multimap<RevId, PatchLineComment> comments, Status status) throws IOException, ConfigInvalidException {
    Ref ref = repo.getRefDatabase().exactRef(refName);
    if (ref == null) {
        return null;
    }//w  w w  .  j  av a  2s  .co  m

    ObjectReader reader = walk.getObjectReader();
    RevCommit commit = walk.parseCommit(ref.getObjectId());
    NoteMap noteMap = NoteMap.read(reader, commit);

    for (Note note : noteMap) {
        byte[] bytes = reader.open(note.getData(), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
        List<PatchLineComment> result = parseNote(bytes, changeId, status);
        if (result == null || result.isEmpty()) {
            continue;
        }
        comments.putAll(new RevId(note.name()), result);
    }
    return noteMap;
}

From source file:grakn.core.graql.reasoner.plan.QueryCollectionBase.java

private Multimap<ReasonerQueryImpl, ReasonerQueryImpl> immediateNeighbourMap() {
    Multimap<ReasonerQueryImpl, ReasonerQueryImpl> neighbourMap = HashMultimap.create();
    this.stream().forEach(q -> neighbourMap.putAll(q, getImmediateNeighbours(q)));
    return neighbourMap;
}

From source file:com.epam.reportportal.extension.bugtracking.InternalTicketAssembler.java

@Override
public InternalTicket apply(PostTicketRQ input) {
    InternalTicket ticket = new InternalTicket();

    if (null != input.getFields()) {
        Multimap<String, String> fieldsMultimap = LinkedListMultimap.create();
        for (PostFormField field : input.getFields()) {
            fieldsMultimap.putAll(field.getId(), field.getValue());
        }//  w w  w.j  a v  a 2 s. c o m
        ticket.setFields(fieldsMultimap);
    }

    if (input.getIsIncludeLogs() || input.getIsIncludeScreenshots()) {
        List<Log> logs = logRepository.findByTestItemRef(input.getTestItemId(),
                0 == input.getNumberOfLogs() ? Integer.MAX_VALUE : input.getNumberOfLogs(),
                input.getIsIncludeScreenshots());
        List<InternalTicket.LogEntry> entries = new ArrayList<>(logs.size());
        for (Log log : logs) {
            BinaryData attachment = null;
            /* Get screenshots if required and they are present */
            if (null != log.getBinaryContent() && input.getIsIncludeScreenshots()) {
                attachment = dataStorage.fetchData(log.getBinaryContent().getBinaryDataId());
            }
            /* Forwarding enabled logs boolean if screens only required */
            entries.add(new InternalTicket.LogEntry(log, attachment, input.getIsIncludeLogs()));
        }
        ticket.setLogs(entries);
    }

    if (input.getIsIncludeComments()) {
        TestItem testItem = itemRepository.findOne(input.getTestItemId());
        if (null != testItem.getIssue().getIssueDescription())
            ticket.setComments(testItem.getIssue().getIssueDescription());
    }

    if (!CommonPredicates.IS_MAP_EMPTY.test(input.getBackLinks())) {
        ticket.setBackLinks(ImmutableMap.copyOf(input.getBackLinks()));
    }
    return ticket;
}

From source file:org.eclipse.xtext.mwe.PathTraverser.java

public Multimap<String, URI> resolvePathes(List<String> pathes, Predicate<URI> isValidPredicate) {
    Multimap<String, URI> uris = HashMultimap.create();
    for (String path : pathes) {
        Set<URI> resourceUris = findAllResourceUris(path, isValidPredicate);
        uris.putAll(path, resourceUris);
    }/*  w ww. j  a va  2  s .  c  o  m*/
    return uris;
}