com.google.common.collect.ImmutableMap.of()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(2733)

本文整理了Java中com.google.common.collect.ImmutableMap.of()方法的一些代码示例,展示了ImmutableMap.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImmutableMap.of()方法的具体详情如下:
包路径:com.google.common.collect.ImmutableMap
类名称:ImmutableMap
方法名:of

ImmutableMap.of介绍

[英]Returns the empty map. This map behaves and performs comparably to Collections#emptyMap, and is preferable mainly for consistency and maintainability of your code.
[中]返回空映射。此映射的行为和性能与集合#emptyMap相当,主要是为了代码的一致性和可维护性。

代码示例

代码示例来源:origin: google/guava

public void testGetAllPresent() throws ExecutionException {
 when(mock.getAllPresent(ImmutableList.of("key")))
   .thenReturn(ImmutableMap.of("key", Boolean.TRUE));
 assertEquals(
   ImmutableMap.of("key", Boolean.TRUE), forward.getAllPresent(ImmutableList.of("key")));
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testSelectCount() throws Exception
{
 final ResultSet resultSet = client.createStatement().executeQuery("SELECT COUNT(*) AS cnt FROM druid.foo");
 final List<Map<String, Object>> rows = getRows(resultSet);
 Assert.assertEquals(
   ImmutableList.of(
     ImmutableMap.of("cnt", 6L)
   ),
   rows
 );
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testExceptionalHandle()
{
 final Response response = abstractListenerHandler.handleGET(error_id);
 Assert.assertEquals(500, response.getStatus());
 Assert.assertEquals(ImmutableMap.of("error", error_message), response.getEntity());
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void workerHeartbeatUpdatesRemovedBlocks() throws Exception {
 // Create a worker.
 long worker = mBlockMaster.getWorkerId(NET_ADDRESS_1);
 mBlockMaster.workerRegister(worker, Arrays.asList("MEM"), ImmutableMap.of("MEM", 100L),
   ImmutableMap.of("MEM", 0L), NO_BLOCKS_ON_TIERS,
   RegisterWorkerPOptions.getDefaultInstance());
 long blockId = 1L;
 mBlockMaster.commitBlock(worker, 50L, "MEM", blockId, 20L);
 // Indicate that blockId is removed on the worker.
 mBlockMaster.workerHeartbeat(worker, null, ImmutableMap.of("MEM", 0L),
   ImmutableList.of(blockId), NO_BLOCKS_ON_TIERS, mMetrics);
 assertTrue(mBlockMaster.getBlockInfo(blockId).getLocations().isEmpty());
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testReplaces()
{
 Assert.assertFalse(factory.replaces(factory));
 Assert.assertFalse(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY, VALUE), true)));
 Assert.assertTrue(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY, VALUE), false)));
 Assert.assertTrue(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY + "1", VALUE), true)));
 Assert.assertTrue(factory.replaces(new MapLookupExtractorFactory(ImmutableMap.of(KEY, VALUE + "1"), true)));
 Assert.assertTrue(factory.replaces(null));
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void getDefaultValues() {
 Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
  PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(),
  PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null),
  ImmutableMap.of()) {
 };
 assertThat(config.get("multiA")).hasValue("foo,bar");
 assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar");
 assertThat(config.get("single")).hasValue("default");
 assertThat(config.getStringArray("single")).containsExactly("default");
}

代码示例来源:origin: prestodb/presto

@Test
public void testBuildQueryOr()
{
  TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(
      COL1, Domain.create(ValueSet.ofRanges(lessThan(BIGINT, 100L), greaterThan(BIGINT, 200L)), false)));
  Document query = MongoSession.buildQuery(tupleDomain);
  Document expected = new Document("$or", asList(
      new Document(COL1.getName(), new Document("$lt", 100L)),
      new Document(COL1.getName(), new Document("$gt", 200L))));
  assertEquals(query, expected);
}

代码示例来源:origin: apache/incubator-druid

@Test
 public void testSelectorWithLookupExtractionFn()
 {
  final Map<String, String> stringMap = ImmutableMap.of(
    "a", "7"
  );
  LookupExtractor mapExtractor = new MapLookupExtractor(stringMap, false);
  LookupExtractionFn lookupFn = new LookupExtractionFn(mapExtractor, true, null, false, true);

  assertFilterMatches(new ColumnComparisonDimFilter(ImmutableList.of(
    new ExtractionDimensionSpec("dim0", "dim0", lookupFn),
    new ExtractionDimensionSpec("dim1", "dim1", lookupFn)
  )), ImmutableList.of("2", "5", "7", "8"));
 }
}

