Java 类org.apache.commons.collections4.MultiSet 实例源码

项目:HCFCore    文件:AbstractMapMultiSet.java   
@Override
public boolean equals(final Object object) {
    if (object == this) {
        return true;
    }
    if (object instanceof MultiSet == false) {
        return false;
    }
    final MultiSet<?> other = (MultiSet<?>) object;
    if (other.size() != size()) {
        return false;
    }
    for (final E element : map.keySet()) {
        if (other.getCount(element) != getCount(element)) {
            return false;
        }
    }
    return true;
}
项目:HCFCore    文件:AbstractMultiSet.java   
@Override
public boolean equals(final Object object) {
    if (object == this) {
        return true;
    }
    if (object instanceof MultiSet == false) {
        return false;
    }
    final MultiSet<?> other = (MultiSet<?>) object;
    if (other.size() != size()) {
        return false;
    }
    for (final Entry<E> entry : entrySet()) {
        if (other.getCount(entry.getElement()) != getCount(entry.getElement())) {
            return false;
        }
    }
    return true;
}
项目:HCFCore    文件:AbstractMapMultiSet.java   
@Override
public boolean equals(final Object object) {
    if (object == this) {
        return true;
    }
    if (object instanceof MultiSet == false) {
        return false;
    }
    final MultiSet<?> other = (MultiSet<?>) object;
    if (other.size() != size()) {
        return false;
    }
    for (final E element : map.keySet()) {
        if (other.getCount(element) != getCount(element)) {
            return false;
        }
    }
    return true;
}
项目:HCFCore    文件:AbstractMultiSet.java   
@Override
public boolean equals(final Object object) {
    if (object == this) {
        return true;
    }
    if (object instanceof MultiSet == false) {
        return false;
    }
    final MultiSet<?> other = (MultiSet<?>) object;
    if (other.size() != size()) {
        return false;
    }
    for (final Entry<E> entry : entrySet()) {
        if (other.getCount(entry.getElement()) != getCount(entry.getElement())) {
            return false;
        }
    }
    return true;
}
项目:HCFCore    文件:SynchronizedMultiSet.java   
@Override
public Set<Entry<E>> entrySet() {
    synchronized (lock) {
        final Set<MultiSet.Entry<E>> set = decorated().entrySet();
        return new SynchronizedSet<MultiSet.Entry<E>>(set, lock);
    }
}
项目:HCFCore    文件:AbstractMultiValuedMap.java   
@Override
public MultiSet.Entry<K> transform(final Map.Entry<K, Collection<V>> mapEntry) {
    return new AbstractMultiSet.AbstractEntry<K>() {
        @Override
        public K getElement() {
            return mapEntry.getKey();
        }

        @Override
        public int getCount() {
            return mapEntry.getValue().size();
        }
    };
}
项目:HCFCore    文件:SynchronizedMultiSet.java   
@Override
public Set<Entry<E>> entrySet() {
    synchronized (lock) {
        final Set<MultiSet.Entry<E>> set = decorated().entrySet();
        return new SynchronizedSet<MultiSet.Entry<E>>(set, lock);
    }
}
项目:HCFCore    文件:AbstractMultiValuedMap.java   
@Override
public MultiSet.Entry<K> transform(final Map.Entry<K, Collection<V>> mapEntry) {
    return new AbstractMultiSet.AbstractEntry<K>() {
        @Override
        public K getElement() {
            return mapEntry.getKey();
        }

        @Override
        public int getCount() {
            return mapEntry.getValue().size();
        }
    };
}
项目:engerek    文件:EvaluationOrderImpl.java   
@Override
public EvaluationOrder decrease(MultiSet<QName> relations) {
    EvaluationOrderImpl clone = clone();
    for (QName relation : relations) {
        clone.advanceThis(relation, -1);
    }
    clone.checkConsistence();
    return clone;
}
项目:midpoint    文件:EvaluationOrderImpl.java   
@Override
public EvaluationOrder decrease(MultiSet<QName> relations) {
    EvaluationOrderImpl clone = clone();
    for (QName relation : relations) {
        clone.advanceThis(relation, -1);
    }
    clone.checkConsistence();
    return clone;
}
项目:midpoint    文件:EvaluationOrderImpl.java   
@Override
public EvaluationOrder decrease(MultiSet<QName> relations) {
    EvaluationOrderImpl clone = clone();
    for (QName relation : relations) {
        clone.advanceThis(relation, -1);
    }
    clone.checkConsistence();
    return clone;
}
项目:CodeKatas    文件:ApacheCommonsDeckOfCardsAsSortedSet.java   
public MultiSet<Rank> countsByRank()
{
    // TODO return the count of cards by Rank
    // Hint: Look at HashMultiset.  Compare HashBag and HashMultiset.  What is the difference?
    return null;
}
项目:CodeKatas    文件:ApacheCommonsDeckOfCardsAsList.java   
public MultiSet<Rank> countsByRank()
{
    // TODO return the count of cards by Rank
    // Hint: Look at HashMultiset.  Compare HashMultiset to HashBag.  What is the difference?
    return null;
}
项目:HCFCore    文件:PredicatedMultiSet.java   
@Override
public Set<MultiSet.Entry<E>> entrySet() {
    return decorated().entrySet();
}
项目:HCFCore    文件:UnmodifiableMultiSet.java   
@Override
public Set<MultiSet.Entry<E>> entrySet() {
    final Set<MultiSet.Entry<E>> set = decorated().entrySet();
    return UnmodifiableSet.unmodifiableSet(set);
}
项目:HCFCore    文件:AbstractMultiValuedMap.java   
@Override
protected Iterator<MultiSet.Entry<K>> createEntrySetIterator() {
    final MapEntryTransformer transformer = new MapEntryTransformer();
    return IteratorUtils.transformedIterator(map.entrySet().iterator(), transformer);
}
项目:HCFCore    文件:UnmodifiableMultiValuedMap.java   
@Override
public MultiSet<K> keys() {
    return UnmodifiableMultiSet.unmodifiableMultiSet(decorated().keys());
}
项目:HCFCore    文件:AbstractMultiValuedMapDecorator.java   
@Override
public MultiSet<K> keys() {
    return decorated().keys();
}
项目:HCFCore    文件:PredicatedMultiSet.java   
@Override
public Set<MultiSet.Entry<E>> entrySet() {
    return decorated().entrySet();
}
项目:HCFCore    文件:UnmodifiableMultiSet.java   
@Override
public Set<MultiSet.Entry<E>> entrySet() {
    final Set<MultiSet.Entry<E>> set = decorated().entrySet();
    return UnmodifiableSet.unmodifiableSet(set);
}
项目:HCFCore    文件:AbstractMultiValuedMap.java   
@Override
protected Iterator<MultiSet.Entry<K>> createEntrySetIterator() {
    final MapEntryTransformer transformer = new MapEntryTransformer();
    return IteratorUtils.transformedIterator(map.entrySet().iterator(), transformer);
}
项目:HCFCore    文件:UnmodifiableMultiValuedMap.java   
@Override
public MultiSet<K> keys() {
    return UnmodifiableMultiSet.unmodifiableMultiSet(decorated().keys());
}
项目:HCFCore    文件:AbstractMultiValuedMapDecorator.java   
@Override
public MultiSet<K> keys() {
    return decorated().keys();
}
项目:engerek    文件:UndefinedEvaluationOrderImpl.java   
@Override
public EvaluationOrder decrease(MultiSet<QName> relations) {
    return this;
}
项目:Beagle    文件:EvaluableExpressionSimplifierTest.java   
/**
 * Test method for {@link EvaluableExpressionSimplifier#simplify(EvaluableExpression)}
 * .
 *
 * <p>Asserts that length of simplified expression is no longer than the length of the
 * initial expression and that the result of the expression still is the same.
 */
