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


Java EnumHashBiMap.create方法代码示例

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


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

示例1: EnumLookup

import com.google.common.collect.EnumHashBiMap; //导入方法依赖的package包/类
/**
 * 
 */
private EnumLookup(final Class<K> enumClass, final int idx, final boolean caseSensitive) {
    this.caseSensitive = caseSensitive;
    final BiMap<K, V> biMap = EnumHashBiMap.create(checkNotNull(enumClass));
    
    for (final K k : enumClass.getEnumConstants()) {
        biMap.put(k, keyForValue(extractKeyValue(k, idx)));
    }
    
    this.delegate = Maps.unmodifiableBiMap(biMap);
    this.inverse = delegate.inverse();
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:15,代码来源:EnumLookup.java

示例2: main

import com.google.common.collect.EnumHashBiMap; //导入方法依赖的package包/类
public static void main(String[] args) {
    ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
    String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};

    // Create Multiset
    BiMap<ENGLISH_WORD, String> biMap = EnumHashBiMap.create(ENGLISH_WORD.class);
    // Create English-Polish dictionary
    int i = 0;
    for(ENGLISH_WORD englishWord: englishWords) {
        biMap.put(englishWord, russianWords[i]);
        i++;
    }

    // Print count words
    System.out.println(biMap); // print {ONE=jeden, TWO=dwa, THREE=trzy, BALL=kula, SNOW=snieg}
    // Print all unique words
    System.out.println(biMap.keySet());    // print [ONE, TWO, THREE, BALL, SNOW]
    System.out.println(biMap.values());    // print [jeden, dwa, trzy, kula, snieg]

    // Print translate by words
    System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE));    // print one = jeden
    System.out.println("two = " + biMap.get(ENGLISH_WORD.TWO));    // print two = dwa
    System.out.println("kula = " + biMap.inverse().get("kula"));    // print kula = BALL
    System.out.println("snieg = " + biMap.inverse().get("snieg"));    // print snieg = SNOW
    System.out.println("empty = " + biMap.get("empty"));    // print empty = null

    // Print count word's pair
    System.out.println(biMap.size());    //print 5

}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:31,代码来源:GuavaEnumHashBiMapTest.java

示例3: main

import com.google.common.collect.EnumHashBiMap; //导入方法依赖的package包/类
public static void main(String[] args) {
    ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
    String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};

    // Создаем Multiset
    BiMap<ENGLISH_WORD, String> biMap = EnumHashBiMap.create(ENGLISH_WORD.class);
    // создаем англо-польский словарь
    int i = 0;
    for(ENGLISH_WORD englishWord: englishWords) {
        biMap.put(englishWord, russianWords[i]);
        i++;
    }

    // Выводим кол-вом вхождений слов
    System.out.println(biMap); // напечатает {ONE=один, TWO=dwa, THREE=trzy, BALL=kula, SNOW=snieg}
    // Выводим все уникальные слова
    System.out.println(biMap.keySet());    // напечатает [ONE, TWO, THREE, BALL, SNOW]
    System.out.println(biMap.values());    // напечатает [jeden, dwa, trzy, kula, snieg]

    // Выводим перевод по каждому слову
    System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE));    // напечатает one = jeden
    System.out.println("two = " + biMap.get(ENGLISH_WORD.TWO));    // напечатает two = dwa
    System.out.println("kula = " + biMap.inverse().get("kula"));    // напечатает kula = BALL
    System.out.println("snieg = " + biMap.inverse().get("snieg"));    // напечатает snieg = SNOW
    System.out.println("empty = " + biMap.get("empty"));    // напечатает empty = null

    // Выводим общее количество переводов в словаре
    System.out.println(biMap.size());    //напечатает 5

}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:31,代码来源:GuavaEnumHashBiMapTest.java

示例4: testSerialization

