com.google.common.collect.Multiset.Entry#getCount ( )源码实例Demo

下面列出了com.google.common.collect.Multiset.Entry#getCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: codebuff   文件: Multisets.java
@Override
public boolean contains(@Nullable Object o) {
  if (o instanceof Entry) {
    /*
     * The GWT compiler wrongly issues a warning here.
     */
    @SuppressWarnings("cast")
    Entry<?> entry = (Entry<?>) o;
    if (entry.getCount() <= 0) {
      return false;
    }
    int count = multiset().count(entry.getElement());
    return count == entry.getCount();
  }
  return false;
}
 
源代码2 项目: codebuff   文件: Multisets.java
@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;
}
 
源代码3 项目: codebuff   文件: ImmutableMultiset.java
@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;
    }
  };
}
 
源代码4 项目: codebuff   文件: ImmutableMultiset.java
@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;
    }
  };
}
 
源代码5 项目: codebuff   文件: Multisets.java
/**
 * An implementation of {@link Multiset#equals}.
 */
static boolean equalsImpl(Multiset<?> multiset, @Nullable Object object) {
  if (object == multiset) {
    return true;
  }
  if (object instanceof Multiset) {
    Multiset<?> that = (Multiset<?>) object;
    /*
     * We can't simply check whether the entry sets are equal, since that
     * approach fails when a TreeMultiset has a comparator that returns 0
     * when passed unequal elements.
     */

    if (multiset.size() != that.size() || multiset.entrySet().size() != that.entrySet().size()) {
      return false;
    }
    for (Entry<?> entry : that.entrySet()) {
      if (multiset.count(entry.getElement()) != entry.getCount()) {
        return false;
      }
    }
    return true;
  }
  return false;
}
 
源代码6 项目: codebuff   文件: Multisets.java
/**
 * Delegate implementation which cares about the element type.
 */

private static <E> boolean retainOccurrencesImpl(Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain) {
  checkNotNull(multisetToModify);
  checkNotNull(occurrencesToRetain);
  // Avoiding ConcurrentModificationExceptions is tricky.
  Iterator<Entry<E>> entryIterator = multisetToModify.entrySet().iterator();
  boolean changed = false;
  while (entryIterator.hasNext()) {
    Entry<E> entry = entryIterator.next();
    int retainCount = occurrencesToRetain.count(entry.getElement());
    if (retainCount == 0) {
      entryIterator.remove();
      changed = true;
    } else if (retainCount < entry.getCount()) {
      multisetToModify.setCount(entry.getElement(), retainCount);
      changed = true;
    }
  }
  return changed;
}
 
源代码7 项目: codebuff   文件: Multisets.java
@Override
public boolean contains(@Nullable Object o) {
  if (o instanceof Entry) {
    /*
     * The GWT compiler wrongly issues a warning here.
     */
    @SuppressWarnings("cast")
    Entry<?> entry = (Entry<?>) o;
    if (entry.getCount() <= 0) {
      return false;
    }
    int count = multiset().count(entry.getElement());
    return count == entry.getCount();
  }
  return false;
}
 
源代码8 项目: codebuff   文件: Multisets.java
@Override
public boolean contains(@Nullable Object o) {
  if (o instanceof Entry) {
    /*
     * The GWT compiler wrongly issues a warning here.
     */
    @SuppressWarnings("cast")
    Entry<?> entry = (Entry<?>) o;
    if (entry.getCount() <= 0) {
      return false;
    }
    int count = multiset().count(entry.getElement());
    return count == entry.getCount();
  }
  return false;
}
 
源代码9 项目: codebuff   文件: Multisets.java
/**
 * Delegate implementation which cares about the element type.
 */

