com.google.common.collect.Maps#asMap ( )源码实例Demo

下面列出了com.google.common.collect.Maps#asMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sharding-jdbc-1.5.1   文件: YamlIntegratedTest.java
@Test
public void testWithDataSource() throws SQLException, URISyntaxException, IOException {
    File yamlFile = new File(YamlIntegratedTest.class.getResource(filePath).toURI());
    DataSource dataSource;
    if (hasDataSource) {
        dataSource = new YamlShardingDataSource(yamlFile);
    } else {
        dataSource = new YamlShardingDataSource(Maps.asMap(Sets.newHashSet("db0", "db1"), new Function<String, DataSource>() {
            @Override
            public DataSource apply(final String key) {
                return createDataSource(key);
            }
        }), yamlFile);
    }
    
    try (Connection conn = dataSource.getConnection();
         Statement stm = conn.createStatement()) {
        stm.executeQuery("SELECT * FROM t_order");
        stm.executeQuery("SELECT * FROM t_order_item");
        stm.executeQuery("SELECT * FROM config");
    }
}
 
/**
 * - see: http://code.google.com/p/guava-libraries/issues/detail?id=56
 */
@Test
public final void whenMapIsBackedBySetAndFunction_thenCorrect() {
    final Function<Integer, Integer> powerOfTwo = new Function<Integer, Integer>() {
        @Override
        public final Integer apply(final Integer input) {
            return (int) Math.pow(input, 2);
        }
    };
    final Set<Integer> lowNumbers = Sets.newHashSet(2, 3, 4);

    final Map<Integer, Integer> numberToPowerOfTwoMuttable = Maps.asMap(lowNumbers, powerOfTwo);
    final Map<Integer, Integer> numberToPowerOfTwoImuttable = Maps.toMap(lowNumbers, powerOfTwo);
    assertThat(numberToPowerOfTwoMuttable.get(2), equalTo(4));
    assertThat(numberToPowerOfTwoImuttable.get(2), equalTo(4));
}
 
源代码3 项目: calcite   文件: DruidSchema.java
@Override protected Map<String, Table> getTableMap() {
  if (!discoverTables) {
    return ImmutableMap.of();
  }

  if (tableMap == null) {
    final DruidConnectionImpl connection = new DruidConnectionImpl(url, coordinatorUrl);
    Set<String> tableNames = connection.tableNames();

    tableMap = Maps.asMap(
        ImmutableSet.copyOf(tableNames),
        CacheBuilder.newBuilder()
            .build(CacheLoader.from(name -> table(name, connection))));
  }

  return tableMap;
}
 
@Test
public void assertWithDataSource() throws Exception {
    File yamlFile = new File(YamlOrchestrationShardingWithMasterSlaveIntegrateTest.class.getResource(filePath).toURI());
    DataSource dataSource;
    if (hasDataSource) {
        dataSource = YamlOrchestrationShardingSphereDataSourceFactory.createDataSource(yamlFile);
    } else {
        Map<String, DataSource> dataSourceMap = Maps.asMap(Sets.newHashSet("db0_master", "db0_slave", "db1_master", "db1_slave"), AbstractYamlDataSourceTest::createDataSource);
        Map<String, DataSource> result = new HashMap<>();
        for (Entry<String, DataSource> each : dataSourceMap.entrySet()) {
            result.put(each.getKey(), each.getValue());
        }
        dataSource = YamlOrchestrationShardingSphereDataSourceFactory.createDataSource(result, yamlFile);
    }
    try (Connection connection = dataSource.getConnection();
         Statement statement = connection.createStatement()) {
        statement.execute(String.format("INSERT INTO t_order(user_id,status) values(%d, %s)", 10, "'insert'"));
        statement.executeQuery("SELECT * FROM t_order");
        statement.executeQuery("SELECT * FROM t_order_item");
        statement.executeQuery("SELECT * FROM config");
    }
    ((OrchestrationShardingSphereDataSource) dataSource).close();
}
 