@Test
public void simplify() {
    final EvaluableExpressionSimplifier simplifier = new EvaluableExpressionSimplifier();

    MultiSet<EvaluableExpression> summands = new HashMultiSet<>();
    summands.add(ConstantExpression.forValue(3));
    summands.add(ConstantExpression.forValue(4));
    summands.add(new EvaluableVariable("a"));
    EvaluableExpression expression = new AdditionExpression(summands);
    EvaluableExpression simplified = simplifier.simplify(expression);
    assertThat(simplified, isNoLongerThan(expression));
    assertThat(simplified, is(producingTheSameValuesAs(expression)));

    summands = new HashMultiSet<>();
    summands.add(ConstantExpression.forValue(19));
    summands.add(new SubtractionExpression(ConstantExpression.forValue(2), ConstantExpression.forValue(5)));
    summands.add(new SubtractionExpression(ConstantExpression.forValue(3), new EvaluableVariable("b")));
    expression = new AdditionExpression(summands);
    simplified = simplifier.simplify(expression);
    assertThat(simplified, isNoLongerThan(expression));
    assertThat(simplified, is(producingTheSameValuesAs(expression)));

    summands = new HashMultiSet<>();
    summands.add(ConstantExpression.forValue(19));
    summands.add(new MultiplicationExpression(new EvaluableVariable("c"), ConstantExpression.forValue(2)));
    summands.add(new AdditionExpression(ConstantExpression.forValue(2), ConstantExpression.forValue(5)));
    summands.add(new AdditionExpression(new EvaluableVariable("c"), new EvaluableVariable("b")));
    summands.add(new SubtractionExpression(new EvaluableVariable("d"), ConstantExpression.forValue(5)));
    summands.add(new SubtractionExpression(ConstantExpression.forValue(3), new EvaluableVariable("b")));
    summands.add(new EvaluableVariable("d"));
    expression = new AdditionExpression(summands);
    simplified = simplifier.simplify(expression);
    assertThat(simplified, isNoLongerThan(expression));
    assertThat(simplified, is(producingTheSameValuesAs(expression)));

    summands = new HashMultiSet<>();
    summands.add(ConstantExpression.forValue(19));
    summands.add(ConstantExpression.forValue(2));
    summands.add(ConstantExpression.forValue(-4.6));
    summands.add(new SubtractionExpression(new EvaluableVariable("x"), ConstantExpression.forValue(3)));
    summands.add(new SubtractionExpression(ConstantExpression.forValue(10.34), ConstantExpression.forValue(-4.6)));
    summands.add(new MultiplicationExpression(new EvaluableVariable("c"), ConstantExpression.forValue(2)));
    summands.add(new AdditionExpression(ConstantExpression.forValue(2), ConstantExpression.forValue(5)));
    summands.add(new AdditionExpression(new EvaluableVariable("c"), new EvaluableVariable("b")));
    summands.add(new SubtractionExpression(new EvaluableVariable("d"), ConstantExpression.forValue(5)));
    summands.add(new SubtractionExpression(ConstantExpression.forValue(3), new EvaluableVariable("b")));
    summands.add(new EvaluableVariable("d"));
    expression = new AdditionExpression(summands);
    simplified = simplifier.simplify(expression);
    assertThat(simplified, isNoLongerThan(expression));
    assertThat(simplified, is(producingTheSameValuesAs(expression)));

    expression = new MultiplicationExpression(ConstantExpression.forValue(3), new EvaluableVariable("a"));
    simplified = simplifier.simplify(expression);
    assertThat(simplified, isNoLongerThan(expression));
    assertThat(simplified, is(producingTheSameValuesAs(expression)));

    expression =
        new AdditionExpression(new SubtractionExpression(new EvaluableVariable("b"), new EvaluableVariable("z")),
            new SubtractionExpression(new EvaluableVariable("x"),
                new AdditionExpression(ConstantExpression.forValue(3.2), new EvaluableVariable("j"))));
    simplified = simplifier.simplify(expression);
    assertThat(simplified, isNoLongerThan(expression));
    assertThat(simplified, is(producingTheSameValuesAs(expression)));
}
项目:midpoint    文件:UndefinedEvaluationOrderImpl.java   
@Override
public EvaluationOrder decrease(MultiSet<QName> relations) {
    return this;
}
项目:midpoint    文件:UndefinedEvaluationOrderImpl.java   
@Override
public EvaluationOrder decrease(MultiSet<QName> relations) {
    return this;
}
项目:HCFCore    文件:PredicatedCollection.java   
/**
 * Decorates the given multiset with validating behavior using the predicate. All accepted elements
 * are appended to the multiset. If the multiset already contains elements, they are validated.
 * <p>
 * The builder is not modified by this method, so it is possible to create more collections
 * or add more elements afterwards. Further changes will not propagate to the returned multiset.
 *
 * @param multiset  the multiset to decorate, must not be null
 * @return the decorated multiset.
 * @throws NullPointerException if multiset is null
 * @throws IllegalArgumentException if multiset contains invalid elements
 */
public MultiSet<E> createPredicatedMultiSet(final MultiSet<E> multiset) {
    if (multiset == null) {
        throw new NullPointerException("MultiSet must not be null.");
    }
    final PredicatedMultiSet<E> predicatedMultiSet =
            PredicatedMultiSet.predicatedMultiSet(multiset, predicate);
    predicatedMultiSet.addAll(accepted);
    return predicatedMultiSet;
}
项目:HCFCore    文件:UnmodifiableMultiSet.java   
/**
 * Factory method to create an unmodifiable multiset.
 * <p>
 * If the multiset passed in is already unmodifiable, it is returned.
 *
 * @param <E>  the type of the elements in the multiset
 * @param multiset  the multiset to decorate, may not be null
 * @return an unmodifiable MultiSet
 * @throws NullPointerException if multiset is null
 */
public static <E> MultiSet<E> unmodifiableMultiSet(final MultiSet<? extends E> multiset) {
    if (multiset instanceof Unmodifiable) {
        @SuppressWarnings("unchecked") // safe to upcast
        final MultiSet<E> tmpMultiSet = (MultiSet<E>) multiset;
        return tmpMultiSet;
    }
    return new UnmodifiableMultiSet<E>(multiset);
}
项目:HCFCore    文件:AbstractMultiValuedMap.java   
/**
 * Returns a {@link MultiSet} view of the key mapping contained in this map.
 * <p>
 * Returns a MultiSet of keys with its values count as the count of the MultiSet.
 * This multiset is backed by the map, so any changes in the map is reflected here.
 * Any method which modifies this multiset like {@code add}, {@code remove},
 * {@link Iterator#remove()} etc throws {@code UnsupportedOperationException}.
 *
 * @return a bag view of the key mapping contained in this map
 */
