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

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

Introduction

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

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:com.eucalyptus.util.CollectionUtils.java

public static <I, K, V> Multimap<K, V> putAll(final Iterable<? extends I> iterable,
        final Multimap<K, V> targetMap, final Function<? super I, K> keyFunction,
        final Function<? super I, V> valueFunction) {
    if (iterable != null)
        for (final I item : iterable) {
            targetMap.put(keyFunction.apply(item), valueFunction.apply(item));
        }/*from w  w  w  .  j ava2 s .c  o m*/
    return targetMap;
}

From source file:org.jetbrains.jet.buildergen.EntityBuilder.java

private static void bindOverriddenRelations(Entity entity, Set<Entity> alreadyBound) {
    if (!alreadyBound.add(entity))
        return;// w  ww  .ja va  2s .co  m
    Multimap<String, Relation<?>> superRelations = HashMultimap.create();
    for (Entity superEntity : entity.getSuperEntities()) {
        bindOverriddenRelations(superEntity, alreadyBound);
        for (Relation<?> relation : superEntity.getRelations()) {
            superRelations.put(relation.getName(), relation);
        }
    }
    Set<String> explicitlyOverridden = Sets.newHashSet();
    for (Relation<?> relation : Lists.newArrayList(entity.getRelations())) {
        relation.getOverriddenRelations().addAll(superRelations.get(relation.getName()));
        explicitlyOverridden.add(relation.getName());
    }

    // "fake overrides"
    for (Map.Entry<String, Collection<Relation<?>>> entry : superRelations.asMap().entrySet()) {
        String relationName = entry.getKey();
        Collection<Relation<?>> overriddenRelations = entry.getValue();
        Relation<?> someOverridden = ContainerUtil.getFirstItem(overriddenRelations);
        RelationWithTarget<Object> fakeOverride = new RelationWithTarget<Object>(
                someOverridden.getMultiplicity(), relationName, someOverridden.getTarget());
        fakeOverride.getOverriddenRelations().addAll(overriddenRelations);
        entity.getRelations().add(fakeOverride);
    }
}

From source file:moa2014.MOAH32014.java

public static int principal(int[][] matrizatual) {
    long startTime = System.currentTimeMillis();
    Multimap<Integer, String> open_list = TreeMultimap.create();
    HashMap<String, Estado> processados = new HashMap();

    int difmatrizatual = diferencaMatriz(matrizatual);

    String stringmatriz = transformaMatrizString(matrizatual);
    open_list.put(difmatrizatual, stringmatriz);
    Estado estadoatual = new Estado(matrizatual, 0);
    processados.put(stringmatriz, estadoatual);

    int arvoresgeradas = 0;
    int arvoresprocessadas = 0;

    while (!open_list.isEmpty()) {
        Iterator iterator = open_list.keySet().iterator();
        Integer key = (Integer) iterator.next();
        String matrizatualx1 = open_list.asMap().get(key).iterator().next();
        Estado estadomenor = processados.get(matrizatualx1);
        int altura = estadomenor.getCusto();
        //LOCALIZA O ZERO
        int[] zerot = localizazero(estadomenor.getMatriz());
        int x = zerot[0];
        int y = zerot[1];
        int x0 = x - 1;
        int x1 = x + 1;
        int y0 = y - 1;
        int y1 = y + 1;
        int difmatrizatualx = diferencaMatriz(estadomenor.getMatriz());
        if (difmatrizatualx == 0) {
            long endTime = System.currentTimeMillis();
            System.out.println("---------------------------------------");
            System.out.println("Arvores Geradas: " + arvoresgeradas);
            System.out.println("Arvores Processadas: " + arvoresprocessadas);
            System.out.println("Quantidade de Movimentos: " + estadomenor.getCusto());
            System.out.println("Tempo de processamento " + (endTime - startTime) + " ms");
            System.out.println("---------------------------------------\n\n");
            return 0;
        }//from  www . j  av  a 2  s . c  o m
        arvoresprocessadas++;
        int[][] matrizatualx = estadomenor.getMatriz();
        if (x0 >= 0) {

            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x0][y];
            matriz[x0][y] = matrizatualx[x][y];

            String stringmatriz1 = transformaMatrizString(matriz);
            if (!(processados.containsKey(stringmatriz1))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz1);

                processados.put(stringmatriz1, estadonovo);

            }
        }
        if (x1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x1][y];
            matriz[x1][y] = matrizatualx[x][y];
            String stringmatriz2 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz2))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz2);

                processados.put(stringmatriz2, estadonovo);

            }
        }
        if (y0 >= 0) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y0];
            matriz[x][y0] = matrizatualx[x][y];
            String stringmatriz3 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz3))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz3);

                processados.put(stringmatriz3, estadonovo);

            }
        }
        if (y1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y1];
            matriz[x][y1] = matrizatualx[x][y];

            int custoateaqui = diferencaMatriz(matriz) + altura + 1;
            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz4);

                processados.put(stringmatriz4, estadonovo);

            }
        }
        open_list.remove(key, matrizatualx1);
    }
    return 0;

}

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

