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

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

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a view collection of all distinct keys contained in this multimap.

Usage

From source file:it.units.malelab.ege.benchmark.symbolicregression.MathUtils.java

public static Map<String, double[]> combinedValuesMap(Map<String, double[]> flatMap) {
    String[] names = new String[flatMap.keySet().size()];
    int[] counters = new int[flatMap.keySet().size()];
    Multimap<String, Double> multimap = ArrayListMultimap.create();
    //init/*from  ww  w .  j  a  va2  s  .c o m*/
    int y = 0;
    for (String name : flatMap.keySet()) {
        names[y] = name;
        counters[y] = 0;
        y = y + 1;
    }
    //fill map
    while (true) {
        for (int i = 0; i < names.length; i++) {
            multimap.put(names[i], flatMap.get(names[i])[counters[i]]);
        }
        for (int i = 0; i < counters.length; i++) {
            counters[i] = counters[i] + 1;
            if ((i < counters.length - 1) && (counters[i] == flatMap.get(names[i]).length)) {
                counters[i] = 0;
            } else {
                break;
            }
        }
        if (counters[counters.length - 1] == flatMap.get(names[counters.length - 1]).length) {
            break;
        }
    }
    //transform
    Map<String, double[]> map = new LinkedHashMap<>();
    for (String key : multimap.keySet()) {
        double[] values = new double[multimap.get(key).size()];
        int i = 0;
        for (Double value : multimap.get(key)) {
            values[i] = value;
            i = i + 1;
        }
        map.put(key, values);
    }
    return map;
}

From source file:com.facebook.buck.android.WriteAppModuleMetadataStep.java

private void writeModuleToStringsMultimap(Multimap<APKModule, String> map, Collection<String> dest) {
    for (APKModule dexStore : map.keySet()) {
        dest.add(MODULE_INDENTATION + dexStore.getName());
        for (String item : map.get(dexStore)) {
            dest.add(ITEM_INDENTATION + item);
        }/*from  w  w w. j a  v  a 2 s  .  c  om*/
    }
}

From source file:pt.ua.ieeta.biomedhub.dictionaries.NejiWriter.java

@Override
public void write(String file, Multimap syn) {
    BufferedWriter writer = null;

    Multimap<String, String> synons = (Multimap) syn;
    try {// www .  j  a v  a  2s.  c  o  m
        writer = new BufferedWriter(new FileWriter(file));

        for (String s : synons.keySet()) {
            String _syns = "";
            for (String _syn : synons.get(s)) {
                _syns += _syn + "|";
            }
            writer.write("UMLS:" + s + ":T023:ANAT\t" + removeLastChar(_syns) + "\n");
            System.out.println("UMLS:" + s + ":T023:ANAT\t" + removeLastChar(_syns));

        }
    } catch (IOException e) {
    } finally {
        try {
            if (writer != null) {
                writer.close();
            }
        } catch (IOException e) {
        }
    }
}

From source file:crawler.HTTPRequest.java

public String serializeRequest(HTTPClient.HTTPMethod method) {
    // give StringBuilder some initial capacity will save time if the 
    // request is big
    StringBuilder builder = new StringBuilder(112);

    // BUILDING FIRST LINE 
    builder.append(method.value());//from  ww w.ja va 2 s .com
    builder.append(" ");
    String path = this.getURL().getPath();
    builder.append(path == "" ? "/" : path);
    builder.append(" ");
    builder.append("HTTP/1.0\r\n");

    // BUILDING HEADERS 
    Multimap<String, String> headers = this.getHeaders();

    for (String key : headers.keySet()) {

        Collection<String> values = headers.get(key);

        for (String value : values) {
            builder.append(key);
            builder.append(":");
            builder.append(value);
            builder.append("\r\n");
        }
    }

    builder.append("\r\n");

    if (method == HTTPClient.HTTPMethod.POST) {
        builder.append(this.getRequestBody());
    }

    return builder.toString();
}

From source file:cuchaz.enigma.convert.MappingsConverter.java

