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

项目:StudyGuide    文件:CourseDetailController.java   
/**
 * Initializes the panel's properties. They are bound in {@link #setCourse(Course)}.
 */
@FXML
private void initialize() {
    course = new SimpleObjectProperty<>();
    creditsValueProperty = new CreditsStringProperty();
    enrollableInComboBox.getItems().addAll(EnrollableIn.values());
    enrollableInComboBox.setConverter(new StringConverter<EnrollableIn>() {

        private final BiMap<EnrollableIn, String> valueMap = EnumHashBiMap.create(EnrollableIn.class);

        @Override
        public String toString(EnrollableIn object) {
            return valueMap.get(object);
        }

        @Override
        public EnrollableIn fromString(String string) {
            return valueMap.inverse().get(string);
        }

        {
            valueMap.put(EnrollableIn.BOTH, EnrollableIn.BOTH.print(messages));
            valueMap.put(EnrollableIn.SUMMER, EnrollableIn.SUMMER.print(messages));
            valueMap.put(EnrollableIn.WINTER, EnrollableIn.WINTER.print(messages));
        }
    });
    teacherNamesProperty = new StringListStringProperty();
    prerequisitesProperty = new CourseListStringProperty();
    corequisitesProperty = new CourseListStringProperty();
}
项目:benayn    文件:EnumLookup.java   
/**
 * 
 */
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();
}
项目:java_in_examples    文件:GuavaEnumHashBiMapTest.java   
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

}
项目:java_in_examples    文件:GuavaEnumHashBiMapTest.java   
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

}
项目: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    文件:EnumHashBiMapJsonDeserializer.java   
@Override
protected EnumHashBiMap<E, V> newMap() {
    return EnumHashBiMap.create( enumClass );
}
项目: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 );
}