@Override
public MultiSet<K> keys() {
    if (keysMultiSetView == null) {
        keysMultiSetView = UnmodifiableMultiSet.unmodifiableMultiSet(new KeysMultiSet());
    }
    return keysMultiSetView;
}
项目:HCFCore    文件:PredicatedCollection.java   
/**
 * Decorates the given multiset with validating behavior using the predicate. All accepted elements
 * are appended to the multiset. If the multiset already contains elements, they are validated.
 * <p>
 * The builder is not modified by this method, so it is possible to create more collections
 * or add more elements afterwards. Further changes will not propagate to the returned multiset.
 *
 * @param multiset  the multiset to decorate, must not be null
 * @return the decorated multiset.
 * @throws NullPointerException if multiset is null
 * @throws IllegalArgumentException if multiset contains invalid elements
 */
public MultiSet<E> createPredicatedMultiSet(final MultiSet<E> multiset) {
    if (multiset == null) {
        throw new NullPointerException("MultiSet must not be null.");
    }
    final PredicatedMultiSet<E> predicatedMultiSet =
            PredicatedMultiSet.predicatedMultiSet(multiset, predicate);
    predicatedMultiSet.addAll(accepted);
    return predicatedMultiSet;
}
项目:HCFCore    文件:UnmodifiableMultiSet.java   
/**
 * Factory method to create an unmodifiable multiset.
 * <p>
 * If the multiset passed in is already unmodifiable, it is returned.
 *
 * @param <E>  the type of the elements in the multiset
 * @param multiset  the multiset to decorate, may not be null
 * @return an unmodifiable MultiSet
 * @throws NullPointerException if multiset is null
 */