import com.google.common.collect.EnumHashBiMap; //导入方法依赖的package包/类
public void testSerialization() {
    BeanWithBiMapTypes bean = new BeanWithBiMapTypes();

    bean.hashBiMap = HashBiMap.create();
    // only one value since it is not sorted
    bean.hashBiMap.put( "one", 1 );

    bean.biMap = bean.hashBiMap;

    bean.enumHashBiMap = EnumHashBiMap.create( AlphaEnum.class );
    bean.enumHashBiMap.put( AlphaEnum.A, 1 );
    bean.enumHashBiMap.put( AlphaEnum.D, 4 );
    bean.enumHashBiMap.put( AlphaEnum.C, 3 );
    bean.enumHashBiMap.put( AlphaEnum.B, 2 );

    bean.enumBiMap = EnumBiMap.create( AlphaEnum.class, NumericEnum.class );
    bean.enumBiMap.put( AlphaEnum.A, NumericEnum.ONE );
    bean.enumBiMap.put( AlphaEnum.D, NumericEnum.FOUR );
    bean.enumBiMap.put( AlphaEnum.C, NumericEnum.THREE );
    bean.enumBiMap.put( AlphaEnum.B, NumericEnum.TWO );

    String expected = "{" +
            "\"biMap\":{\"one\":1}," +
            "\"hashBiMap\":{\"one\":1}," +
            "\"enumHashBiMap\":{\"A\":1,\"B\":2,\"C\":3,\"D\":4}," +
            "\"enumBiMap\":{\"A\":\"ONE\",\"B\":\"TWO\",\"C\":\"THREE\",\"D\":\"FOUR\"}" +
            "}";

    assertEquals( expected, BeanWithBiMapTypesMapper.INSTANCE.write( bean ) );
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:31,代码来源:BiMapGwtTest.java

示例5: testDeserialization

import com.google.common.collect.EnumHashBiMap; //导入方法依赖的package包/类
public void testDeserialization() {
    String input = "{" +
            "\"biMap\":{\"one\":1,\"two\":2,\"three\":3,\"four\":4}," +
            "\"hashBiMap\":{\"one\":1,\"two\":2,\"three\":3,\"four\":4}," +
            "\"enumHashBiMap\":{\"A\":1,\"B\":2,\"C\":3,\"D\":4}," +
            "\"enumBiMap\":{\"A\":\"ONE\",\"B\":\"TWO\",\"C\":\"THREE\",\"D\":\"FOUR\"}" +
            "}";

    BeanWithBiMapTypes result = BeanWithBiMapTypesMapper.INSTANCE.read( input );
    assertNotNull( result );

    HashBiMap<String, Integer> expectedHashBiMap = HashBiMap.create();
    expectedHashBiMap.put( "one", 1 );
    expectedHashBiMap.put( "two", 2 );
    expectedHashBiMap.put( "three", 3 );
    expectedHashBiMap.put( "four", 4 );

    assertNotNull( result.biMap );
    assertEquals( expectedHashBiMap, result.biMap );
    assertEquals( expectedHashBiMap, result.hashBiMap );

    EnumHashBiMap<AlphaEnum, Integer> expectedEnumHashBiMap = EnumHashBiMap.create( AlphaEnum.class );
    expectedEnumHashBiMap.put( AlphaEnum.A, 1 );
    expectedEnumHashBiMap.put( AlphaEnum.D, 4 );
    expectedEnumHashBiMap.put( AlphaEnum.C, 3 );
    expectedEnumHashBiMap.put( AlphaEnum.B, 2 );
    assertEquals( expectedEnumHashBiMap, result.enumHashBiMap );

    EnumBiMap<AlphaEnum, NumericEnum> expectedEnumBiMap = EnumBiMap.create( AlphaEnum.class, NumericEnum.class );
    expectedEnumBiMap.put( AlphaEnum.A, NumericEnum.ONE );
    expectedEnumBiMap.put( AlphaEnum.D, NumericEnum.FOUR );
    expectedEnumBiMap.put( AlphaEnum.C, NumericEnum.THREE );
    expectedEnumBiMap.put( AlphaEnum.B, NumericEnum.TWO );
    assertEquals( expectedEnumBiMap, result.enumBiMap );
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:36,代码来源:BiMapGwtTest.java

示例6: newMap

import com.google.common.collect.EnumHashBiMap; //导入方法依赖的package包/类
@Override
protected EnumHashBiMap<E, V> newMap() {
    return EnumHashBiMap.create( enumClass );
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:5,代码来源:EnumHashBiMapJsonDeserializer.java


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