Example usage for com.google.common.collect Maps toMap

List of usage examples for com.google.common.collect Maps toMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps toMap.

Prototype

public static <K, V> ImmutableMap<K, V> toMap(Iterator<K> keys, Function<? super K, V> valueFunction) 

Source Link

Document

Returns an immutable map whose keys are the distinct elements of keys and whose value for each key was computed by valueFunction .

Usage

From source file:com.googlecode.blaisemath.sketch.SketchActions.java

public static void alignVertical(Set<Graphic<Graphics2D>> selection) {
    Iterable<Graphic<Graphics2D>> sub = Iterables.filter(selection, MOVABLE_PREDICATE);
    if (Iterables.size(sub) < 2) {
        Logger.getLogger(SketchActions.class.getName()).log(Level.INFO,
                "Cannot align with fewer than 2 movable predicates.");
        return;/*  ww  w  .j  a va 2  s  .  co  m*/
    }
    ImmutableMap<Graphic<Graphics2D>, Point2D> locs = Maps.toMap(sub, LOC_FUNCTION);
    double xAvg = Points.average(locs.values()).getY();
    for (Graphic<Graphics2D> gr : sub) {
        setPrimitiveLocation((PrimitiveGraphicSupport<?, Graphics2D>) gr,
                new Point2D.Double(xAvg, locs.get(gr).getY()));
    }
}

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

@Override
public void dropTables(final Set<String> tablesToDrop) {
    String dropQuery = "DROP TABLE IF EXISTS %s"; // full table name (ks.cf)

    for (String tableName : tablesToDrop) {
        BoundStatement dropStatement = getPreparedStatement(tableName,
                String.format(dropQuery, getFullTableName(tableName)), longRunningQuerySession)
                        .setConsistencyLevel(ConsistencyLevel.ALL).bind();
        try {//from  w w w.j  a  v  a  2  s .c o m
            ResultSet resultSet = longRunningQuerySession.execute(dropStatement);
            CQLKeyValueServices.logTracedQuery(dropQuery, resultSet, session, cqlStatementCache.NORMAL_QUERY);
        } catch (com.datastax.driver.core.exceptions.UnavailableException e) {
            throw new InsufficientConsistencyException(
                    "Dropping tables requires all Cassandra nodes to be up and available.", e);
        }
    }

    CQLKeyValueServices.waitForSchemaVersionsToCoalesce("dropTables(" + tablesToDrop.size() + " tables)", this);

    put(CassandraConstants.METADATA_TABLE,
            Maps.toMap(Lists.transform(Lists.newArrayList(tablesToDrop), new Function<String, Cell>() {
                @Override
                public Cell apply(String tableName) {
                    return CQLKeyValueServices.getMetadataCell(tableName);
                }
            }), Functions.constant(PtBytes.EMPTY_BYTE_ARRAY)), System.currentTimeMillis());
}