Search in sources :

Example 11 with Counter

use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.

the class ListIterateTest method assertReverseForEachWithIndex.

private void assertReverseForEachWithIndex(List<Integer> list) {
    Counter counter = new Counter();
    ListIterate.reverseForEachWithIndex(list, (object, index) -> {
        Assert.assertEquals(counter.getCount() + 1, object.longValue());
        Assert.assertEquals(4 - counter.getCount(), index);
        counter.increment();
    });
}
Also used : Counter(org.eclipse.collections.impl.Counter)

Example 12 with Counter

use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.

the class AbstractBag method count.

@Override
public int count(Predicate<? super T> predicate) {
    Counter result = new Counter();
    this.forEachWithOccurrences((each, occurrences) -> {
        if (predicate.accept(each)) {
            result.add(occurrences);
        }
    });
    return result.getCount();
}
Also used : Counter(org.eclipse.collections.impl.Counter)

Example 13 with Counter

use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.

the class ImmutableSortedBagImpl method hashCode.

@Override
public int hashCode() {
    Counter counter = new Counter();
    this.forEachWithOccurrences((each, count) -> counter.add((each == null ? 0 : each.hashCode()) ^ count));
    return counter.getCount();
}
Also used : Counter(org.eclipse.collections.impl.Counter)

Example 14 with Counter

use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.

the class TreeBag method addOccurrences.

@Override
public int addOccurrences(T item, int occurrences) {
    if (occurrences < 0) {
        throw new IllegalArgumentException("Cannot add a negative number of occurrences");
    }
    if (occurrences > 0) {
        Counter counter = this.items.getIfAbsentPut(item, Counter::new);
        counter.add(occurrences);
        this.size += occurrences;
        return counter.getCount();
    }
    return this.occurrencesOf(item);
}
Also used : Counter(org.eclipse.collections.impl.Counter)

Example 15 with Counter

use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.

the class TreeBag method add.

@Override
public boolean add(T item) {
    Counter counter = this.items.getIfAbsentPut(item, Counter::new);
    counter.increment();
    this.size++;
    return true;
}
Also used : Counter(org.eclipse.collections.impl.Counter)

Aggregations

Counter (org.eclipse.collections.impl.Counter)25 Test (org.junit.Test)10 MutableList (org.eclipse.collections.api.list.MutableList)6 NoSuchElementException (java.util.NoSuchElementException)5 Function (org.eclipse.collections.api.block.function.Function)5 Predicates (org.eclipse.collections.impl.block.factory.Predicates)5 Procedures (org.eclipse.collections.impl.block.factory.Procedures)5 FastList (org.eclipse.collections.impl.list.mutable.FastList)5 Collections (java.util.Collections)4 Iterator (java.util.Iterator)4 RichIterable (org.eclipse.collections.api.RichIterable)4 TreeBag (org.eclipse.collections.impl.bag.sorted.mutable.TreeBag)4 Lists (org.eclipse.collections.impl.factory.Lists)4 Interval (org.eclipse.collections.impl.list.Interval)4 Assert (org.junit.Assert)4 Map (java.util.Map)3 LazyIterable (org.eclipse.collections.api.LazyIterable)3 MutableSortedBag (org.eclipse.collections.api.bag.sorted.MutableSortedBag)3 MutableSortedMap (org.eclipse.collections.api.map.sorted.MutableSortedMap)3 TreeSortedMap (org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap)3