static Set<String> sanityCheckDatacenters(Cassandra.Client client, int desiredRf, boolean safetyDisabled)
        throws InvalidRequestException, TException {
    ensureTestKeyspaceExists(client);//from  www. j  a v a2  s  .  com
    Set<String> hosts = Sets.newHashSet();

    Multimap<String, String> dataCenterToRack = HashMultimap.create();
    List<TokenRange> ring = client.describe_ring(CassandraConstants.SIMPLE_RF_TEST_KEYSPACE);
    for (TokenRange tokenRange : ring) {
        for (EndpointDetails details : tokenRange.getEndpoint_details()) {
            dataCenterToRack.put(details.datacenter, details.rack);
            hosts.add(details.host);
        }
    }

    if (dataCenterToRack.size() == 1) {
        String dc = dataCenterToRack.keySet().iterator().next();
        String rack = dataCenterToRack.values().iterator().next();
        if (dc.equals(CassandraConstants.DEFAULT_DC) && rack.equals(CassandraConstants.DEFAULT_RACK)
                && desiredRf > 1) {
            // We don't allow greater than RF=1 because they didn't set up their network.
            logErrorOrThrow(
                    "The cassandra cluster is not set up to be datacenter and rack aware.  "
                            + "Please set this up before running with a replication factor higher than 1.",
                    safetyDisabled);

        }
        if (dataCenterToRack.values().size() < desiredRf && hosts.size() > desiredRf) {
            logErrorOrThrow("The cassandra cluster only has one DC, "
                    + "and is set up with less racks than the desired number of replicas, "
                    + "and there are more hosts than the replication factor. "
                    + "It is very likely that your rack configuration is incorrect and replicas would not be placed correctly for the failure tolerance you want.",
                    safetyDisabled);
        }
    }

    return dataCenterToRack.keySet();
}

From source file:org.sonar.server.qualityprofile.index.ActiveRuleIndex.java

private static Multimap<String, FacetValue> processAggregations(@Nullable Aggregations aggregations) {
    Multimap<String, FacetValue> stats = ArrayListMultimap.create();
    if (aggregations == null) {
        return stats;
    }//from  w w w  .ja v  a  2 s .c  om
    for (Aggregation aggregation : aggregations.asList()) {
        if (aggregation instanceof StringTerms) {
            for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
                FacetValue facetValue = new FacetValue(value.getKeyAsString(), value.getDocCount());
                stats.put(aggregation.getName(), facetValue);
            }
        } else if (aggregation instanceof InternalValueCount) {
            InternalValueCount count = (InternalValueCount) aggregation;
            FacetValue facetValue = new FacetValue(count.getName(), count.getValue());
            stats.put(count.getName(), facetValue);
        }
    }
    return stats;
}

From source file:com.streamsets.pipeline.lib.el.ELUtils.java

public static Multimap<String, Record> partitionBatchByExpression(ELEval elEvaluator, ELVars variables,
        String expression, Batch batch) {
    Multimap<String, Record> partitions = ArrayListMultimap.create();

    Iterator<Record> batchIterator = batch.getRecords();

    while (batchIterator.hasNext()) {
        Record record = batchIterator.next();
        RecordEL.setRecordInContext(variables, record);
        try {//ww  w .  j a va2s. c  o m
            String partitionName = elEvaluator.eval(variables, expression, String.class);
            LOG.debug("Expression '{}' is evaluated to '{}' : ", expression, partitionName);
            partitions.put(partitionName, record);
        } catch (ELEvalException e) {
            LOG.error("Failed to evaluate expression '{}' : ", expression, e.toString(), e);
        }
    }

    return partitions;
}

From source file:com.giaybac.traprange.MAIN.java

private static void extractTables(String[] args) {
    try {//from  w  w  w.j  a  v  a  2  s  .com
        List<Integer> pages = getPages(args);
        List<Integer> exceptPages = getExceptPages(args);
        List<Integer[]> exceptLines = getExceptLines(args);
        String in = getIn(args);
        String out = getOut(args);

        PDFTableExtractor extractor = (new PDFTableExtractor()).setSource(in);
        //page
        for (Integer page : pages) {
            extractor.addPage(page);
        }
        //except page
        for (Integer exceptPage : exceptPages) {
            extractor.exceptPage(exceptPage);
        }
        //except lines
        List<Integer> exceptLineIdxs = new ArrayList<>();
        Multimap<Integer, Integer> exceptLineInPages = LinkedListMultimap.create();
        for (Integer[] exceptLine : exceptLines) {
            if (exceptLine.length == 1) {
                exceptLineIdxs.add(exceptLine[0]);
            } else if (exceptLine.length == 2) {
                int lineIdx = exceptLine[0];
                int pageIdx = exceptLine[1];
                exceptLineInPages.put(pageIdx, lineIdx);
            }
        }
        if (!exceptLineIdxs.isEmpty()) {
            extractor.exceptLine(Ints.toArray(exceptLineIdxs));
        }
        if (!exceptLineInPages.isEmpty()) {
            for (int pageIdx : exceptLineInPages.keySet()) {
                extractor.exceptLine(pageIdx, Ints.toArray(exceptLineInPages.get(pageIdx)));
            }
        }
        //begin parsing pdf file
        List<Table> tables = extractor.extract();

        Writer writer = new OutputStreamWriter(new FileOutputStream(out), "UTF-8");
        try {
            for (Table table : tables) {
                writer.write("Page: " + (table.getPageIdx() + 1) + "\n");
                writer.write(table.toHtml());
            }
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        logger.error(null, e);
    }
}

From source file:com.android.tools.lint.checks.ViewTypeDetector.java

private static void addViewTags(Multimap<String, String> map, Element element) {
    String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
    if (id != null && !id.isEmpty()) {
        id = LintUtils.stripIdPrefix(id);
        if (!map.containsEntry(id, element.getTagName())) {
            map.put(id, element.getTagName());
        }// w  w w  .  j  ava  2  s .  com
    }

    NodeList children = element.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            addViewTags(map, (Element) child);
        }
    }
}

