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

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

Introduction

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

Prototype

Map<K, Collection<V>> asMap();

Source Link

Document

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values.

Usage

From source file:org.apache.james.mailbox.store.mail.MessageIdMapper.java

default void delete(Multimap<MessageId, MailboxId> ids) {
    ids.asMap().forEach(this::delete);
}

From source file:com.opengamma.strata.loader.csv.CurveGroupDefinitionCsvLoader.java

/**
 * Builds a list of curve group definitions from the map of curves and their keys.
 * <p>//  w w w .  j a  v a 2  s .  co m
 * The keys specify which curve groups each curve belongs to and how it is used in the group, for example
 * as a discount curve for a particular currency or as a forward curve for an index.
 *
 * @param garMap  the map of name to keys
 * @return a map of curve group name to curve group definition built from the curves
 */
private static ImmutableList<CurveGroupDefinition> buildCurveGroups(
        Map<CurveName, Set<GroupAndReference>> garMap) {

    Multimap<CurveGroupName, CurveGroupEntry> groups = LinkedHashMultimap.create();

    for (Map.Entry<CurveName, Set<GroupAndReference>> entry : garMap.entrySet()) {
        CurveName curveName = entry.getKey();
        Set<GroupAndReference> curveIds = entry.getValue();
        Map<CurveGroupName, List<GroupAndReference>> idsByGroup = curveIds.stream()
                .collect(groupingBy(p -> p.groupName));

        for (Map.Entry<CurveGroupName, List<GroupAndReference>> groupEntry : idsByGroup.entrySet()) {
            CurveGroupName groupName = groupEntry.getKey();
            List<GroupAndReference> gars = groupEntry.getValue();
            groups.put(groupName, curveGroupEntry(curveName, gars));
        }
    }
    return MapStream.of(groups.asMap())
            .map((name, entry) -> CurveGroupDefinition.of(name, entry, ImmutableList.of()))
            .collect(toImmutableList());
}

From source file:kn.uni.gis.dataimport.Main.java

private static void insertData(SQLFacade sqlConnection, final String tableName, final List<String> readLines)
        throws SQLException {
    // Mapping from id -> multiple (parsed) lines
    Multimap<String, List<String>> index = Multimaps
            .index(Lists.transform(readLines, new Function<String, List<String>>() {
                @Override//from   w w w.jav  a2 s . c  o m
                public List<String> apply(String input) {
                    ArrayList<String> newArrayList = Lists
                            .newArrayList(Splitter.on("\t").trimResults().split(input));
                    newArrayList.remove(newArrayList.size() - 1);
                    return newArrayList;

                }

            }), new Function<List<String>, String>() {
                @Override
                public String apply(List<String> input) {
                    return input.get(ID_INDEX);
                }
            });

    // Collapse now to a mapping id -> one line
    Map<String, List<String>> collapsedValues = Maps.transformValues(index.asMap(),
            new Function<Collection<List<String>>, List<String>>() {

                @Override
                public List<String> apply(Collection<List<String>> input) {
                    List<String> toReturn = Lists.newArrayList();

                    // set id
                    List<String> firstLine = input.iterator().next();
                    toReturn.add(firstLine.get(0));

                    // set coordinates
                    StringBuilder stringBuilder = new StringBuilder();

                    for (List<String> ret : input) {
                        stringBuilder.append(ret.get(1));
                        stringBuilder.append(" ");
                        stringBuilder.append(ret.get(2));
                        stringBuilder.append(",");
                    }
                    String coords = stringBuilder.toString();

                    // add additional line data
                    for (int i = 5; i < firstLine.size(); i++) {
                        toReturn.add("'" + firstLine.get(i).replaceAll("'", "''") + "'");
                    }

                    // delete last ',' and add GeoInformation as last column
                    toReturn.add(GeoColumn.getGeoColumn(tableName)
                            .getGeoInsertionSQL(coords.substring(0, coords.lastIndexOf(','))));
                    return toReturn;
                }

            });

    List<String> toexecute = Lists.newArrayList();
    for (Map.Entry<String, List<String>> entry : collapsedValues.entrySet()) {
        toexecute.add(String.format("insert into \"%s\" values (%s);", tableName,
                Joiner.on(",").join(entry.getValue())));
    }
    sqlConnection.executeBatch(toexecute.toArray(new String[toexecute.size()]));

}

From source file:org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelOptUtil.java

/**
 * Given a RelNode, it checks whether there is any filtering condition
 * below. Basically we check whether the operators
 * below altered the PK cardinality in any way
 *//*from  w w  w.j  a v a  2  s  .co  m*/
