Java Code Examples for com.google.common.collect.EnumBiMap#create()
The following examples show how to use
com.google.common.collect.EnumBiMap#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuavaEnumBiMapTest.java From java_in_examples with Apache License 2.0 | 5 votes |
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 }
Example 2
Source File: GuavaEnumBiMapTest.java From java_in_examples with Apache License 2.0 | 5 votes |
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 }
Example 3
Source File: BiMapGwtTest.java From gwt-jackson with Apache License 2.0 | 5 votes |
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 ) ); }
Example 4
Source File: BiMapGwtTest.java From gwt-jackson with Apache License 2.0 | 5 votes |
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 ); }
Example 5
Source File: EnumBiMapJsonDeserializer.java From gwt-jackson with Apache License 2.0 | 4 votes |
@Override protected EnumBiMap<K, V> newMap() { return EnumBiMap.create( enumKeyClass, enumValueClass ); }