源代码5 项目: Quicksql   文件: DruidSchema.java
@Override protected Map<String, Table> getTableMap() {
  if (!discoverTables) {
    return ImmutableMap.of();
  }

  if (tableMap == null) {
    final DruidConnectionImpl connection = new DruidConnectionImpl(url, coordinatorUrl);
    Set<String> tableNames = connection.tableNames();

    tableMap = Maps.asMap(
            ImmutableSet.copyOf(tableNames),
            CacheBuilder.newBuilder()
              .build(new CacheLoader<String, Table>() {
                @Override public Table load(@Nonnull String tableName) throws Exception {
                  final Map<String, SqlTypeName> fieldMap = new LinkedHashMap<>();
                  final Set<String> metricNameSet = new LinkedHashSet<>();
                  final Map<String, List<ComplexMetric>> complexMetrics = new HashMap<>();

                  connection.metadata(tableName, DruidTable.DEFAULT_TIMESTAMP_COLUMN,
                          null, fieldMap, metricNameSet, complexMetrics);

                  return DruidTable.create(DruidSchema.this, tableName, null,
                          fieldMap, metricNameSet, DruidTable.DEFAULT_TIMESTAMP_COLUMN,
                          complexMetrics);
                }
              }));
  }

  return tableMap;
}
 
源代码6 项目: nomulus   文件: ForeignKeyIndex.java
@Override
public Map<Key<ForeignKeyIndex<?>>, Optional<ForeignKeyIndex<?>>> loadAll(
    Iterable<? extends Key<ForeignKeyIndex<?>>> keys) {
  ImmutableSet<Key<ForeignKeyIndex<?>>> typedKeys = ImmutableSet.copyOf(keys);
  Map<Key<ForeignKeyIndex<?>>, ForeignKeyIndex<?>> existingFkis =
      tm().doTransactionless(() -> ofy().load().keys(typedKeys));
  // ofy() omits keys that don't have values in Datastore, so re-add them in
  // here with Optional.empty() values.
  return Maps.asMap(
      typedKeys,
      (Key<ForeignKeyIndex<?>> key) ->
          Optional.ofNullable(existingFkis.getOrDefault(key, null)));
}
 
源代码7 项目: calcite   文件: RedisSchema.java
@Override protected Map<String, Table> getTableMap() {
  JsonCustomTable[] jsonCustomTables = new JsonCustomTable[tables.size()];
  Set<String> tableNames = Arrays.stream(tables.toArray(jsonCustomTables))
      .map(e -> e.name).collect(Collectors.toSet());
  tableMap = Maps.asMap(
      ImmutableSet.copyOf(tableNames),
      CacheBuilder.newBuilder()
          .build(CacheLoader.from(this::table)));
  return tableMap;
}
 
源代码8 项目: codebuff   文件: Graphs.java
/**
 * Returns a map that is a live view of {@code graph}, with nodes as keys
 * and the set of incident edges as values.
 */


private static <N, E> Map<N, Set<E>> nodeToIncidentEdges(final Network<N, E> graph) {
  checkNotNull(graph, "graph");
  return Maps.asMap(
  graph.nodes(),
  new Function<N, Set<E>>() {
    @Override
    public Set<E> apply(N node) {
      return graph.incidentEdges(node);
    }
  });
}
 
源代码9 项目: codebuff   文件: Graphs.java
private static <N> Map<N, Set<N>> nodeToAdjacentNodes(final Graph<N> graph) {
  checkNotNull(graph, "graph");
  return Maps.asMap(
  graph.nodes(),
  new Function<N, Set<N>>() {
    @Override
    public Set<N> apply(N node) {
      return graph.adjacentNodes(node);
    }
  });
}
 
源代码10 项目: codebuff   文件: ImmutableNetwork.java
private static <N, E> NodeConnections<N, E> nodeConnectionsOf(Network<N, E> graph, N node) {
    if (graph.isDirected()) {
      Map<E, N> inEdgeMap = Maps.asMap(graph.inEdges(node), sourceNodeFn(graph));
      Map<E, N> outEdgeMap = Maps.asMap(graph.outEdges(node), targetNodeFn(graph));
      return graph.allowsParallelEdges()
? DirectedMultiNodeConnections.ofImmutable(inEdgeMap, outEdgeMap)
: DirectedNodeConnections.ofImmutable(inEdgeMap, outEdgeMap);
    }
else {
      Map<E, N> incidentEdgeMap = Maps.asMap(graph.incidentEdges(node), oppositeNodeFn(graph, node));
      return graph.allowsParallelEdges()
        ? UndirectedMultiNodeConnections.ofImmutable(incidentEdgeMap)
        : UndirectedNodeConnections.ofImmutable(incidentEdgeMap);
    }
  }
 