public static Mappings newMappings(ClassMatches matches, Mappings oldMappings, Deobfuscator sourceDeobfuscator,
        Deobfuscator destDeobfuscator) {

    // sort the unique matches by size of inner class chain
    Multimap<Integer, java.util.Map.Entry<ClassEntry, ClassEntry>> matchesByDestChainSize = HashMultimap
            .create();/*from   ww  w.  j a  v a2s.com*/
    for (java.util.Map.Entry<ClassEntry, ClassEntry> match : matches.getUniqueMatches().entrySet()) {
        int chainSize = destDeobfuscator.getJarIndex().getObfClassChain(match.getValue()).size();
        matchesByDestChainSize.put(chainSize, match);
    }

    // build the mappings (in order of small-to-large inner chains)
    Mappings newMappings = new Mappings();
    List<Integer> chainSizes = Lists.newArrayList(matchesByDestChainSize.keySet());
    Collections.sort(chainSizes);
    for (int chainSize : chainSizes) {
        for (java.util.Map.Entry<ClassEntry, ClassEntry> match : matchesByDestChainSize.get(chainSize)) {

            // get class info
            ClassEntry obfSourceClassEntry = match.getKey();
            ClassEntry obfDestClassEntry = match.getValue();
            List<ClassEntry> destClassChain = destDeobfuscator.getJarIndex()
                    .getObfClassChain(obfDestClassEntry);

            ClassMapping sourceMapping = sourceDeobfuscator.getMappings().getClassByObf(obfSourceClassEntry);
            if (sourceMapping == null) {
                // if this class was never deobfuscated, don't try to match it
                continue;
            }

            // find out where to make the dest class mapping
            if (destClassChain.size() == 1) {
                // not an inner class, add directly to mappings
                newMappings
                        .addClassMapping(migrateClassMapping(obfDestClassEntry, sourceMapping, matches, false));
            } else {
                // inner class, find the outer class mapping
                ClassMapping destMapping = null;
                for (int i = 0; i < destClassChain.size() - 1; i++) {
                    ClassEntry destChainClassEntry = destClassChain.get(i);
                    if (destMapping == null) {
                        destMapping = newMappings.getClassByObf(destChainClassEntry);
                        if (destMapping == null) {
                            destMapping = new ClassMapping(destChainClassEntry.getName());
                            newMappings.addClassMapping(destMapping);
                        }
                    } else {
                        destMapping = destMapping
                                .getInnerClassByObfSimple(destChainClassEntry.getInnermostClassName());
                        if (destMapping == null) {
                            destMapping = new ClassMapping(destChainClassEntry.getName());
                            destMapping.addInnerClassMapping(destMapping);
                        }
                    }
                }
                destMapping.addInnerClassMapping(
                        migrateClassMapping(obfDestClassEntry, sourceMapping, matches, true));
            }
        }
    }
    return newMappings;
}

From source file:org.gradle.execution.TaskNameResolvingBuildConfigurationAction.java

public void configure(BuildExecutionContext context) {
    GradleInternal gradle = context.getGradle();
    List<String> taskNames = gradle.getStartParameter().getTaskNames();
    Multimap<String, Task> selectedTasks = doSelect(gradle, taskNames, taskNameResolver);

    TaskGraphExecuter executer = gradle.getTaskGraph();
    for (String name : selectedTasks.keySet()) {
        executer.addTasks(selectedTasks.get(name));
    }//w  ww .  jav  a  2  s  . c o  m

    if (selectedTasks.keySet().size() == 1) {
        LOGGER.info("Selected primary task {}", GUtil.toString(selectedTasks.keySet()));
    } else {
        LOGGER.info("Selected primary tasks {}", GUtil.toString(selectedTasks.keySet()));
    }

    context.proceed();
}

From source file:org.opentestsystem.shared.security.service.RoleSpecificPermissionsService.java