public static <E> MultiSet<E> unmodifiableMultiSet(final MultiSet<? extends E> multiset) {
    if (multiset instanceof Unmodifiable) {
        @SuppressWarnings("unchecked") // safe to upcast
        final MultiSet<E> tmpMultiSet = (MultiSet<E>) multiset;
        return tmpMultiSet;
    }
    return new UnmodifiableMultiSet<E>(multiset);
}
项目:HCFCore    文件:AbstractMultiValuedMap.java   
/**
 * Returns a {@link MultiSet} view of the key mapping contained in this map.
 * <p>
 * Returns a MultiSet of keys with its values count as the count of the MultiSet.
 * This multiset is backed by the map, so any changes in the map is reflected here.
 * Any method which modifies this multiset like {@code add}, {@code remove},
 * {@link Iterator#remove()} etc throws {@code UnsupportedOperationException}.
 *
 * @return a bag view of the key mapping contained in this map
 */
@Override
public MultiSet<K> keys() {
    if (keysMultiSetView == null) {
        keysMultiSetView = UnmodifiableMultiSet.unmodifiableMultiSet(new KeysMultiSet());
    }
    return keysMultiSetView;
}
项目:HCFCore    文件:PredicatedCollection.java   
/**
 * Create a new predicated multiset filled with the accepted elements.
 * <p>
 * The builder is not modified by this method, so it is possible to create more collections
 * or add more elements afterwards. Further changes will not propagate to the returned multiset.
 *
 * @return a new predicated multiset.
 */
public MultiSet<E> createPredicatedMultiSet() {
    return createPredicatedMultiSet(new HashMultiSet<E>());
}
项目:HCFCore    文件:AbstractMultiSetDecorator.java   
/**
 * Constructor that wraps (not copies).
 *
 * @param multiset  the multiset to decorate, must not be null
 * @throws NullPointerException if multiset is null
 */
protected AbstractMultiSetDecorator(final MultiSet<E> multiset) {
    super(multiset);
}
项目:HCFCore    文件:AbstractMultiSetDecorator.java   
/**
 * Gets the multiset being decorated.
 *
 * @return the decorated multiset
 */
@Override
protected MultiSet<E> decorated() {
    return (MultiSet<E>) super.decorated();
}
项目:HCFCore    文件:SynchronizedMultiSet.java   
/**
 * Factory method to create a synchronized multiset.
 *
 * @param <E> the type of the elements in the multiset
 * @param multiset  the multiset to decorate, must not be null
 * @return a new synchronized MultiSet
 * @throws NullPointerException if multiset is null
 */
public static <E> SynchronizedMultiSet<E> synchronizedMultiSet(final MultiSet<E> multiset) {
    return new SynchronizedMultiSet<E>(multiset);
}
项目:HCFCore    文件:SynchronizedMultiSet.java   
/**
 * Constructor that wraps (not copies).
 *
 * @param multiset  the multiset to decorate, must not be null
 * @throws NullPointerException if multiset is null
 */
protected SynchronizedMultiSet(final MultiSet<E> multiset) {
    super(multiset);
}
项目:HCFCore    文件:SynchronizedMultiSet.java   
/**
 * Constructor that wraps (not copies).
 *
 * @param multiset  the multiset to decorate, must not be null
 * @param lock  the lock to use, must not be null
 * @throws NullPointerException if multiset or lock is null
 */
protected SynchronizedMultiSet(final MultiSet<E> multiset, final Object lock) {
    super(multiset, lock);
}
项目:HCFCore    文件:SynchronizedMultiSet.java   
/**
 * Gets the multiset being decorated.
 *
 * @return the decorated multiset
 */
@Override
protected MultiSet<E> decorated() {
    return (MultiSet<E>) super.decorated();
}