Java Code Examples for com.google.common.collect.Multiset.Entry#getElement()

The following examples show how to use com.google.common.collect.Multiset.Entry#getElement() . 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: Multisets.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
  if (object instanceof Multiset.Entry) {
    Entry<?> entry = (Entry<?>) object;
    Object element = entry.getElement();
    int entryCount = entry.getCount();
    if (entryCount != 0) {
      // Safe as long as we never add a new entry, which we won't.
      @SuppressWarnings("unchecked")
      Multiset<Object> multiset = (Multiset) multiset();
      return multiset.setCount(element, entryCount, 0);
    }
  }
  return false;
}
 
Example 2
Source File: ImmutableMultiset.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public UnmodifiableIterator<E> iterator() {
  final Iterator<Entry<E>> entryIterator = entrySet().iterator();
  return new UnmodifiableIterator<E>() {
    int remaining;

    E element;


    @Override
    public boolean hasNext() {
      return (remaining > 0) || entryIterator.hasNext();
    }

    @Override
    public E next() {
      if (remaining <= 0) {
        Entry<E> entry = entryIterator.next();
        element = entry.getElement();
        remaining = entry.getCount();
      }
      remaining--;
      return element;
    }
  };
}
 
Example 3
Source File: Multisets.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
  if (object instanceof Multiset.Entry) {
    Entry<?> entry = (Entry<?>) object;
    Object element = entry.getElement();
    int entryCount = entry.getCount();
    if (entryCount != 0) {
      // Safe as long as we never add a new entry, which we won't.
      @SuppressWarnings("unchecked")
      Multiset<Object> multiset = (Multiset) multiset();
      return multiset.setCount(element, entryCount, 0);
    }
  }
  return false;
}
 
Example 4
Source File: ImmutableMultiset.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public UnmodifiableIterator<E> iterator() {
  final Iterator<Entry<E>> entryIterator = entrySet().iterator();
  return new UnmodifiableIterator<E>() {
    int remaining;

    E element;


    @Override
    public boolean hasNext() {
      return (remaining > 0) || entryIterator.hasNext();
    }

    @Override
    public E next() {
      if (remaining <= 0) {
        Entry<E> entry = entryIterator.next();
        element = entry.getElement();
        remaining = entry.getCount();
      }
      remaining--;
      return element;
    }
  };
}
 
Example 5
Source File: Multisets.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
  if (object instanceof Multiset.Entry) {
    Entry<?> entry = (Entry<?>) object;
    Object element = entry.getElement();
    int entryCount = entry.getCount();
    if (entryCount != 0) {
      // Safe as long as we never add a new entry, which we won't.
      @SuppressWarnings("unchecked")
      Multiset<Object> multiset = (Multiset) multiset();
      return multiset.setCount(element, entryCount, 0);
    }
  }
  return false;
}
 
Example 6
Source File: Multisets.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
  if (object instanceof Multiset.Entry) {
    Entry<?> entry = (Entry<?>) object;
    Object element = entry.getElement();
    int entryCount = entry.getCount();
    if (entryCount != 0) {
      // Safe as long as we never add a new entry, which we won't.
      @SuppressWarnings("unchecked")
      Multiset<Object> multiset = (Multiset) multiset();
      return multiset.setCount(element, entryCount, 0);
    }
  }
  return false;
}
 
Example 7
Source File: ImmutableMultiset.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public UnmodifiableIterator<E> iterator() {
  final Iterator<Entry<E>> entryIterator = entrySet().iterator();
  return new UnmodifiableIterator<E>() {
    int remaining;
    E element;

    @Override
    public boolean hasNext() {
      return (remaining > 0) || entryIterator.hasNext();
    }

    @Override
    public E next() {
      if (remaining <= 0) {
        Entry<E> entry = entryIterator.next();
        element = entry.getElement();
        remaining = entry.getCount();
      }
      remaining--;
      return element;
    }
  };
}
 
Example 8
Source File: ImmutableMultiset.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public UnmodifiableIterator<E> iterator() {
  final Iterator<Entry<E>> entryIterator = entrySet().iterator();
  return new UnmodifiableIterator<E>() {
    int remaining;

    E element;


    @Override
    public boolean hasNext() {
      return (remaining > 0) || entryIterator.hasNext();
    }

    @Override
    public E next() {
      if (remaining <= 0) {
        Entry<E> entry = entryIterator.next();
        element = entry.getElement();
        remaining = entry.getCount();
      }
      remaining--;
      return element;
    }
  };
}
 
Example 9
Source File: Multisets.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Iterator<E> iterator() {
  return new TransformedIterator<Entry<E>, E>(multiset().entrySet().iterator()) {
    @Override
    E transform(Entry<E> entry) {
      return entry.getElement();
    }
  };
}
 
Example 10
Source File: ImmutableMultiset.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
SerializedForm(Multiset<?> multiset) {
  int distinct = multiset.entrySet().size();
  elements = new Object[distinct];
  counts = new int[distinct];
  int i = 0;
  for (Entry<?> entry : multiset.entrySet()) {
    elements[i] = entry.getElement();
    counts[i] = entry.getCount();
    i++;
  }
}
 
Example 11
Source File: Multisets.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Iterator<E> iterator() {
  return new TransformedIterator<Entry<E>, E>(multiset().entrySet().iterator()) {
    @Override
    E transform(Entry<E> entry) {
      return entry.getElement();
    }
  };
}
 
Example 12
Source File: ImmutableMultiset.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
SerializedForm(Multiset<?> multiset) {
  int distinct = multiset.entrySet().size();
  elements = new Object[distinct];
  counts = new int[distinct];
  int i = 0;
  for (Entry<?> entry : multiset.entrySet()) {
    elements[i] = entry.getElement();
    counts[i] = entry.getCount();
    i++;
  }
}
 
Example 13
Source File: ImmutableMultiset.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
SerializedForm(Multiset<?> multiset) {
  int distinct = multiset.entrySet().size();
  elements = new Object[distinct];
  counts = new int[distinct];
  int i = 0;
  for (Entry<?> entry : multiset.entrySet()) {
    elements[i] = entry.getElement();
    counts[i] = entry.getCount();
    i++;
  }
}
 
Example 14
Source File: Multisets.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Iterator<E> iterator() {
  return new TransformedIterator<Entry<E>, E>(multiset().entrySet().iterator()) {
    @Override
    E transform(Entry<E> entry) {
      return entry.getElement();
    }
  };
}
 
Example 15
Source File: SortedMultisets.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static <E> E getElementOrThrow(Entry<E> entry) {
  if (entry == null) {
    throw new NoSuchElementException();
  }
  return entry.getElement();
}
 
Example 16
Source File: SortedMultisets.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static <E> E getElementOrNull(@Nullable Entry<E> entry) {
  return (entry == null) ? null : entry.getElement();
}
 
Example 17
Source File: SortedMultisets.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static <E> E getElementOrThrow(Entry<E> entry) {
  if (entry == null) {
    throw new NoSuchElementException();
  }
  return entry.getElement();
}
 
Example 18
Source File: SortedMultisets.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static <E> E getElementOrThrow(Entry<E> entry) {
  if (entry == null) {
    throw new NoSuchElementException();
  }
  return entry.getElement();
}
 
Example 19
Source File: SortedMultisets.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static <E> E getElementOrNull(@Nullable Entry<E> entry) {
  return (entry == null) ? null : entry.getElement();
}
 
Example 20
Source File: SortedMultisets.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static <E> E getElementOrNull(@Nullable Entry<E> entry) {
  return (entry == null) ? null : entry.getElement();
}