Guava Multiset.Entry - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Multiset.Entry class.

This code example shows how to use the following methods:getCount
	// http://philippeadjiman.com/blog/2010/02/20/a-generic-method-for-sorting-google-collections-multiset-per-entry-count/ 
	public static <T> List<Entry<T>> sortByCount(Multiset<T> multiset) {
 
		Comparator<Multiset.Entry<T>> occurence_comparator = new Comparator<Multiset.Entry<T>>() {
			public int compare(Multiset.Entry<T> e1, Multiset.Entry<T> e2) {
				return e2.getCount() - e1.getCount();
			} 
		}; 
		List<Entry<T>> sortedByCount = new ArrayList<Entry<T>>(multiset.entrySet());
		Collections.sort(sortedByCount, occurence_comparator);
 
		return sortedByCount;
	} 
 
	public static <T> List<T> head(List<T> list, int n) {
		if (n <= list.size()) {
			return list.subList(0, n);
		} else { 
			return list;
		} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hashCode
    assertFalse(entry(NE, 1).equals(null));
  } 
 
  public void testHashCode() { 
    assertEquals(control("foo", 1).hashCode(), entry("foo", 1).hashCode());
    assertEquals(control("bar", 2).hashCode(), entry("bar", 2).hashCode());
  } 
 
  public void testHashCodeNull() { 
    assertEquals(control(NE, 1).hashCode(), entry(NE, 1).hashCode());
  } 
 
  public void testNegativeCount() { 
    try { 
      entry("foo", -1); 
      fail();
    } catch (IllegalArgumentException expected) {}
  } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount, getElement
  @SuppressWarnings("unchecked") 
  // Needed to stop Eclipse whining 
  private void resetWithHole() { 
    List<E> container = new ArrayList<E>();
    container.addAll(Collections.nCopies(a.getCount(), a.getElement()));
    container.addAll(Collections.nCopies(c.getCount(), c.getElement()));
    super.resetContainer(getSubjectGenerator().create(container.toArray()));
    sortedMultiset = (SortedMultiset<E>) getMultiset();
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptyMultisetFirst() { 
    assertNull(sortedMultiset.firstEntry());
    try { 
      sortedMultiset.elementSet().first();
      fail(); 
    } catch (NoSuchElementException e) {}
  } 
 
  @CollectionFeature.Require(SUPPORTS_REMOVE) 

4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
  } 
 
  public void testEntryAfterRemove() { 
    ms.add("a", 8);
    Multiset.Entry<String> entry = ms.entrySet().iterator().next();
    assertEquals(8, entry.getCount());
    ms.remove("a");
    assertEquals(7, entry.getCount());
    ms.remove("a", 4);
    assertEquals(3, entry.getCount());
    ms.elementSet().remove("a");
    assertEquals(0, entry.getCount());
    ms.add("a", 5);
    assertEquals(5, entry.getCount());
  } 
 
  public void testEntryAfterClear() { 
    ms.add("a", 3);
    Multiset.Entry<String> entry = ms.entrySet().iterator().next();
    ms.clear();
2
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getElement
      } 
 
      @Override 
      <E> SortedMultiset<E> subMultiset(SortedMultiset<E> multiset, List<Entry<E>> entries,
          int targetEntry) {
        return multiset.tailMultiset(entries.get(targetEntry).getElement(), CLOSED); 
      } 
    }, 
    TAIL_OPEN {
      @Override 
      <E> List<Entry<E>> expectedEntries(int targetEntry, List<Entry<E>> entries) {
        return entries.subList(targetEntry + 1, entries.size()); 
      } 
 
      @Override 
      <E> SortedMultiset<E> subMultiset(SortedMultiset<E> multiset, List<Entry<E>> entries,
          int targetEntry) {
        return multiset.tailMultiset(entries.get(targetEntry).getElement(), OPEN); 
      } 
    }, 
1
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getElement
      } 
 
      @Override 
      <E> SortedMultiset<E> subMultiset(SortedMultiset<E> multiset, List<Entry<E>> entries,
          int targetEntry) {
        return multiset.headMultiset(entries.get(targetEntry).getElement(), OPEN); 
      } 
    }; 
    abstract <E> List<Entry<E>> expectedEntries(int targetEntry, List<Entry<E>> entries);
 
    abstract <E> SortedMultiset<E> subMultiset(SortedMultiset<E> multiset, List<Entry<E>> entries,
        int targetEntry);
  } 
 
  private void testSubMultisetEntrySet(SubMultisetSpec spec) {
    List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
    for (int i = 0; i < entries.size(); i++) {
      List<Entry<E>> expected = spec.expectedEntries(i, entries);
      SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
      assertEquals(expected, copyToList(subMultiset.entrySet()));
2
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Guava Multiset.Entry Methods: