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


Java Builder类代码示例

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


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

示例1: testBuilderPutAll

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutAll() {
  Map<String, Integer> toPut = new LinkedHashMap<String, Integer>();
  toPut.put("one", 1);
  toPut.put("two", 2);
  toPut.put("three", 3);
  Map<String, Integer> moreToPut = new LinkedHashMap<String, Integer>();
  moreToPut.put("four", 4);
  moreToPut.put("five", 5);

  ImmutableBiMap<String, Integer> map = new Builder<String, Integer>()
      .putAll(toPut)
      .putAll(moreToPut)
      .build();
  assertMapEquals(map,
      "one", 1, "two", 2, "three", 3, "four", 4, "five", 5);
  assertMapEquals(map.inverse(),
      1, "one", 2, "two", 3, "three", 4, "four", 5, "five");
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:ImmutableBiMapTest.java

示例2: testBuilderReuse

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderReuse() {
  Builder<String, Integer> builder = new Builder<String, Integer>();
  ImmutableBiMap<String, Integer> mapOne = builder
      .put("one", 1)
      .put("two", 2)
      .build();
  ImmutableBiMap<String, Integer> mapTwo = builder
      .put("three", 3)
      .put("four", 4)
      .build();

  assertMapEquals(mapOne, "one", 1, "two", 2);
  assertMapEquals(mapOne.inverse(), 1, "one", 2, "two");
  assertMapEquals(mapTwo, "one", 1, "two", 2, "three", 3, "four", 4);
  assertMapEquals(mapTwo.inverse(),
      1, "one", 2, "two", 3, "three", 4, "four");
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:ImmutableBiMapTest.java

示例3: testDuplicateValues

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testDuplicateValues() {
  ImmutableMap<String, Integer> map
      = new ImmutableMap.Builder<String, Integer>()
          .put("one", 1)
          .put("two", 2)
          .put("uno", 1)
          .put("dos", 2)
          .build();

  try {
    ImmutableBiMap.copyOf(map);
    fail();
  } catch (IllegalArgumentException expected) {
    assertThat(expected.getMessage()).contains("1");
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:ImmutableBiMapTest.java

示例4: resolveShardForPath

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
Long resolveShardForPath(final YangInstanceIdentifier path) {
    final String shardName = actorContext.getShardStrategyFactory().getStrategy(path).findShard(path);
    Long cookie = shards.get(shardName);
    if (cookie == null) {
        synchronized (this) {
            cookie = shards.get(shardName);
            if (cookie == null) {
                cookie = nextShard++;

                Builder<String, Long> builder = ImmutableBiMap.builder();
                builder.putAll(shards);
                builder.put(shardName, cookie);
                shards = builder.build();
            }
        }
    }

    return cookie;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:ModuleShardBackendResolver.java

示例5: testDuplicateValues

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testDuplicateValues() {
  ImmutableMap<String, Integer> map
      = new ImmutableMap.Builder<String, Integer>()
          .put("one", 1)
          .put("two", 2)
          .put("uno", 1)
          .put("dos", 2)
          .build();

  try {
    ImmutableBiMap.copyOf(map);
    fail();
  } catch (IllegalArgumentException expected) {
    assertTrue(expected.getMessage().contains("1"));
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:17,代码来源:ImmutableBiMapTest.java

示例6: testDuplicateValues

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testDuplicateValues() {
  ImmutableMap<String, Integer> map =
      new ImmutableMap.Builder<String, Integer>()
          .put("one", 1)
          .put("two", 2)
          .put("uno", 1)
          .put("dos", 2)
          .build();

  try {
    ImmutableBiMap.copyOf(map);
    fail();
  } catch (IllegalArgumentException expected) {
    assertThat(expected.getMessage()).contains("1");
  }
}
 
开发者ID:google,项目名称:guava,代码行数:17,代码来源:ImmutableBiMapTest.java

示例7: create

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
/**
 * Create a prefix {@link Converter} for {@link XPathExpressionException} defined in a particular YANG
 * {@link Module} .Instantiation requires establishing how a module's imports are mapped to actual modules
 * and their namespaces. This information is cached and used for improved lookups.
 *
 * @param ctx A SchemaContext
 * @param module Module in which the XPath is defined
 * @return A new Converter
 */
public static @Nonnull Converter<String, QNameModule> create(final SchemaContext ctx, final Module module) {
    // Always check for null ctx
    requireNonNull(ctx, "Schema context may not be null");

    // Use immutable map builder for detection of duplicates (which should never occur)
    final Builder<String, QNameModule> b = ImmutableBiMap.builder();
    b.put(module.getPrefix(), module.getQNameModule());

    for (ModuleImport i : module.getImports()) {
        final Optional<Module> mod = ctx.findModule(i.getModuleName(), i.getRevision());
        checkArgument(mod.isPresent(), "Unsatisfied import of %s by module %s", i, module);

        b.put(i.getPrefix(), mod.get().getQNameModule());
    }

    return Maps.asConverter(b.build());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:27,代码来源:PrefixConverters.java

示例8: testEmptyBuilder

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testEmptyBuilder() {
  ImmutableBiMap<String, Integer> map
      = new Builder<String, Integer>().build();
  assertEquals(Collections.<String, Integer>emptyMap(), map);
  assertEquals(Collections.<Integer, String>emptyMap(), map.inverse());
  assertSame(ImmutableBiMap.of(), map);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:ImmutableBiMapTest.java

示例9: testSingletonBuilder

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testSingletonBuilder() {
  ImmutableBiMap<String, Integer> map = new Builder<String, Integer>()
      .put("one", 1)
      .build();
  assertMapEquals(map, "one", 1);
  assertMapEquals(map.inverse(), 1, "one");
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:ImmutableBiMapTest.java

示例10: testBuilder_orderEntriesByValueAfterExactSizeBuild

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilder_orderEntriesByValueAfterExactSizeBuild() {
  ImmutableBiMap.Builder<String, Integer> builder =
      new ImmutableBiMap.Builder<String, Integer>(2).put("four", 4).put("one", 1);
  ImmutableMap<String, Integer> keyOrdered = builder.build();
  ImmutableMap<String, Integer> valueOrdered =
      builder.orderEntriesByValue(Ordering.natural()).build();
  assertMapEquals(keyOrdered, "four", 4, "one", 1);
  assertMapEquals(valueOrdered, "one", 1, "four", 4);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:ImmutableBiMapTest.java

示例11: testBuilder_orderEntriesByValue_usedTwiceFails

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilder_orderEntriesByValue_usedTwiceFails() {
  ImmutableBiMap.Builder<String, Integer> builder = new Builder<String, Integer>()
      .orderEntriesByValue(Ordering.natural());
  try {
    builder.orderEntriesByValue(Ordering.natural());
    fail("Expected IllegalStateException");
  } catch (IllegalStateException expected) {}
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:ImmutableBiMapTest.java

示例12: testBuilderPutNullKey

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullKey() {
  Builder<String, Integer> builder = new Builder<String, Integer>();
  try {
    builder.put(null, 1);
    fail();
  } catch (NullPointerException expected) {
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:ImmutableBiMapTest.java

示例13: testBuilderPutNullValue

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullValue() {
  Builder<String, Integer> builder = new Builder<String, Integer>();
  try {
    builder.put("one", null);
    fail();
  } catch (NullPointerException expected) {
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:ImmutableBiMapTest.java

示例14: testBuilderPutNullKeyViaPutAll

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullKeyViaPutAll() {
  Builder<String, Integer> builder = new Builder<String, Integer>();
  try {
    builder.putAll(Collections.<String, Integer>singletonMap(null, 1));
    fail();
  } catch (NullPointerException expected) {
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:ImmutableBiMapTest.java

示例15: testBuilderPutNullValueViaPutAll

import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullValueViaPutAll() {
  Builder<String, Integer> builder = new Builder<String, Integer>();
  try {
    builder.putAll(Collections.<String, Integer>singletonMap("one", null));
    fail();
  } catch (NullPointerException expected) {
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:ImmutableBiMapTest.java


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