当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableMap类代码示例

本文整理汇总了Java中com.google.common.collect.ImmutableMap的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMap类的具体用法?Java ImmutableMap怎么用?Java ImmutableMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ImmutableMap类属于com.google.common.collect包,在下文中一共展示了ImmutableMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: revertToFrozen

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
public static void revertToFrozen()
{
    if (!PersistentRegistry.FROZEN.isPopulated())
    {
        FMLLog.warning("Can't revert to frozen GameData state without freezing first.");
        return;
    }
    else
    {
        FMLLog.fine("Reverting to frozen data state.");
    }
    for (Map.Entry<ResourceLocation, FMLControlledNamespacedRegistry<?>> r : PersistentRegistry.ACTIVE.registries.entrySet())
    {
        final Class<? extends IForgeRegistryEntry> registrySuperType = PersistentRegistry.ACTIVE.getRegistrySuperType(r.getKey());
        loadRegistry(r.getKey(), PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE, registrySuperType);
    }
    // the id mapping has reverted, fire remap events for those that care about id changes
    Loader.instance().fireRemapEvent(ImmutableMap.<ResourceLocation, Integer[]>of(), ImmutableMap.<ResourceLocation, Integer[]>of(), true);

    // the id mapping has reverted, ensure we sync up the object holders
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    FMLLog.fine("Frozen state restored.");
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:24,代码来源:PersistentRegistryManager.java

示例2: shouldHandleEmptyInMergedMaps

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void shouldHandleEmptyInMergedMaps() throws Exception {

    final Observable<Integer> a = Observable.empty();

    final Observable<Integer> b = Observable.create(s -> {
        s.onNext(1);
        s.onNext(2);
        s.onNext(3);
        s.onComplete();
    });

    final ImmutableMap<String, Observable<Integer>> map = ImmutableMap.of(
        "a", a,
        "b", b
    );

    final Observable<ImmutableMap<String, Integer>> observableMap =
        MoreObservables.mergeMaps(map);

    final int error = observableMap
        .reduce(1, (x, y) -> 0)
        .blockingGet();

    assertEquals(0, error);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:27,代码来源:MoreObservablesTest.java

示例3: sendMagicLinkEmail

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
public void sendMagicLinkEmail(String loginIdentifier, String next) {
    AppUser user = userService.get(loginIdentifier);
    if (user == null) {
        Logger.error("Sending magic link failed. No such user %s", loginIdentifier);
        return; // fail silently so job doesn't get retry
    }

    String link = next == null
        ? createLinkForUser(user)
        : createLinkForUser(user, next);
    Map<String, Object> model = ImmutableMap.<String, Object>of(
        "magicLink", link);

    mailer.mail()
        .to(user.getEmail())
        .from(mailerSenderEmail)
        .subject("Your News Xtend X2 magic login link")
        .body(new HandlebarsView("user-login-email", model))
        .send();
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:21,代码来源:MagicLinkService.java

示例4: mergeMaps

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void mergeMaps() throws Exception {

    final Map<String, Observable<Integer>> o = ImmutableMap.of(
        "a", Observable.just(1),
        "b", Observable.just(1, 2, 3),
        "c", Observable.empty()
    );

    final ImmutableMap<String, Integer> expected = ImmutableMap.of(
        "a", 1,
        "b", 3
    );

    final ImmutableMap<String, Integer> actual = MoreObservables.mergeMaps(o)
        .lastElement()
        .blockingGet();

    assertEquals(expected , actual);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:21,代码来源:MoreObservablesTest.java

示例5: testShardDataTreeSnapshotWithMetadata

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void testShardDataTreeSnapshotWithMetadata() throws Exception {
    NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    Map<Class<? extends ShardDataTreeSnapshotMetadata<?>>, ShardDataTreeSnapshotMetadata<?>> expMetadata =
            ImmutableMap.of(TestShardDataTreeSnapshotMetadata.class, new TestShardDataTreeSnapshotMetadata("test"));
    MetadataShardDataTreeSnapshot snapshot = new MetadataShardDataTreeSnapshot(expectedNode, expMetadata);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
        snapshot.serialize(out);
    }

    ShardDataTreeSnapshot deserialized;
    try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
        deserialized = ShardDataTreeSnapshot.deserialize(in);
    }

    Optional<NormalizedNode<?, ?>> actualNode = deserialized.getRootNode();
    assertEquals("rootNode present", true, actualNode.isPresent());
    assertEquals("rootNode", expectedNode, actualNode.get());
    assertEquals("Deserialized type", MetadataShardDataTreeSnapshot.class, deserialized.getClass());
    assertEquals("Metadata", expMetadata, ((MetadataShardDataTreeSnapshot)deserialized).getMetadata());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:ShardDataTreeSnapshotTest.java

示例6: flatten

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
public static <K,V> ImmutableList<ImmutableMap<K, V>> flatten(ImmutableMultimap<K, V> src) {
	ImmutableList.Builder<ImmutableMap<K, V>> listBuilder=ImmutableList.builder();
	
	if (!src.isEmpty()) {
		ImmutableMap<K, Collection<V>> map = src.asMap();
		int entries=map.values().stream().reduce(1, (s,l) -> s*l.size(), (a,b) -> a*b);
		
		ImmutableList<Line<K,V>> lines = map.entrySet().stream()
				.map(e -> new Line<>(e.getKey(), e.getValue()))
				.collect(ImmutableList.toImmutableList());
		
		for (int i=0;i<entries;i++) {
			ImmutableMap.Builder<K, V> mapBuilder = ImmutableMap.builder();
			
			int fact=1;
			for (Line<K,V> line: lines) {
				mapBuilder.put(line.key, line.get((i/fact) % line.values.length));
				fact=fact*line.values.length;
			}
			
			listBuilder.add(mapBuilder.build());
		}
	}
	return listBuilder.build();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:26,代码来源:Multimaps.java

示例7: shouldConvertCurrency

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void shouldConvertCurrency() {

	ExchangeRatesContainer container = new ExchangeRatesContainer();
	container.setRates(ImmutableMap.of(
			Currency.EUR.name(), new BigDecimal("0.8"),
			Currency.RUB.name(), new BigDecimal("80")
	));

	when(client.getRates(Currency.getBase())).thenReturn(container);

	final BigDecimal amount = new BigDecimal(100);
	final BigDecimal expectedConvertionResult = new BigDecimal("1.25");

	BigDecimal result = ratesService.convert(Currency.RUB, Currency.USD, amount);

	assertTrue(expectedConvertionResult.compareTo(result) == 0);
}
 
开发者ID:sniperqpc,项目名称:Spring-cloud-gather,代码行数:19,代码来源:ExchangeRatesServiceImplTest.java

示例8: mapGraphValue

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Override
public Object mapGraphValue(@NonNull RefProperty schema,
    @NonNull GraphEntityContext graphEntityContext,
    @NonNull ValueContext valueContext,
    @NonNull SchemaMapperAdapter schemaMapperAdapter) {

  Model refModel = graphEntityContext.getSwaggerDefinitions().get(schema.getSimpleRef());

  if (refModel == null) {
    throw new SchemaMapperRuntimeException(String.format(
        "Unable to resolve reference to swagger model: '%s'.", schema.getSimpleRef()));
  }

  Builder<String, Object> builder = ImmutableMap.builder();
  refModel.getProperties().forEach((propKey, propValue) -> builder.put(propKey,
      Optional.fromNullable(schemaMapperAdapter.mapGraphValue(propValue, graphEntityContext,
          valueContext, schemaMapperAdapter))));

  return builder.build();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:21,代码来源:RefSchemaMapper.java

示例9: setUserQuota

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Override
public void setUserQuota(String userId, long maxObjects, long maxSizeKB) {
  HttpUrl.Builder urlBuilder =
      HttpUrl.parse(endpoint)
          .newBuilder()
          .addPathSegment("user")
          .query("quota")
          .addQueryParameter("uid", userId)
          .addQueryParameter("quota-type", "user");

  String body =
      gson.toJson(
          ImmutableMap.of(
              "max_objects", String.valueOf(maxObjects),
              "max_size_kb", String.valueOf(maxSizeKB),
              "enabled", "true"));

  Request request =
      new Request.Builder().put(RequestBody.create(null, body)).url(urlBuilder.build()).build();

  safeCall(request);
}
 
开发者ID:twonote,项目名称:radosgw-admin4j,代码行数:23,代码来源:RgwAdminImpl.java

示例10: Mapping

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, MetadataFieldMapper[] metadataMappers, SourceTransform[] sourceTransforms, ImmutableMap<String, Object> meta) {
    this.indexCreated = indexCreated;
    this.metadataMappers = metadataMappers;
    ImmutableMap.Builder<Class<? extends MetadataFieldMapper>, MetadataFieldMapper> builder = ImmutableMap.builder();
    for (MetadataFieldMapper metadataMapper : metadataMappers) {
        if (indexCreated.before(Version.V_2_0_0_beta1) && LEGACY_INCLUDE_IN_OBJECT.contains(metadataMapper.name())) {
            rootObjectMapper = rootObjectMapper.copyAndPutMapper(metadataMapper);
        }
        builder.put(metadataMapper.getClass(), metadataMapper);
    }
    this.root = rootObjectMapper;
    // keep root mappers sorted for consistent serialization
    Arrays.sort(metadataMappers, new Comparator<Mapper>() {
        @Override
        public int compare(Mapper o1, Mapper o2) {
            return o1.name().compareTo(o2.name());
        }
    });
    this.metadataMappersMap = builder.build();
    this.sourceTransforms = sourceTransforms;
    this.meta = meta;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:Mapping.java

示例11: shouldReturnRequiredCycle3AttributesWhenValuesExistInCycle3Assertion

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void shouldReturnRequiredCycle3AttributesWhenValuesExistInCycle3Assertion(){
    List<Attribute> accountCreationAttributes = Arrays.asList(CYCLE_3).stream()
            .map(attributeQueryAttributeFactory::createAttribute)
            .collect(toList());

    ImmutableMap<String, String> build = ImmutableMap.<String, String>builder().put("cycle3Key", "cycle3Value").build();
    Cycle3Dataset cycle3Dataset = Cycle3Dataset.createFromData(build);
    HubAssertion hubAssertion =new HubAssertion("1", "issuerId", DateTime.now(), new PersistentId("1"), null, Optional.of(cycle3Dataset));

    List<Attribute> userAttributesForAccountCreation = userAccountCreationAttributeExtractor.getUserAccountCreationAttributes(accountCreationAttributes, null, Optional.of(hubAssertion));

    List<Attribute> cycle_3 = userAttributesForAccountCreation.stream().filter(a -> a.getName().equals("cycle_3")).collect(toList());
    StringBasedMdsAttributeValue personName = (StringBasedMdsAttributeValue) cycle_3.get(0).getAttributeValues().get(0);

    assertThat(cycle_3.size()).isEqualTo(1);
    assertThat(personName.getValue().equals("cycle3Value"));
}
 
开发者ID:alphagov,项目名称:verify-matching-service-adapter,代码行数:19,代码来源:UserAccountCreationAttributeExtractorTest.java

示例12: map_ThrowsException_EndpointWithoutProduces

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void map_ThrowsException_EndpointWithoutProduces() throws IOException {
  // Arrange
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).path("/breweries",
      new Path().get(new Operation().vendorExtensions(
          ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
              DBEERPEDIA.BREWERIES.stringValue())).response(Status.OK.getStatusCode(),
                  new Response().schema(mock(Property.class)))));

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage(String.format("Path '%s' should produce at least one media type.",
      "/" + DBEERPEDIA.OPENAPI_HOST + "/breweries"));

  // Act
  requestMapper.map(httpConfigurationMock);
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:18,代码来源:OpenApiRequestMapperTest.java

示例13: filteredMapping

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
/** Tests situation when only a subset of classes are to be mapped. */
@Test
public void filteredMapping() {
  ImmutableList<String> lines =
      ImmutableList.of(
          "com.test.stuff,//java/com/test/stuff:target",
          "com.test.hello,//java/com/test/other:target");

  ImmutableMap<String, BuildRule> actual =
      (new UserDefinedResolver(lines)).resolve(ImmutableSet.of("com.test.stuff"));

  assertThat(actual)
      .containsExactly(
          "com.test.stuff", ExternalBuildRule.create("//java/com/test/stuff:target"));
  assertThat(actual).doesNotContainKey("com.test.hello");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:17,代码来源:UserDefinedResolverTest.java

示例14: testUserIdOnly

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void testUserIdOnly() throws IOException {
  String json = JSON_FACTORY.toString(ImmutableMap.of("localId", "user"));
  UserRecord userRecord = parseUser(json);
  assertEquals("user", userRecord.getUid());
  assertNull(userRecord.getEmail());
  assertNull(userRecord.getPhoneNumber());
  assertNull(userRecord.getPhotoUrl());
  assertNull(userRecord.getDisplayName());
  assertEquals(0L, userRecord.getUserMetadata().getCreationTimestamp());
  assertEquals(0L, userRecord.getUserMetadata().getLastSignInTimestamp());
  assertEquals(0, userRecord.getCustomClaims().size());
  assertFalse(userRecord.isDisabled());
  assertFalse(userRecord.isEmailVerified());
  assertEquals(0, userRecord.getProviderData().length);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:UserRecordTest.java

示例15: mapGraphValue_ReturnsResults_WhenRefCanBeResolved

import com.google.common.collect.ImmutableMap; //导入依赖的package包/类
@Test
public void mapGraphValue_ReturnsResults_WhenRefCanBeResolved() {
  // Arrange
  property.set$ref(DUMMY_REF);
  Model refModel = new ModelImpl();
  refModel.setProperties(ImmutableMap.of(KEY_1, PROPERTY_1, KEY_2, PROPERTY_2));

  when(entityBuilderContext.getLdPathExecutor()).thenReturn(ldPathExecutor);
  when(entityBuilderContext.getSwaggerDefinitions()).thenReturn(
      ImmutableMap.of(property.getSimpleRef(), refModel));
  when(ldPathExecutor.ldPathQuery(context, LD_PATH_QUERY)).thenReturn(ImmutableList.of(VALUE_2));

  // Act
  Map<String, Object> result =
      (Map<String, Object>) schemaMapper.mapGraphValue(property, entityBuilderContext,
          ValueContext.builder().value(context).build(), schemaMapperAdapter);

  // Assert
  assertThat(result.keySet(), hasSize(2));
  assertEquals(((Optional) result.get(KEY_1)).orNull(), VALUE_1.stringValue());
  assertEquals(((Optional) result.get(KEY_2)).orNull(), VALUE_2.intValue());
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:23,代码来源:RefSchemaMapperTest.java


注:本文中的com.google.common.collect.ImmutableMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。