public static boolean isRowFilteringPlan(final RelMetadataQuery mq, RelNode operator) {
    final Multimap<Class<? extends RelNode>, RelNode> nodesBelowNonFkInput = mq.getNodeTypes(operator);
    for (Entry<Class<? extends RelNode>, Collection<RelNode>> e : nodesBelowNonFkInput.asMap().entrySet()) {
        if (e.getKey() == TableScan.class) {
            if (e.getValue().size() > 1) {
                // Bail out as we may not have more than one TS on non-FK side
                return true;
            }
        } else if (e.getKey() == Project.class) {
            // We check there is no windowing expression
            for (RelNode node : e.getValue()) {
                Project p = (Project) node;
                for (RexNode expr : p.getChildExps()) {
                    if (expr instanceof RexOver) {
                        // Bail out as it may change cardinality
                        return true;
                    }
                }
            }
        } else if (e.getKey() == Aggregate.class) {
            // We check there is are not grouping sets
            for (RelNode node : e.getValue()) {
                Aggregate a = (Aggregate) node;
                if (a.getGroupType() != Group.SIMPLE) {
                    // Bail out as it may change cardinality
                    return true;
                }
            }
        } else if (e.getKey() == Sort.class) {
            // We check whether there is a limit clause
            for (RelNode node : e.getValue()) {
                Sort s = (Sort) node;
                if (s.fetch != null || s.offset != null) {
                    // Bail out as it may change cardinality
                    return true;
                }
            }
        } else {
            // Bail out, we cannot rewrite the expression if non-fk side cardinality
            // is being altered
            return true;
        }
    }
    // It passed all the tests
    return false;
}

From source file:com.continuuity.weave.internal.appmaster.RunnableContainerRequest.java

RunnableContainerRequest(WeaveSpecification.Order.Type orderType,
        Multimap<Resource, RuntimeSpecification> requests) {
    this.orderType = orderType;
    this.requests = requests.asMap().entrySet().iterator();
}

From source file:cc.kave.commons.utils.json.legacy.MultimapTypeAdapter.java

@Override
public JsonElement serialize(final Multimap src, final Type typeOfSrc, final JsonSerializationContext context) {
    return context.serialize(src.asMap(), createMapType(typeOfSrc));
}

From source file:org.apache.bigtop.itest.hbase.system.Scanner.java

public static int doScan(HTable table, int val) throws IOException, InterruptedException {
    Scan s = new Scan();
    byte[] start = {};
    byte[] stop = {};
    byte[] value = Bytes.toBytes(String.format("%010d", val));
    s.setStartRow(start);//w  ww  .  j a v  a2s.  c  om
    s.setStopRow(stop);
    SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("f1"), Bytes.toBytes("qual"),
            CompareOp.EQUAL, value);
    s.setFilter(filter);

    // Keep track of gathered elements.
    Multimap<String, String> mm = ArrayListMultimap.create();

    // Counts
    int cnt = 0;
    long i = 0;
    ResultScanner rs = table.getScanner(s);
    for (Result r : rs) {
        if (r.getRow() == null) {
            continue;
        }

        NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> columnFamilyMap = r.getMap();

        // Output time to show if flush related.
        String k = Bytes.toStringBinary(r.getRow());
        if (mm.get(k).size() >= 1) {
            System.out.println("Duplicate rowkey " + k);
            LOG.error("Duplicate rowkey " + k);
        }

        mm.put(Bytes.toStringBinary(r.getRow()), i + ": " + r);
        cnt++;
        i++;
    }

    System.out.println("scan items counted: " + cnt + " for scan " + s.toString() + " with filter f1:qual == "
            + Bytes.toString(value));

    // Print out dupes.
    int dupes = 0;
    for (Entry<String, Collection<String>> e : mm.asMap().entrySet()) {
        if (e.getValue().size() > 1) {
            dupes++;
            System.out.print("Row " + e.getKey() + " had time stamps: ");
            String[] tss = e.getValue().toArray(new String[0]);
            System.out.println(Arrays.toString(tss));
        }
    }

    return dupes;
}

From source file:at.ac.univie.isc.asio.junit.IsMultimapContaining.java

@Override
protected boolean matchesSafely(final Multimap<K, V> item) {
    for (Map.Entry<K, Collection<V>> entry : item.asMap().entrySet()) {
        if (keyMatcher.matches(entry.getKey()) && valueMatcher.matches(entry.getValue())) {
            return true;
        }/*  www. java 2 s . com*/
    }
    return false;
}

From source file:google.registry.tools.DomainCheckCommand.java

@Override
void initEppToolCommand() {
    Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters);
    for (Collection<String> values : domainNameMap.asMap().values()) {
        setSoyTemplate(DomainCheckSoyInfo.getInstance(), DomainCheckSoyInfo.DOMAINCHECK);
        addSoyRecord(clientId, new SoyMapData("domainNames", values));
    }/* w w  w.j  a va2s.com*/
}

From source file:google.registry.tools.DomainCheckClaimsCommand.java

@Override
void initEppToolCommand() {
    Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters);
    for (Collection<String> values : domainNameMap.asMap().values()) {
        setSoyTemplate(DomainCheckClaimsSoyInfo.getInstance(), DomainCheckClaimsSoyInfo.DOMAINCHECKCLAIMS);
        addSoyRecord(clientId, new SoyMapData("domainNames", values));
    }/* w  w w  .j  a v  a 2  s .c o m*/
}