Exemplo n.º 1
0
 Object readResolve() {
   LinkedHashMultiset<Object> multiset = LinkedHashMultiset.create(elements.length);
   for (int i = 0; i < elements.length; i++) {
     multiset.add(elements[i], counts[i]);
   }
   return ImmutableMultiset.copyOf(multiset);
 }
  @BeforeExperiment
  void setUp() {
    hashMultiset = HashMultiset.create(size);
    linkedHashMultiset = LinkedHashMultiset.create(size);
    treeMultiset = TreeMultiset.create();

    Random random = new Random();

    int sizeRemaining = size;

    // TODO(kevinb): generate better test contents for multisets
    for (int i = 0; sizeRemaining > 0; i++) {
      // The JVM will return interned values for small ints.
      Integer value = random.nextInt(1000) + 128;
      int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
      sizeRemaining -= count;
      hashMultiset.add(value, count);
      linkedHashMultiset.add(value, count);
      treeMultiset.add(value, count);
    }

    // TODO(kevinb): convert to assert once benchmark tests enable asserts by default
    Preconditions.checkState(hashMultiset.size() == size);
  }