代码示例来源:origin: prestodb/presto

@Test
public void ruleAddedTableLayoutToTableScan()
{
  tester().assertThat(pickTableLayout.pickTableLayoutWithoutPredicate())
      .on(p -> p.tableScan(
          nationTableHandle,
          ImmutableList.of(p.symbol("nationkey", BIGINT)),
          ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT))))
      .matches(
          constrainedTableScanWithTableLayout("nation", ImmutableMap.of(), ImmutableMap.of("nationkey", "nationkey")));
}

代码示例来源:origin: prestodb/presto

@Test
public void testTableScan()
{
  assertMinimallyOptimizedPlan("SELECT orderkey FROM lineitem",
      output(ImmutableList.of("ORDERKEY"),
          tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey"))));
}

代码示例来源:origin: prestodb/presto

@Test
public void testExtractFixedValuesFromAll()
{
  assertEquals(TupleDomain.extractFixedValues(TupleDomain.all()).get(), ImmutableMap.of());
}

代码示例来源:origin: prestodb/presto

@Test
public void testCreateSchema()
{
  assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default"));
  metadata.createSchema(SESSION, "test", ImmutableMap.of());
  assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default", "test"));
}

代码示例来源:origin: prestodb/presto

@Test
public void testSemiJoinNotNeeded()
{
  tester().assertThat(new PruneSemiJoinColumns())
      .on(p -> buildProjectedSemiJoin(p, symbol -> symbol.getName().equals("leftValue")))
      .matches(
          strictProject(
              ImmutableMap.of("leftValue", expression("leftValue")),
              values("leftKey", "leftKeyHash", "leftValue")));
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testSelectCountAlternateStyle() throws Exception
{
 final ResultSet resultSet = client.prepareStatement("SELECT COUNT(*) AS cnt FROM druid.foo").executeQuery();
 final List<Map<String, Object>> rows = getRows(resultSet);
 Assert.assertEquals(
   ImmutableList.of(
     ImmutableMap.of("cnt", 6L)
   ),
   rows
 );
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testGetDatasourceNonFullWithInterval()
{
 Map<String, Object> actual = resource.getDatasource(dataSource, "1975/2015", null);
 Map<String, Object> expected = ImmutableMap.of(
   KEY_DIMENSIONS, ImmutableSet.of("d1", "d2"),
   KEY_METRICS, ImmutableSet.of("m1", "m2")
 );
 EasyMock.verify(serverInventoryView);
 Assert.assertEquals(expected, actual);
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testRowSignature()
{
 final DimFilterHavingSpec havingSpec = new DimFilterHavingSpec(new SelectorDimFilter("foo", "1", null), null);
 havingSpec.setRowSignature(ImmutableMap.of("foo", ValueType.LONG));
 Assert.assertTrue(havingSpec.eval(new MapBasedRow(0, ImmutableMap.of("foo", 1L))));
 Assert.assertFalse(havingSpec.eval(new MapBasedRow(0, ImmutableMap.of("foo", 2L))));
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testQueryMaxTimeout()
{
 exception.expect(IAE.class);
 exception.expectMessage("configured [timeout = 1000] is more than enforced limit of maxQueryTimeout [100].");
 Query<?> query = new TestQuery(
   new TableDataSource("test"),
   new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("0/100"))),
   false,
   ImmutableMap.of(QueryContexts.TIMEOUT_KEY, 1000)
 );
 QueryContexts.verifyMaxQueryTimeout(query, 100);
}

代码示例来源:origin: prestodb/presto

@Test
public void doesNotFireIfTableScanHasTableLayout()
{
  tester().assertThat(pickTableLayout.pickTableLayoutWithoutPredicate())
      .on(p -> p.tableScan(
          nationTableHandle,
          ImmutableList.of(p.symbol("nationkey", BIGINT)),
          ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)),
          Optional.of(nationTableLayoutHandle)))
      .doesNotFire();
}

代码示例来源:origin: prestodb/presto

@Test(expectedExceptions = {IllegalStateException.class}, expectedExceptionsMessageRegExp = "missing expression for alias .*")
  public void testProjectLimitsScope()
  {
    assertMinimallyOptimizedPlan("SELECT 1 + orderkey FROM lineitem",
        output(ImmutableList.of("ORDERKEY"),
            project(ImmutableMap.of("EXPRESSION", expression("CAST(1 AS bigint) + ORDERKEY")),
                tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")))));
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testEmptySingleValuesMapToDomain()
{
  assertEquals(TupleDomain.fromFixedValues(ImmutableMap.of()), TupleDomain.all());
}

相关文章