Java 类com.google.common.collect.EnumBiMap 实例源码

项目:equalsverifier    文件:ReflectiveGuavaEnumBiMapFactoryTest.java   
@Before
public void setUp() {
    prefabValues.addFactory(Enum.class, TwoElementEnum.ONE, TwoElementEnum.TWO, TwoElementEnum.ONE);

    expectedRed = EnumBiMap.create(TwoElementEnum.class, TwoElementEnum.class);
    expectedRed.put(TwoElementEnum.ONE, TwoElementEnum.TWO);
    expectedBlack = EnumBiMap.create(TwoElementEnum.class, TwoElementEnum.class);
    expectedBlack.put(TwoElementEnum.TWO, TwoElementEnum.TWO);
}
项目:equalsverifier    文件:ReflectiveGuavaEnumBiMapFactoryTest.java   
@Test
public void createSpecificEnumSet() {
    TypeTag tag = new TypeTag(EnumBiMap.class, new TypeTag(TwoElementEnum.class), new TypeTag(TwoElementEnum.class));
    Tuple<?> tuple = factory.createValues(tag, prefabValues, emptyTypeStack);

    assertEquals(expectedRed, tuple.getRed());
    assertEquals(expectedBlack, tuple.getBlack());
}
项目:equalsverifier    文件:ReflectiveGuavaEnumBiMapFactoryTest.java   
@Test
public void createWildcardEnumSet() {
    TypeTag tag = new TypeTag(EnumBiMap.class, new TypeTag(Object.class), new TypeTag(Object.class));
    Tuple<?> tuple = factory.createValues(tag, prefabValues, emptyTypeStack);

    assertEquals(expectedRed, tuple.getRed());
    assertEquals(expectedBlack, tuple.getBlack());
}
项目:equalsverifier    文件:ReflectiveGuavaEnumBiMapFactoryTest.java   
@Test
public void createRawEnumSet() {
    TypeTag tag = new TypeTag(EnumBiMap.class);
    Tuple<?> tuple = factory.createValues(tag, prefabValues, emptyTypeStack);

    assertEquals(expectedRed, tuple.getRed());
    assertEquals(expectedBlack, tuple.getBlack());
}
项目:java_in_examples    文件:GuavaEnumBiMapTest.java   
public static void main(String[] args) {
    ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
    POLISH_WORD[] polishWords = POLISH_WORD.values();

    // Create Multiset
    BiMap<ENGLISH_WORD, POLISH_WORD> biMap = EnumBiMap.create(ENGLISH_WORD.class, POLISH_WORD.class);
    // Create English-Polish dictionary
    int i = 0;
    for(ENGLISH_WORD englishWord: englishWords) {
        biMap.put(englishWord, polishWords[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(POLISH_WORD.KULA));    // print kula = BALL
    System.out.println("snieg = " + biMap.inverse().get(POLISH_WORD.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

}
项目:java_in_examples    文件:GuavaEnumBiMapTest.java   
public static void main(String[] args) {
    ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
    POLISH_WORD[] polishWords = POLISH_WORD.values();

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

    // Выводим кол-вом вхождений слов
    System.out.println(biMap); // напечатает {ONE=JEDEN, 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(POLISH_WORD.KULA));    // напечатает kula = BALL
    System.out.println("snieg = " + biMap.inverse().get(POLISH_WORD.SNIEG));    // напечатает snieg = SNOW
    System.out.println("empty = " + biMap.get("empty"));    // напечатает empty = null

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

}
项目:gwt-jackson    文件:BiMapGwtTest.java   
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 ) );
}
项目:gwt-jackson    文件:BiMapGwtTest.java   
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 );
}
项目:gwt-jackson    文件:EnumBiMapJsonDeserializer.java   
@Override
protected EnumBiMap<K, V> newMap() {
    return EnumBiMap.create( enumKeyClass, enumValueClass );
}
项目:gwt-jackson    文件:GuavaConfiguration.java   
@Override
protected void configure() {
    type( Optional.class ).serializer( OptionalJsonSerializer.class ).deserializer( OptionalJsonDeserializer.class );
    type( FluentIterable.class ).serializer( IterableJsonSerializer.class );

    // Immutable Collections
    type( ImmutableCollection.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( ImmutableCollectionJsonDeserializer.class );
    type( ImmutableList.class ).serializer( CollectionJsonSerializer.class ).deserializer( ImmutableListJsonDeserializer.class );
    type( ImmutableSet.class ).serializer( CollectionJsonSerializer.class ).deserializer( ImmutableSetJsonDeserializer.class );
    type( ImmutableSortedSet.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( ImmutableSortedSetJsonDeserializer.class );

    // Immutable Map
    type( ImmutableMap.class ).serializer( MapJsonSerializer.class ).deserializer( ImmutableMapJsonDeserializer.class );
    type( ImmutableSortedMap.class ).serializer( MapJsonSerializer.class ).deserializer( ImmutableSortedMapJsonDeserializer.class );

    // BiMap
    type( BiMap.class ).serializer( MapJsonSerializer.class ).deserializer( BiMapJsonDeserializer.class );
    type( ImmutableBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( ImmutableBiMapJsonDeserializer.class );
    type( HashBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( HashBiMapJsonDeserializer.class );
    type( EnumBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( EnumBiMapJsonDeserializer.class );
    type( EnumHashBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( EnumHashBiMapJsonDeserializer.class );

    // Multiset
    type( Multiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( MultisetJsonDeserializer.class );
    type( HashMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( HashMultisetJsonDeserializer.class );
    type( LinkedHashMultiset.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( LinkedHashMultisetJsonDeserializer.class );
    type( SortedMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( SortedMultisetJsonDeserializer.class );
    type( TreeMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( TreeMultisetJsonDeserializer.class );
    type( ImmutableMultiset.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( ImmutableMultisetJsonDeserializer.class );
    type( EnumMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( EnumMultisetJsonDeserializer.class );

    // Multimap
    type( Multimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( MultimapJsonDeserializer.class );

    type( ImmutableMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( ImmutableMultimapJsonDeserializer.class );
    type( ImmutableSetMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( ImmutableSetMultimapJsonDeserializer.class );
    type( ImmutableListMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( ImmutableListMultimapJsonDeserializer.class );

    type( SetMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( SetMultimapJsonDeserializer.class );
    type( HashMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( HashMultimapJsonDeserializer.class );
    type( LinkedHashMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( LinkedHashMultimapJsonDeserializer.class );
    type( SortedSetMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( SortedSetMultimapJsonDeserializer.class );
    type( TreeMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( TreeMultimapJsonDeserializer.class );

    type( ListMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( ListMultimapJsonDeserializer.class );
    type( ArrayListMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( ArrayListMultimapJsonDeserializer.class );
    type( LinkedListMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( LinkedListMultimapJsonDeserializer.class );
}