@Override public int getCount(final Object object) { synchronized (lock) { return getBag().getCount(object); } }
@Override public int getCount(final Object object) { return decorated().getCount(object); }
@Override public int getCount(final Object object) { return decorated().getCount(object); }
@Override public int getCount(final Object object) { return getBag().getCount(object); }
/** * Returns <code>true</code> if the bag contains all elements in the given * collection, respecting cardinality. * * @param other the bag to check against * @return <code>true</code> if the Bag contains all the collection */ boolean containsAll(final Bag<?> other) { final Iterator<?> it = other.uniqueSet().iterator(); while (it.hasNext()) { final Object current = it.next(); if (getCount(current) < other.getCount(current)) { return false; } } return true; }
/** * Compares this Bag to another. This Bag equals another Bag if it contains * the same number of occurrences of the same elements. * * @param object the Bag to compare to * @return true if equal */ @Override public boolean equals(final Object object) { if (object == this) { return true; } if (object instanceof Bag == false) { return false; } final Bag<?> other = (Bag<?>) object; if (other.size() != size()) { return false; } for (final E element : map.keySet()) { if (other.getCount(element) != getCount(element)) { return false; } } return true; }
/** * Returns the number of occurrences of the provided object in the iterable. * * @param <E> the element type that the {@link Iterable} may contain * @param <T> the element type of the object to find * @param iterable the {@link Iterable} to search * @param obj the object to find the cardinality of * @return the number of occurrences of obj in iterable */ public static <E, T extends E> int frequency(final Iterable<E> iterable, final T obj) { if (iterable instanceof Set<?>) { return ((Set<E>) iterable).contains(obj) ? 1 : 0; } if (iterable instanceof Bag<?>) { return ((Bag<E>) iterable).getCount(obj); } return size(filteredIterable(emptyIfNull(iterable), EqualPredicate.<E>equalPredicate(obj))); }
/** * Remove any members of the bag that are not in the given bag, respecting * cardinality. * @see #retainAll(Collection) * * @param other the bag to retain * @return <code>true</code> if this call changed the collection */ boolean retainAll(final Bag<?> other) { boolean result = false; final Bag<E> excess = new HashBag<>(); final Iterator<E> i = uniqueSet().iterator(); while (i.hasNext()) { final E current = i.next(); final int myCount = getCount(current); final int otherCount = other.getCount(current); if (1 <= otherCount && otherCount <= myCount) { excess.add(current, myCount - otherCount); } else { excess.add(current, myCount); } } if (!excess.isEmpty()) { result = removeAll(excess); } return result; }
private boolean checkIfPlayerWins(int playerNumber) { Bag<Rank> newRanks = this.getRanks(this.cardsPerPlayer.get(playerNumber)); Rank rank = this.getProbableBook(newRanks); int rankCount = newRanks.getCount(rank); if (rankCount == 4) { LOGGER.info("Player:{} has a BOOK! Player:{} WINS!!!", playerNumber, playerNumber); this.outcome = Outcome.WINNER; return false; } this.outcome = Outcome.CONTINUE; return true; }