From source file:moa2014.MOAH22014.java

public static int principal(int[][] matrizatual) {
    long startTime = System.currentTimeMillis();
    Multimap<Integer, String> open_list = TreeMultimap.create();
    HashMap<String, Estado> processados = new HashMap();

    int difmatrizatual = diferencaMatriz(matrizatual);

    String stringmatriz = transformaMatrizString(matrizatual);
    open_list.put(difmatrizatual, stringmatriz);
    Estado estadoatual = new Estado(matrizatual, 0);
    processados.put(stringmatriz, estadoatual);

    int arvoresgeradas = 0;
    int arvoresprocessadas = 0;

    while (!open_list.isEmpty()) {
        Iterator iterator = open_list.keySet().iterator();

        Integer key = (Integer) iterator.next();
        String matrizatualx1 = open_list.asMap().get(key).iterator().next();
        Estado estadomenor = processados.get(matrizatualx1);
        int altura = estadomenor.getCusto();
        //LOCALIZA O ZERO
        int[] zerot = localizazero(estadomenor.getMatriz());
        int x = zerot[0];
        int y = zerot[1];
        int x0 = x - 1;
        int x1 = x + 1;
        int y0 = y - 1;
        int y1 = y + 1;
        int difmatrizatualx = diferencaMatriz(estadomenor.getMatriz());
        if (difmatrizatualx == 0) {
            long endTime = System.currentTimeMillis();
            System.out.println("---------------------------------------");
            System.out.println("Arvores Geradas: " + arvoresgeradas);
            System.out.println("Arvores Processadas: " + arvoresprocessadas);
            System.out.println("Quantidade de Movimentos: " + estadomenor.getCusto());
            System.out.println("Tempo de processamento " + (endTime - startTime) + " ms");
            System.out.println("---------------------------------------\n\n");
            return 0;
        }/*  w w  w.j  ava  2 s  .c o  m*/
        arvoresprocessadas++;
        int[][] matrizatualx = estadomenor.getMatriz();
        if (x0 >= 0) {

            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x0][y];
            matriz[x0][y] = matrizatualx[x][y];

            String stringmatriz1 = transformaMatrizString(matriz);
            if (!(processados.containsKey(stringmatriz1))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz1);

                processados.put(stringmatriz1, estadonovo);

            }
        }
        if (x1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x1][y];
            matriz[x1][y] = matrizatualx[x][y];
            String stringmatriz2 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz2))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz2);

                processados.put(stringmatriz2, estadonovo);

            }
        }
        if (y0 >= 0) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y0];
            matriz[x][y0] = matrizatualx[x][y];
            String stringmatriz3 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz3))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz3);

                processados.put(stringmatriz3, estadonovo);

            }
        }
        if (y1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y1];
            matriz[x][y1] = matrizatualx[x][y];

            int custoateaqui = diferencaMatriz(matriz) + altura + 1;
            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz4);

                processados.put(stringmatriz4, estadonovo);

            }
        }
        open_list.remove(key, matrizatualx1);
    }
    return 0;

}

From source file:com.google.idea.blaze.base.sync.projectstructure.ContentEntryEditor.java

private static Multimap<WorkspacePath, WorkspacePath> sortExcludesByRootDirectory(
        Collection<WorkspacePath> rootDirectories, Collection<WorkspacePath> excludedDirectories) {

    Multimap<WorkspacePath, WorkspacePath> result = ArrayListMultimap.create();
    for (WorkspacePath exclude : excludedDirectories) {
        WorkspacePath foundWorkspacePath = rootDirectories.stream()
                .filter(rootDirectory -> isUnderRootDirectory(rootDirectory, exclude.relativePath()))
                .findFirst().orElse(null);
        if (foundWorkspacePath != null) {
            result.put(foundWorkspacePath, exclude);
        }/*from w  w w  . j av a 2 s . c o  m*/
    }
    return result;
}