private static <E> boolean retainOccurrencesImpl(Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain) {
  checkNotNull(multisetToModify);
  checkNotNull(occurrencesToRetain);
  // Avoiding ConcurrentModificationExceptions is tricky.
  Iterator<Entry<E>> entryIterator = multisetToModify.entrySet().iterator();
  boolean changed = false;
  while (entryIterator.hasNext()) {
    Entry<E> entry = entryIterator.next();
    int retainCount = occurrencesToRetain.count(entry.getElement());
    if (retainCount == 0) {
      entryIterator.remove();
      changed = true;
    } else if (retainCount < entry.getCount()) {
      multisetToModify.setCount(entry.getElement(), retainCount);
      changed = true;
    }
  }
  return changed;
}
 
源代码10 项目: codebuff   文件: Multisets.java
@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;
}
 
源代码11 项目: codebuff   文件: ImmutableMultiset.java
@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;
    }
  };
}
 
源代码12 项目: codebuff   文件: ImmutableMultiset.java
@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;
    }
  };
}
 
源代码13 项目: codebuff   文件: Multisets.java
@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;
}
 
源代码14 项目: codebuff   文件: Multisets.java
/**
 * Returns {@code true} if {@code subMultiset.count(o) <=
 * superMultiset.count(o)} for all {@code o}.
 *
 * @since 10.0
 */

@CanIgnoreReturnValue
public static boolean containsOccurrences(Multiset<?> superMultiset, Multiset<?> subMultiset) {
  checkNotNull(superMultiset);
  checkNotNull(subMultiset);
  for (Entry<?> entry : subMultiset.entrySet()) {
    int superCount = superMultiset.count(entry.getElement());
    if (superCount < entry.getCount()) {
      return false;
    }
  }
  return true;
}
 
源代码15 项目: codebuff   文件: Multisets.java
/**
 * An implementation of {@link Multiset#size}.
 */

static int sizeImpl(Multiset<?> multiset) {
  long size = 0;
  for (Entry<?> entry : multiset.entrySet()) {
    size += entry.getCount();
  }
  return Ints.saturatedCast(size);
}
 
源代码16 项目: codebuff   文件: ImmutableMultiset.java
@Override
public boolean contains(Object o) {
  if (o instanceof Entry) {
    Entry<?> entry = (Entry<?>) o;
    if (entry.getCount() <= 0) {
      return false;
    }
    int count = count(entry.getElement());
    return count == entry.getCount();
  }
  return false;
}
 
源代码17 项目: codebuff   文件: ImmutableMultiset.java
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++;
  }
}
 
源代码18 项目: codebuff   文件: Multisets.java
/**
 * For each occurrence of an element {@code e} in {@code occurrencesToRemove},
 * removes one occurrence of {@code e} in {@code multisetToModify}.
 *
 * <p>Equivalently, this method modifies {@code multisetToModify} so that
 * {@code multisetToModify.count(e)} is set to
 * {@code Math.max(0, multisetToModify.count(e) -
 * occurrencesToRemove.count(e))}.
 *
 * <p>This is <i>not</i> the same as {@code multisetToModify.}
 * {@link Multiset#removeAll removeAll}{@code (occurrencesToRemove)}, which
 * removes all occurrences of elements that appear in
 * {@code occurrencesToRemove}. However, this operation <i>is</i> equivalent
 * to, albeit sometimes more efficient than, the following: <pre>   {@code
 *
 *   for (E e : occurrencesToRemove) {
 *     multisetToModify.remove(e);
 *   }}</pre>
 *
 * @return {@code true} if {@code multisetToModify} was changed as a result of
 *         this operation
 * @since 10.0 (missing in 18.0 when only the overload taking an {@code Iterable} was present)
 */

@CanIgnoreReturnValue
public static boolean removeOccurrences(Multiset<?> multisetToModify, Multiset<?> occurrencesToRemove) {
  checkNotNull(multisetToModify);
  checkNotNull(occurrencesToRemove);
  boolean changed = false;
  Iterator<? extends Entry<?>> entryIterator = multisetToModify.entrySet().iterator();
  while (entryIterator.hasNext()) {
    Entry<?> entry = entryIterator.next();
    int removeCount = occurrencesToRemove.count(entry.getElement());
    if (removeCount >= entry.getCount()) {
      entryIterator.remove();
      changed = true;
    } else if (removeCount > 0) {
      multisetToModify.remove(entry.getElement(), removeCount);
      changed = true;
    }
  }
  return changed;
}
 