源代码11 项目: codebuff   文件: ImmutableNetwork.java
private static <N, E> NodeConnections<N, E> nodeConnectionsOf(Network<N, E> graph, N node) {
    if (graph.isDirected()) {
      Map<E, N> inEdgeMap = Maps.asMap(graph.inEdges(node), sourceNodeFn(graph));
      Map<E, N> outEdgeMap = Maps.asMap(graph.outEdges(node), targetNodeFn(graph));
      return graph.allowsParallelEdges()
      ? DirectedMultiNodeConnections.ofImmutable(inEdgeMap, outEdgeMap)
      : DirectedNodeConnections.ofImmutable(inEdgeMap, outEdgeMap);
    }
else {
      Map<E, N> incidentEdgeMap = Maps.asMap(graph.incidentEdges(node), oppositeNodeFn(graph, node));
      return graph.allowsParallelEdges()
        ? UndirectedMultiNodeConnections.ofImmutable(incidentEdgeMap)
        : UndirectedNodeConnections.ofImmutable(incidentEdgeMap);
    }
  }
 
源代码12 项目: codebuff   文件: Graphs.java
private static <N> Map<N, Set<N>> nodeToAdjacentNodes(final Graph<N> graph) {
  checkNotNull(graph, "graph");
  return Maps.asMap(
  graph.nodes(),
  new Function<N, Set<N>>() {
    @Override
    public Set<N> apply(N node) {
      return graph.adjacentNodes(node);
    }
  });
}
 
源代码13 项目: codebuff   文件: ImmutableNetwork.java
private static <N, E> NodeConnections<N, E> nodeConnectionsOf(Network<N, E> graph, N node) {
    if (graph.isDirected()) {
      Map<E, N> inEdgeMap = Maps.asMap(graph.inEdges(node), sourceNodeFn(graph));
      Map<E, N> outEdgeMap = Maps.asMap(graph.outEdges(node), targetNodeFn(graph));
      return graph.allowsParallelEdges()
      ? DirectedMultiNodeConnections.ofImmutable(inEdgeMap, outEdgeMap)
      : DirectedNodeConnections.ofImmutable(inEdgeMap, outEdgeMap);
    }
else {
      Map<E, N> incidentEdgeMap = Maps.asMap(graph.incidentEdges(node), oppositeNodeFn(graph, node));
      return graph.allowsParallelEdges()
        ? UndirectedMultiNodeConnections.ofImmutable(incidentEdgeMap)
        : UndirectedNodeConnections.ofImmutable(incidentEdgeMap);
    }
  }
 
源代码14 项目: codebuff   文件: Graphs.java
/**
 * Returns a map that is a live view of {@code graph}, with nodes as keys
 * and the set of incident edges as values.
 */
private static <N, E> Map<N, Set<E>> nodeToIncidentEdges(final Network<N, E> graph) {
  checkNotNull(graph, "graph");
  return Maps.asMap(graph.nodes(), new Function<N, Set<E>>() {
    @Override
    public Set<E> apply(N node) {
      return graph.incidentEdges(node);
    }
  });
}
 
源代码15 项目: codebuff   文件: Graphs.java
private static <N> Map<N, Set<N>> nodeToAdjacentNodes(final Graph<N> graph) {
  checkNotNull(graph, "graph");
  return Maps.asMap(
  graph.nodes(),
  new Function<N, Set<N>>() {
    @Override
    public Set<N> apply(N node) {
      return graph.adjacentNodes(node);
    }
  });
}
 
源代码16 项目: lttrs-android   文件: ThreadOverviewItem.java
@Override
public Map<String, Boolean> getMailboxIds() {
    return Maps.asMap(mailboxes, id -> true);
}
 
源代码17 项目: lttrs-android   文件: EmailWithKeywords.java
@Override
public Map<String, Boolean> getKeywords() {
    return Maps.asMap(keywords, keyword -> true);
}
 
源代码18 项目: ProjectAres   文件: TableView.java
@Override
public Map<R, V> column(C columnKey) {
    return Maps.asMap(Sets.filter(rowKeySet(), rowKey -> contains(rowKey, columnKey)),
                      rowKey -> map.get(rowKey).get(columnKey));
}
 
源代码19 项目: GomJabbar   文件: ConsulTargetsCacheTest.java
private ComposableFuture<Map<String, Set<String>>> createServicesMap() {
  final Map<String, Set<String>> services = Maps.asMap(Sets.newHashSet(EXCLUDED_SERVICE, INCLUDED_MODULE), __ -> Collections.emptySet());
  return ComposableFutures.fromValue(services);
}
 
源代码20 项目: docker-client   文件: ObjectMapperProvider.java
@Override
public void serialize(final ImmutableSet value, final JsonGenerator jgen,
                      final SerializerProvider provider) throws IOException {
  final Map map = (value == null) ? null : Maps.asMap(value, EMPTY_MAP);
  OBJECT_MAPPER.writeValue(jgen, map);
}