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

项目:gwt-jackson    文件:MultisetGwtTest.java   
public void testSerialization() {
    BeanWithMultisetTypes bean = new BeanWithMultisetTypes();

    List<String> list = Arrays.asList( "foo", "abc", null, "abc" );
    List<String> listWithNonNull = Arrays.asList( "foo", "abc", "bar", "abc" );

    bean.multiset = LinkedHashMultiset.create( list );
    bean.hashMultiset = HashMultiset.create( Arrays.asList( "abc", "abc" ) );
    bean.linkedHashMultiset = LinkedHashMultiset.create( list );
    bean.sortedMultiset = TreeMultiset.create( listWithNonNull );
    bean.treeMultiset = TreeMultiset.create( listWithNonNull );
    bean.immutableMultiset = ImmutableMultiset.copyOf( listWithNonNull );
    bean.enumMultiset = EnumMultiset.create( Arrays.asList( AlphaEnum.B, AlphaEnum.A, AlphaEnum.D, AlphaEnum.A ) );

    String expected = "{" +
            "\"multiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"hashMultiset\":[\"abc\",\"abc\"]," +
            "\"linkedHashMultiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"sortedMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
            "\"treeMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
            "\"immutableMultiset\":[\"foo\",\"abc\",\"abc\",\"bar\"]," +
            "\"enumMultiset\":[\"A\",\"A\",\"B\",\"D\"]" +
            "}";

    assertEquals( expected, BeanWithMultisetTypesMapper.INSTANCE.write( bean ) );
}
项目:gwt-jackson    文件:MultisetGwtTest.java   
public void testDeserialization() {
    String input = "{" +
            "\"multiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"hashMultiset\":[\"abc\",\"abc\"]," +
            "\"linkedHashMultiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"sortedMultiset\":[\"foo\",\"abc\",\"bar\",\"abc\",null]," +
            "\"treeMultiset\":[\"bar\",\"abc\",\"abc\",\"foo\",null]," +
            "\"immutableMultiset\":[\"foo\",\"abc\",\"abc\",\"bar\",null]," +
            "\"enumMultiset\":[\"B\",\"A\",\"A\",\"D\",null]" +
            "}";

    BeanWithMultisetTypes result = BeanWithMultisetTypesMapper.INSTANCE.read( input );
    assertNotNull( result );

    List<String> expectedList = Arrays.asList( "foo", "abc", null, "abc" );
    List<String> expectedListWithNonNull = Arrays.asList( "foo", "abc", "bar", "abc" );

    assertEquals( LinkedHashMultiset.create( expectedList ), result.multiset );
    assertEquals( HashMultiset.create( Arrays.asList( "abc", "abc" ) ), result.hashMultiset );
    assertEquals( LinkedHashMultiset.create( expectedList ), result.linkedHashMultiset );
    assertEquals( TreeMultiset.create( expectedListWithNonNull ), result.sortedMultiset );
    assertEquals( TreeMultiset.create( expectedListWithNonNull ), result.treeMultiset );
    assertEquals( ImmutableMultiset.copyOf( expectedListWithNonNull ), result.immutableMultiset );
    assertEquals( EnumMultiset.create( Arrays.asList( AlphaEnum.B, AlphaEnum.A, AlphaEnum.D, AlphaEnum.A ) ), result.enumMultiset );
}
项目:creeper    文件:Hand.java   
public Hand(Set<Card> cards) {
    this.cards = cards;
    checkArgument(cards.size() == 5);
    Set<Suit> suits = EnumSet.noneOf(Suit.class);
    Multiset<Rank> ranks = EnumMultiset.create(Rank.class);
    for (Card card : cards) {
        suits.add(card.suit);
        ranks.add(card.rank);
    }
    Set<Entry<Rank>> entries = ranks.entrySet();
    for (Entry<Rank> entry : byCountThenRank.immutableSortedCopy(entries)) {
        distinctRanks.addFirst(entry.getElement());
    }
    Rank first = distinctRanks.getFirst();
    int distinctCount = distinctRanks.size();
    if (distinctCount == 5) {
        boolean flush = suits.size() == 1;
        if (first.ordinal() - distinctRanks.getLast().ordinal() == 4) {
            category = flush ? STRAIGHT_FLUSH : STRAIGHT;
        }
        else if (first == ACE && distinctRanks.get(1) == FIVE) {
            category = flush ? STRAIGHT_FLUSH : STRAIGHT;
            // ace plays low, move to end
            distinctRanks.addLast(distinctRanks.removeFirst());
        }
        else {
            category = flush ? FLUSH : HIGH_CARD;
        }
    }
    else if (distinctCount == 4) {
        category = ONE_PAIR;
    }
    else if (distinctCount == 3) {
        category = ranks.count(first) == 2 ? TWO_PAIR : THREE_OF_A_KIND;
    }
    else {
        category = ranks.count(first) == 3 ? FULL_HOUSE : FOUR_OF_A_KIND;
    }
}
项目:QMAClone    文件:GameTest.java   
@Test
public void prepareProblemsShouldSelectFromSelectedGenresAndTypesEqually() {
  List<Integer> problemIds = Lists.newArrayList();
  Set<ProblemGenre> selectedGenres = EnumSet.of(ProblemGenre.Anige, ProblemGenre.Sports);
  Set<ProblemType> selectedTypes = EnumSet.of(ProblemType.Marubatsu, ProblemType.YonTaku,
      ProblemType.Rensou);

  List<PacketProblem> problems = game.prepareProblems(0, NewAndOldProblems.Both, problemIds,
      selectedGenres, selectedTypes, 0, null);

  Multiset<ProblemGenre> genres = EnumMultiset.create(ProblemGenre.class);
  Multiset<ProblemType> types = EnumMultiset.create(ProblemType.class);

  for (PacketProblem problem : problems) {
    assertThat(problem.genre, isIn(selectedGenres));
    genres.add(problem.genre);

    assertThat(problem.type, isIn(selectedTypes));
    types.add(problem.type);
  }

  // 問題が見つからなかった場合に問題数が少なくなる場合があることを許容する
  assertThat(genres.count(ProblemGenre.Anige), isOneOf(7, 8, 9));
  assertThat(genres.count(ProblemGenre.Sports), isOneOf(7, 8, 9));
  assertThat(types.count(ProblemType.Marubatsu), isOneOf(3, 4, 5, 6, 7));
  assertThat(types.count(ProblemType.YonTaku), isOneOf(3, 4, 5, 6, 7));
  assertThat(types.count(ProblemType.Rensou), isOneOf(3, 4, 5, 6, 7));
}
项目:molgenis    文件:Parser.java   
/**
 * Transforms a stream of lines and sends them to the error sink
 *
 * @param lines      the Stream of lines to transform
 * @param outputSink {@link LineSink} to write transformed lines to
 * @param errorSink  {@link LineSink} to write unparseable lines to
 * @return Multiset counting the {@link LineType}s found in the stream
 */
Multiset<LineType> transformLines(Stream<String> lines, LineSink outputSink, LineSink errorSink)
{
    Multiset<LineType> lineTypes = EnumMultiset.create(LineType.class);
    writeVcfHeader(outputSink);
    lines.map(line -> transformLine(line, lineTypes.size(), countValidLines(lineTypes), outputSink, errorSink))
         .forEach(lineTypes::add);
    return lineTypes;
}
项目:gwt-jackson    文件:EnumMultisetJsonDeserializer.java   
@Override
protected EnumMultiset<E> newCollection() {
    return EnumMultiset.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 );
}