源代码19 项目: codebuff   文件: Multisets.java
/**
 * For each occurrence of an element {@code e} in {@code occurrencesToRemove},
 * removes one occurrence of {@code e} in {@code multisetToModify}.
 *
 * <p>Equivalently, this method modifies {@code multisetToModify} so that
 * {@code multisetToModify.count(e)} is set to
 * {@code Math.max(0, multisetToModify.count(e) -
 * occurrencesToRemove.count(e))}.
 *
 * <p>This is <i>not</i> the same as {@code multisetToModify.}
 * {@link Multiset#removeAll removeAll}{@code (occurrencesToRemove)}, which
 * removes all occurrences of elements that appear in
 * {@code occurrencesToRemove}. However, this operation <i>is</i> equivalent
 * to, albeit sometimes more efficient than, the following: <pre>   {@code
 *
 *   for (E e : occurrencesToRemove) {
 *     multisetToModify.remove(e);
 *   }}</pre>
 *
 * @return {@code true} if {@code multisetToModify} was changed as a result of
 *         this operation
 * @since 10.0 (missing in 18.0 when only the overload taking an {@code Iterable} was present)
 */

@CanIgnoreReturnValue
public static boolean removeOccurrences(Multiset<?> multisetToModify, Multiset<?> occurrencesToRemove) {
  checkNotNull(multisetToModify);
  checkNotNull(occurrencesToRemove);
  boolean changed = false;
  Iterator<? extends Entry<?>> entryIterator = multisetToModify.entrySet().iterator();
  while (entryIterator.hasNext()) {
    Entry<?> entry = entryIterator.next();
    int removeCount = occurrencesToRemove.count(entry.getElement());
    if (removeCount >= entry.getCount()) {
      entryIterator.remove();
      changed = true;
    } else if (removeCount > 0) {
      multisetToModify.remove(entry.getElement(), removeCount);
      changed = true;
    }
  }
  return changed;
}
 
源代码20 项目: codebuff   文件: Multisets.java
/**
 * For each occurrence of an element {@code e} in {@code occurrencesToRemove},
 * removes one occurrence of {@code e} in {@code multisetToModify}.
 *
 * <p>Equivalently, this method modifies {@code multisetToModify} so that
 * {@code multisetToModify.count(e)} is set to
 * {@code Math.max(0, multisetToModify.count(e) -
 * occurrencesToRemove.count(e))}.
 *
 * <p>This is <i>not</i> the same as {@code multisetToModify.}
 * {@link Multiset#removeAll removeAll}{@code (occurrencesToRemove)}, which
 * removes all occurrences of elements that appear in
 * {@code occurrencesToRemove}. However, this operation <i>is</i> equivalent
 * to, albeit sometimes more efficient than, the following: <pre>   {@code
 *
 *   for (E e : occurrencesToRemove) {
 *     multisetToModify.remove(e);
 *   }}</pre>
 *
 * @return {@code true} if {@code multisetToModify} was changed as a result of
 *         this operation
 * @since 10.0 (missing in 18.0 when only the overload taking an {@code Iterable} was present)
 */

@CanIgnoreReturnValue
public static boolean removeOccurrences(Multiset<?> multisetToModify, Multiset<?> occurrencesToRemove) {
  checkNotNull(multisetToModify);
  checkNotNull(occurrencesToRemove);
  boolean changed = false;
  Iterator<? extends Entry<?>> entryIterator = multisetToModify.entrySet().iterator();
  while (entryIterator.hasNext()) {
    Entry<?> entry = entryIterator.next();
    int removeCount = occurrencesToRemove.count(entry.getElement());
    if (removeCount >= entry.getCount()) {
      entryIterator.remove();
      changed = true;
    } else if (removeCount > 0) {
      multisetToModify.remove(entry.getElement(), removeCount);
      changed = true;
    }
  }
  return changed;
}