private Map<String, RoleToPermissionMapping> getRoleMapping() {
    if (roleMapping == null) {
        Map<String, RoleToPermissionMapping> map = new HashMap<String, RoleToPermissionMapping>();
        Multimap<String, SbacPermission> resolvedRoles = permissionResolver.getRoleBindings(componentName);
        for (String sbacRoleName : resolvedRoles.keySet()) {
            RoleToPermissionMapping mapping = new RoleToPermissionMapping(sbacRoleName,
                    resolvedRoles.get(sbacRoleName), true);
            map.put(sbacRoleName, mapping);
        }//from ww  w  .ja v a  2s  .  c  o m
        roleMapping = map;
    }
    return roleMapping;
}

From source file:io.bazel.rules.closure.webfiles.WebfilesValidatorProgram.java

private int displayErrors(Set<String> suppress, Multimap<String, String> errors) {
    int exitCode = 0;
    for (String category : errors.keySet()) {
        boolean ignored = suppress.contains(category) || suppress.contains(SUPPRESS_EVERYTHING);
        String prefix = ignored ? WARNING_PREFIX : ERROR_PREFIX;
        for (String error : errors.get(category)) {
            output.println(prefix + error);
        }/* w w w  . j ava 2s.c o m*/
        if (!ignored) {
            exitCode = 1;
            output.printf("%sUse suppress=[\"%s\"] to make the errors above warnings%n", NOTE_PREFIX, category);
        }
    }
    return exitCode;
}

From source file:org.softinica.maven.jmeter.report.analyser.SummaryReportAnalyzer.java

@Override
protected void fillTable(Table table, Multimap<Object, Sample> grouped) {
    StandardDeviation deviation = new StandardDeviation();
    for (Object key : grouped.keySet()) {
        double total = 0D;
        int sampleCount = grouped.get(key).size();
        double[] values = new double[sampleCount];
        double min = Double.MAX_VALUE;
        double max = Double.MIN_VALUE;
        long minTimestamp = Long.MAX_VALUE;
        long maxTimestamp = Long.MIN_VALUE;
        long totalBytes = 0;
        int errorCount = 0;
        int i = 0;
        for (Sample sample : grouped.get(key)) {
            total += sample.getValue();/*from   ww  w .java  2 s . c o  m*/
            values[i] = sample.getValue();
            i++;
            if (min > sample.getValue()) {
                min = sample.getValue();
            }
            if (max < sample.getValue()) {
                max = sample.getValue();
            }
            if (!sample.isSuccess()) {
                errorCount++;
            }
            if (minTimestamp > sample.getTimestamp()) {
                minTimestamp = sample.getTimestamp();
            }
            if (maxTimestamp < sample.getTimestamp()) {
                maxTimestamp = sample.getTimestamp();
            }
            totalBytes += sample.getByteCount();
        }
        table.put(key, LABEL, key.toString());
        table.put(key, SAMPLES, String.valueOf(sampleCount));
        table.put(key, AVERAGE, NUMBER_FORMAT.format(total / sampleCount));
        table.put(key, MIN, NUMBER_FORMAT.format(min));
        table.put(key, MAX, NUMBER_FORMAT.format(max));
        table.put(key, STD_DEV, NUMBER_FORMAT.format(deviation.evaluate(values)));
        table.put(key, ERROR, NUMBER_FORMAT.format(100.0D * errorCount / sampleCount));
        table.put(key, THROUGHPUT, NUMBER_FORMAT.format(sampleCount / total * 1000));
        table.put(key, KB_PER_SEC, NUMBER_FORMAT.format(totalBytes / total * 1000));
        table.put(key, AVERAGE_BYTES, NUMBER_FORMAT.format(totalBytes / sampleCount));
    }
}

From source file:eu.interedition.collatex.dekker.matrix.IslandConflictResolver.java

private List<Double> shortestToLongestDistances(Multimap<Double, Island> distanceMap) {
    List<Double> distances = Lists.newArrayList(distanceMap.keySet());
    Collections.sort(distances);//from  w ww .  ja v a  2s  .c om
    return distances;
}