CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-collections--eclipse-collections

A comprehensive collections library for Java delivering productivity and performance through an expressive and efficient set of APIs and types.

Pending
Overview
Eval results
Files

primitive-collections.mddocs/

Primitive Collections

Eclipse Collections provides complete primitive collection APIs for all Java primitive types (boolean, byte, char, short, int, long, float, double). These collections avoid boxing overhead and provide memory-efficient alternatives to object collections.

Capabilities

Overview

Primitive collections are organized in packages under org.eclipse.collections.api and org.eclipse.collections.impl:

  • org.eclipse.collections.api.collection.primitive - Base primitive collection interfaces
  • org.eclipse.collections.api.list.primitive - Primitive list interfaces
  • org.eclipse.collections.api.set.primitive - Primitive set interfaces
  • org.eclipse.collections.api.bag.primitive - Primitive bag interfaces
  • org.eclipse.collections.api.stack.primitive - Primitive stack interfaces
  • org.eclipse.collections.api.map.primitive - Primitive map interfaces
  • org.eclipse.collections.impl.factory.primitive - Factory classes

Base Primitive Interfaces

Foundation interfaces for all primitive collections.

/**
 * Root primitive iterable interface
 */
interface PrimitiveIterable {
    /**
     * Returns the number of elements
     * @return size of collection
     */
    int size();
    
    /**
     * Tests if collection is empty
     * @return true if empty
     */
    boolean isEmpty();
    
    /**
     * Tests if collection is not empty  
     * @return true if not empty
     */
    boolean notEmpty();
    
    /**
     * Convert to array of primitive wrapper objects
     * @return Object array containing wrapper objects
     */
    Object[] toArray();
    
    /**
     * Create string representation
     * @return string representation
     */
    String toString();
}

/**
 * Base mutable primitive collection interface
 */
interface MutablePrimitiveCollection<T> extends PrimitiveIterable {
    /**
     * Remove all elements
     */
    void clear();
    
    /**
     * Add all elements from source
     * @param source source iterable to add from
     * @return true if collection was modified
     */
    boolean addAll(PrimitiveIterable source);
    
    /**
     * Remove all elements from source
     * @param source source iterable to remove from
     * @return true if collection was modified
     */
    boolean removeAll(PrimitiveIterable source);
    
    /**
     * Retain only elements in source
     * @param source source iterable to retain
     * @return true if collection was modified
     */
    boolean retainAll(PrimitiveIterable source);
}

/**
 * Base immutable primitive collection interface
 */
interface ImmutablePrimitiveCollection<T> extends PrimitiveIterable {
    /**
     * Create new collection with element added
     * @param element element to add
     * @return new immutable collection
     */
    ImmutablePrimitiveCollection<T> newWith(T element);
    
    /**
     * Create new collection with element removed
     * @param element element to remove
     * @return new immutable collection
     */
    ImmutablePrimitiveCollection<T> newWithout(T element);
    
    /**
     * Create new collection with all elements added
     * @param elements elements to add
     * @return new immutable collection
     */
    ImmutablePrimitiveCollection<T> newWithAll(PrimitiveIterable elements);
    
    /**
     * Create new collection with all elements removed
     * @param elements elements to remove
     * @return new immutable collection
     */
    ImmutablePrimitiveCollection<T> newWithoutAll(PrimitiveIterable elements);
}

Int Collections (Example for all primitive types)

Complete int collection interfaces - similar patterns exist for all primitive types.

/**
 * Base int iterable providing core int collection operations
 */
interface IntIterable extends PrimitiveIterable {
    /**
     * Returns primitive int iterator
     * @return IntIterator for efficient iteration
     */
    IntIterator intIterator();
    
    /**
     * Execute procedure for each int element
     * @param procedure procedure to execute
     */
    void forEach(IntProcedure procedure);
    
    /**
     * Execute procedure for each element with index
     * @param procedure procedure receiving int and index
     */
    void forEachWithIndex(IntIntProcedure procedure);
    
    // Counting and testing
    /**
     * Count elements matching predicate
     * @param predicate predicate to test
     * @return count of matching elements
     */
    int count(IntPredicate predicate);
    
    /**
     * Test if any element matches predicate
     * @param predicate predicate to test
     * @return true if any match
     */
    boolean anySatisfy(IntPredicate predicate);
    
    /**
     * Test if all elements match predicate
     * @param predicate predicate to test  
     * @return true if all match
     */
    boolean allSatisfy(IntPredicate predicate);
    
    /**
     * Test if no elements match predicate
     * @param predicate predicate to test
     * @return true if none match
     */
    boolean noneSatisfy(IntPredicate predicate);
    
    // Filtering operations
    /**
     * Filter elements matching predicate
     * @param predicate predicate for filtering
     * @return IntIterable with matching elements
     */
    IntIterable select(IntPredicate predicate);
    
    /**
     * Filter elements not matching predicate
     * @param predicate predicate for filtering
     * @return IntIterable with non-matching elements
     */
    IntIterable reject(IntPredicate predicate);
    
    // Transformation operations
    /**
     * Transform each int to an object
     * @param function transformation function
     * @return RichIterable of transformed objects
     */
    <V> RichIterable<V> collect(IntToObjectFunction<? extends V> function);
    
    // Finding operations
    /**
     * Find first element matching predicate
     * @param predicate predicate for finding
     * @return first matching element
     * @throws NoSuchElementException if no match found
     */
    int detectIfNone(IntPredicate predicate, int ifNone);
    
    // Aggregation operations  
    /**
     * Sum all int values
     * @return sum as long to avoid overflow
     */
    long sum();
    
    /**
     * Find minimum int value
     * @return minimum value
     * @throws NoSuchElementException if empty
     */
    int min();
    
    /**
     * Find maximum int value  
     * @return maximum value
     * @throws NoSuchElementException if empty
     */
    int max();
    
    /**
     * Calculate average of all values
     * @return average as double
     */
    double average();
    
    /**
     * Calculate median of all values
     * @return median as double
     */
    double median();
    
    // Conversion operations
    /**
     * Convert to primitive int array
     * @return int array containing all elements
     */
    int[] toArray();
    
    /**
     * Convert to mutable int list
     * @return MutableIntList containing all elements
     */
    MutableIntList toList();
    
    /**
     * Convert to mutable int set
     * @return MutableIntSet containing all elements
     */
    MutableIntSet toSet();
    
    /**
     * Convert to mutable int bag
     * @return MutableIntBag containing all elements
     */
    MutableIntBag toBag();
    
    /**
     * Convert to sorted mutable int list
     * @return sorted MutableIntList
     */
    MutableIntList toSortedList();
    
    // String operations
    /**
     * Create string representation with separator
     * @param separator separator between elements
     * @return string representation
     */
    String makeString(String separator);
    
    /**
     * Create string representation with start, separator, and end
     * @param start starting delimiter
     * @param separator separator between elements  
     * @param end ending delimiter
     * @return string representation
     */
    String makeString(String start, String separator, String end);
    
    // Injection (reduce) operation
    /**
     * Reduce collection to single value using injected value and function
     * @param injectedValue starting value
     * @param function reduction function
     * @return reduced value
     */
    <T> T injectInto(T injectedValue, ObjectIntToObjectFunction<? super T, ? extends T> function);
}

/**
 * Mutable int collection interface
 */
interface MutableIntCollection extends IntIterable, MutablePrimitiveCollection<Integer> {
    // Modification operations
    /**
     * Add int element to collection
     * @param element element to add
     * @return true if collection was modified
     */
    boolean add(int element);
    
    /**
     * Add all int elements to collection
     * @param source array of elements to add
     * @return true if collection was modified
     */
    boolean addAll(int... source);
    
    /**
     * Add all elements from int iterable
     * @param source source iterable
     * @return true if collection was modified
     */
    boolean addAll(IntIterable source);
    
    /**
     * Remove int element from collection
     * @param value element to remove
     * @return true if element was removed
     */
    boolean remove(int value);
    
    /**
     * Remove all specified int elements
     * @param source array of elements to remove
     * @return true if collection was modified
     */
    boolean removeAll(int... source);
    
    /**
     * Remove all elements from int iterable
     * @param source source iterable to remove
     * @return true if collection was modified
     */
    boolean removeAll(IntIterable source);
    
    /**
     * Retain only specified elements
     * @param source array of elements to retain
     * @return true if collection was modified
     */
    boolean retainAll(int... source);
    
    /**
     * Retain only elements from int iterable
     * @param source source iterable to retain
     * @return true if collection was modified
     */
    boolean retainAll(IntIterable source);
    
    // Fluent API methods
    /**
     * Add element and return this collection for chaining
     * @param element element to add
     * @return this collection
     */
    MutableIntCollection with(int element);
    
    /**
     * Remove element and return this collection for chaining
     * @param element element to remove
     * @return this collection
     */
    MutableIntCollection without(int element);
    
    /**
     * Add all elements and return this collection for chaining
     * @param elements elements to add
     * @return this collection
     */
    MutableIntCollection withAll(IntIterable elements);
    
    /**
     * Remove all elements and return this collection for chaining
     * @param elements elements to remove
     * @return this collection
     */
    MutableIntCollection withoutAll(IntIterable elements);
    
    // Mutable transformations return new collections
    MutableIntCollection select(IntPredicate predicate);
    MutableIntCollection reject(IntPredicate predicate);
    <V> MutableCollection<V> collect(IntToObjectFunction<? extends V> function);
    
    // Parallel processing
    ParallelIntIterable asParallel(ExecutorService executorService, int batchSize);
    
    // Immutable view
    ImmutableIntCollection toImmutable();
}

/**
 * Immutable int collection interface
 */
interface ImmutableIntCollection extends IntIterable, ImmutablePrimitiveCollection<Integer> {
    // Immutable modification operations return new collections
    ImmutableIntCollection newWith(int element);
    ImmutableIntCollection newWithout(int element);  
    ImmutableIntCollection newWithAll(IntIterable elements);
    ImmutableIntCollection newWithoutAll(IntIterable elements);
    
    // Immutable transformations
    ImmutableIntCollection select(IntPredicate predicate);
    ImmutableIntCollection reject(IntPredicate predicate);
    <V> ImmutableCollection<V> collect(IntToObjectFunction<? extends V> function);
}

Int List Interface

Indexed int collections providing list-specific operations.

/**
 * Mutable int list providing indexed access
 */
interface MutableIntList extends MutableIntCollection {
    // Indexed access operations
    /**
     * Get int element at specified index
     * @param index index of element
     * @return element at index
     * @throws IndexOutOfBoundsException if index invalid
     */
    int get(int index);
    
    /**
     * Set int element at specified index
     * @param index index to set
     * @param element new element value
     * @return previous element at index
     * @throws IndexOutOfBoundsException if index invalid
     */
    int set(int index, int element);
    
    /**
     * Add int element at specified index
     * @param index index to add at
     * @param element element to add
     * @throws IndexOutOfBoundsException if index invalid
     */
    void addAtIndex(int index, int element);
    
    /**
     * Remove int element at specified index  
     * @param index index to remove
     * @return removed element
     * @throws IndexOutOfBoundsException if index invalid
     */
    int removeAtIndex(int index);
    
    // Search operations
    /**
     * Find first index of element
     * @param value element to find
     * @return index of element or -1 if not found
     */
    int indexOf(int value);
    
    /**
     * Find last index of element
     * @param value element to find  
     * @return last index of element or -1 if not found
     */
    int lastIndexOf(int value);
    
    // In-place operations
    /**
     * Sort this list in place
     * @return this list for chaining
     */
    MutableIntList sortThis();
    
    /**
     * Reverse this list in place
     * @return this list for chaining
     */
    MutableIntList reverseThis();
    
    /**
     * Shuffle this list in place
     * @return this list for chaining
     */
    MutableIntList shuffleThis();
    
    /**
     * Shuffle this list with specified random
     * @param rnd Random instance for shuffling
     * @return this list for chaining
     */
    MutableIntList shuffleThis(Random rnd);
    
    // List-specific transformations
    MutableIntList select(IntPredicate predicate);
    MutableIntList reject(IntPredicate predicate);
    <V> MutableList<V> collect(IntToObjectFunction<? extends V> function);
    
    // Fluent API
    MutableIntList with(int element);
    MutableIntList without(int element);
    MutableIntList withAll(IntIterable elements);
    MutableIntList withoutAll(IntIterable elements);
    
    // Sublist operations
    /**
     * Get sublist view
     * @param fromIndex starting index (inclusive)
     * @param toIndex ending index (exclusive)
     * @return MutableIntList view of sublist
     */
    MutableIntList subList(int fromIndex, int toIndex);
    
    // Immutable conversion
    ImmutableIntList toImmutable();
}

/**
 * Immutable int list interface
 */
interface ImmutableIntList extends ImmutableIntCollection {
    // Indexed access (read-only)
    int get(int index);
    int indexOf(int value);
    int lastIndexOf(int value);
    
    // Immutable modifications
    ImmutableIntList newWith(int element);
    ImmutableIntList newWithout(int element);
    ImmutableIntList newWithAll(IntIterable elements);
    ImmutableIntList newWithoutAll(IntIterable elements);
    
    // Immutable transformations
    ImmutableIntList select(IntPredicate predicate);
    ImmutableIntList reject(IntPredicate predicate);
    <V> ImmutableList<V> collect(IntToObjectFunction<? extends V> function);
    
    // Sublist
    ImmutableIntList subList(int fromIndex, int toIndex);
}

Int Set Interface

Unique int collections providing set operations.

/**
 * Mutable int set providing unique int elements
 */
interface MutableIntSet extends MutableIntCollection {
    // Set-specific operations
    /**
     * Test if element is contained in set
     * @param value element to test
     * @return true if contained
     */
    boolean contains(int value);
    
    /**
     * Test if all elements are contained in set
     * @param source elements to test
     * @return true if all contained
     */
    boolean containsAll(int... source);
    
    /**
     * Test if all elements from iterable are contained
     * @param source elements to test
     * @return true if all contained
     */
    boolean containsAll(IntIterable source);
    
    // Set algebra operations (return new sets)
    /**
     * Compute union with another int set
     * @param set other set
     * @return new MutableIntSet containing union
     */
    MutableIntSet union(IntSet set);
    
    /**
     * Compute intersection with another int set  
     * @param set other set
     * @return new MutableIntSet containing intersection
     */
    MutableIntSet intersect(IntSet set);
    
    /**
     * Compute difference with another int set
     * @param subtrahend set to subtract
     * @return new MutableIntSet containing difference  
     */
    MutableIntSet difference(IntSet subtrahend);
    
    /**
     * Compute symmetric difference with another int set
     * @param set other set
     * @return new MutableIntSet containing symmetric difference
     */
    MutableIntSet symmetricDifference(IntSet set);
    
    // Set transformations
    MutableIntSet select(IntPredicate predicate);
    MutableIntSet reject(IntPredicate predicate);
    <V> MutableSet<V> collect(IntToObjectFunction<? extends V> function);
    
    // Fluent API
    MutableIntSet with(int element);
    MutableIntSet without(int element);
    MutableIntSet withAll(IntIterable elements);
    MutableIntSet withoutAll(IntIterable elements);
    
    // Immutable conversion
    ImmutableIntSet toImmutable();
}

/**
 * Immutable int set interface
 */
interface ImmutableIntSet extends ImmutableIntCollection {
    // Set operations
    boolean contains(int value);
    boolean containsAll(int... source);
    boolean containsAll(IntIterable source);
    
    // Immutable set algebra
    ImmutableIntSet union(IntSet set);
    ImmutableIntSet intersect(IntSet set);
    ImmutableIntSet difference(IntSet subtrahend);
    ImmutableIntSet symmetricDifference(IntSet set);
    
    // Immutable modifications
    ImmutableIntSet newWith(int element);
    ImmutableIntSet newWithout(int element);
    ImmutableIntSet newWithAll(IntIterable elements);
    ImmutableIntSet newWithoutAll(IntIterable elements);
    
    // Immutable transformations
    ImmutableIntSet select(IntPredicate predicate);
    ImmutableIntSet reject(IntPredicate predicate);
    <V> ImmutableSet<V> collect(IntToObjectFunction<? extends V> function);
}

Int Bag Interface

Multi-set int collections allowing duplicates with occurrence counting.

/**
 * Mutable int bag (multiset) allowing duplicate elements with counts
 */
interface MutableIntBag extends MutableIntCollection {
    /**
     * Get occurrence count of element
     * @param item element to count
     * @return number of occurrences
     */
    int occurrencesOf(int item);
    
    /**
     * Get number of distinct elements
     * @return count of unique elements
     */
    int sizeDistinct();
    
    /**
     * Add multiple occurrences of element
     * @param item element to add
     * @param occurrences number of occurrences to add
     */
    void addOccurrences(int item, int occurrences);
    
    /**
     * Remove occurrences of element
     * @param item element to remove occurrences of
     * @param occurrences number of occurrences to remove
     * @return true if any were removed
     */
    boolean removeOccurrences(int item, int occurrences);
    
    /**
     * Set exact occurrence count of element
     * @param item element to set count for
     * @param occurrences target occurrence count
     */
    void setOccurrences(int item, int occurrences);
    
    /**
     * Convert to map of items to their occurrence counts
     * @return MutableObjectIntMap with item->count mappings
     */
    MutableObjectIntMap<Integer> toMapOfItemToCount();
    
    // Bag transformations
    MutableIntBag select(IntPredicate predicate);
    MutableIntBag reject(IntPredicate predicate);
    <V> MutableBag<V> collect(IntToObjectFunction<? extends V> function);
    
    // Fluent API
    MutableIntBag with(int element);
    MutableIntBag without(int element);
    MutableIntBag withAll(IntIterable elements);
    MutableIntBag withoutAll(IntIterable elements);
    
    // Immutable conversion
    ImmutableIntBag toImmutable();
}

/**
 * Immutable int bag interface
 */
interface ImmutableIntBag extends ImmutableIntCollection {
    // Bag-specific operations (read-only)
    int occurrencesOf(int item);
    int sizeDistinct();
    MutableObjectIntMap<Integer> toMapOfItemToCount();
    
    // Immutable modifications
    ImmutableIntBag newWith(int element);
    ImmutableIntBag newWithout(int element);
    ImmutableIntBag newWithAll(IntIterable elements);
    ImmutableIntBag newWithoutAll(IntIterable elements);
    
    // Immutable transformations
    ImmutableIntBag select(IntPredicate predicate);
    ImmutableIntBag reject(IntPredicate predicate);
    <V> ImmutableBag<V> collect(IntToObjectFunction<? extends V> function);
}

Int Stack Interface

LIFO (Last In, First Out) int collections.

/**
 * Mutable int stack providing LIFO access
 */
interface MutableIntStack extends MutableIntCollection {
    /**
     * Push element onto top of stack
     * @param item element to push
     */
    void push(int item);
    
    /**
     * Pop element from top of stack
     * @return top element
     * @throws EmptyStackException if empty
     */
    int pop();
    
    /**
     * Pop multiple elements from stack
     * @param count number of elements to pop
     * @return MutableIntList containing popped elements in order
     */
    MutableIntList pop(int count);
    
    /**
     * Peek at top element without removing
     * @return top element
     * @throws EmptyStackException if empty
     */
    int peek();
    
    /**
     * Peek at multiple top elements without removing
     * @param count number of elements to peek
     * @return MutableIntList containing top elements
     */
    MutableIntList peek(int count);
    
    /**
     * Peek at element at specified distance from top
     * @param index distance from top (0 = top element)
     * @return element at specified distance
     */
    int peekAt(int index);
    
    // Stack transformations
    MutableIntStack select(IntPredicate predicate);
    MutableIntStack reject(IntPredicate predicate);
    <V> MutableStack<V> collect(IntToObjectFunction<? extends V> function);
    
    // Immutable conversion
    ImmutableIntStack toImmutable();
}

/**
 * Immutable int stack interface
 */
interface ImmutableIntStack extends ImmutableIntCollection {
    // Stack operations (read-only)
    int peek();
    MutableIntList peek(int count);
    int peekAt(int index);
    
    // Immutable stack operations (return new stacks)
    ImmutableIntStack push(int item);
    ImmutableIntStack pop();
    ImmutableIntStack pop(int count);
    
    // Immutable modifications
    ImmutableIntStack newWith(int element);
    ImmutableIntStack newWithout(int element);
    ImmutableIntStack newWithAll(IntIterable elements);
    ImmutableIntStack newWithoutAll(IntIterable elements);
    
    // Immutable transformations
    ImmutableIntStack select(IntPredicate predicate);
    ImmutableIntStack reject(IntPredicate predicate);
    <V> ImmutableStack<V> collect(IntToObjectFunction<? extends V> function);
}

Primitive Map Interfaces

Maps involving primitive keys and/or values.

/**
 * Map from Object keys to int values
 */
interface ObjectIntMap<K> extends IntIterable {
    // Map operations
    /**
     * Get int value for key
     * @param key key to lookup
     * @return int value for key
     */
    int get(Object key);
    
    /**
     * Get int value for key or return default if not found
     * @param key key to lookup
     * @param ifAbsent default value if key not found
     * @return int value for key or default
     */
    int getIfAbsent(Object key, int ifAbsent);
    
    /**
     * Test if map contains key
     * @param key key to test
     * @return true if key is contained
     */
    boolean containsKey(Object key);
    
    /**
     * Test if map contains value
     * @param value value to test
     * @return true if value is contained
     */
    boolean containsValue(int value);
    
    // Views
    /**
     * Get view of all keys
     * @return RichIterable of keys
     */
    RichIterable<K> keysView();
    
    /**
     * Get view of all values as IntIterable
     * @return IntIterable of values
     */
    IntIterable valuesView();
    
    /**
     * Get view of key-value pairs
     * @return RichIterable of ObjectIntPair entries
     */
    RichIterable<ObjectIntPair<K>> keyValuesView();
    
    // Conversion
    /**
     * Convert to regular map with Integer values
     * @return MutableMap with Integer values
     */
    MutableMap<K, Integer> toMap();
}

/**
 * Mutable Object-to-int map
 */
interface MutableObjectIntMap<K> extends ObjectIntMap<K> {
    // Modification operations
    /**
     * Put key-value pair
     * @param key key to put
     * @param value int value to associate
     * @return previous value or 0 if no previous mapping
     */
    int put(K key, int value);
    
    /**
     * Put key-value pair only if key is not present
     * @param key key to put
     * @param value int value to associate
     * @return previous value or 0 if no previous mapping
     */
    int putIfAbsent(K key, int value);
    
    /**
     * Get value for key, putting and returning default if absent
     * @param key key to get/put
     * @param value default value to put if absent
     * @return existing value or the default value that was put
     */
    int getIfAbsentPut(K key, int value);
    
    /**
     * Get value for key, computing and putting if absent
     * @param key key to get/put
     * @param function function to compute value if absent
     * @return existing value or computed value that was put
     */
    int getIfAbsentPut(K key, IntFunction0 function);
    
    /**
     * Update value for key using factory and update function
     * @param key key to update
     * @param factory function to create initial value if key absent
     * @param function function to update existing value
     * @return updated value
     */
    int updateValue(K key, IntFunction0 factory, IntToIntFunction function);
    
    /**
     * Remove mapping for key
     * @param key key to remove
     * @return previous value or 0 if no mapping existed
     */
    int removeKey(Object key);
    
    /**
     * Remove mapping for key only if it maps to specified value
     * @param key key to remove
     * @param value value that must be mapped to key
     * @return true if mapping was removed
     */
    boolean remove(Object key, int value);
    
    // Bulk operations
    /**
     * Add value to existing mapping, putting initial value if key absent
     * @param key key to add to
     * @param toBeAdded value to add
     * @param initialValueIfAbsent initial value if key not present
     * @return updated value after addition
     */
    int addToValue(K key, int toBeAdded, int initialValueIfAbsent);
    
    /**
     * Put all mappings from another ObjectIntMap
     * @param map map to copy from
     */
    void putAll(ObjectIntMap<? extends K> map);
    
    // Fluent API
    MutableObjectIntMap<K> withKeyValue(K key, int value);
    MutableObjectIntMap<K> withoutKey(K key);
    MutableObjectIntMap<K> withoutAllKeys(Iterable<? extends K> keys);
    
    // Transformations
    MutableObjectIntMap<K> select(ObjectIntPredicate<? super K> predicate);
    MutableObjectIntMap<K> reject(ObjectIntPredicate<? super K> predicate);
    
    // Immutable conversion
    ImmutableObjectIntMap<K> toImmutable();
}

/**
 * Map from int keys to Object values  
 */
interface IntObjectMap<V> extends RichIterable<V> {
    // Map operations
    V get(int key);
    V getIfAbsent(int key, V ifAbsent);
    boolean containsKey(int key);
    boolean containsValue(Object value);
    
    // Views
    IntIterable keysView();
    RichIterable<V> valuesView();  
    RichIterable<IntObjectPair<V>> keyValuesView();
    
    // Size operations
    int size();
    boolean isEmpty();
}

/**
 * Mutable int-to-Object map
 */
interface MutableIntObjectMap<V> extends IntObjectMap<V> {
    // Modification operations
    V put(int key, V value);
    V putIfAbsent(int key, V value);
    V getIfAbsentPut(int key, V value);
    V getIfAbsentPut(int key, Function0<? extends V> function);
    <P> V getIfAbsentPutWith(int key, Function<? super P, ? extends V> function, P parameter);
    V updateValue(int key, Function0<? extends V> factory, Function<? super V, ? extends V> function);
    <P> V updateValueWith(int key, Function0<? extends V> factory, Function2<? super V, ? super P, ? extends V> function, P parameter);
    
    V remove(int key);
    boolean remove(int key, Object value);
    
    // Bulk operations  
    void putAll(IntObjectMap<? extends V> map);
    
    // Fluent API
    MutableIntObjectMap<V> withKeyValue(int key, V value);
    MutableIntObjectMap<V> withoutKey(int key);
    MutableIntObjectMap<V> withoutAllKeys(IntIterable keys);
    
    // Transformations
    MutableIntObjectMap<V> select(IntObjectPredicate<? super V> predicate);
    MutableIntObjectMap<V> reject(IntObjectPredicate<? super V> predicate);
    <V2> MutableIntObjectMap<V2> collectValues(Function<? super V, ? extends V2> function);
    
    // Immutable conversion
    ImmutableIntObjectMap<V> toImmutable();
}

/**
 * Map from int keys to int values
 */
interface IntIntMap extends IntIterable {
    // Map operations
    int get(int key);
    int getIfAbsent(int key, int ifAbsent);
    boolean containsKey(int key);
    boolean containsValue(int value);
    
    // Views
    IntIterable keysView();
    IntIterable valuesView();
    RichIterable<IntIntPair> keyValuesView();
    
    // Size operations  
    int size();
    boolean isEmpty();
}

/**
 * Mutable int-to-int map
 */
interface MutableIntIntMap extends IntIntMap {
    // Modification operations
    int put(int key, int value);
    int putIfAbsent(int key, int value);
    int getIfAbsentPut(int key, int value);
    int getIfAbsentPut(int key, IntFunction0 function);
    int updateValue(int key, IntFunction0 factory, IntToIntFunction function);
    int addToValue(int key, int toBeAdded, int initialValueIfAbsent);
    
    int remove(int key);
    boolean remove(int key, int value);
    
    // Bulk operations
    void putAll(IntIntMap map);
    
    // Fluent API  
    MutableIntIntMap withKeyValue(int key, int value);
    MutableIntIntMap withoutKey(int key);
    MutableIntIntMap withoutAllKeys(IntIterable keys);
    
    // Transformations
    MutableIntIntMap select(IntIntPredicate predicate);
    MutableIntIntMap reject(IntIntPredicate predicate);
    
    // Immutable conversion
    ImmutableIntIntMap toImmutable();
}

Primitive Factory Classes

Factory classes for creating primitive collections.

/**
 * Factory for creating int lists
 */
public final class IntLists {
    public static final ImmutableIntListFactory immutable;
    public static final MutableIntListFactory mutable;
}

interface MutableIntListFactory {
    MutableIntList empty();
    MutableIntList with(int... elements);
    MutableIntList withAll(IntIterable items);
    MutableIntList withInitialCapacity(int initialCapacity);
}

interface ImmutableIntListFactory {
    ImmutableIntList empty();
    ImmutableIntList of(int... elements);
    ImmutableIntList ofAll(IntIterable items);
}

/**
 * Factory for creating int sets
 */
public final class IntSets {
    public static final ImmutableIntSetFactory immutable;
    public static final MutableIntSetFactory mutable;
}

/**
 * Factory for creating int bags
 */
public final class IntBags {
    public static final ImmutableIntBagFactory immutable;
    public static final MutableIntBagFactory mutable;
}

/**
 * Factory for creating int stacks
 */
public final class IntStacks {
    public static final ImmutableIntStackFactory immutable;
    public static final MutableIntStackFactory mutable;
}

/**
 * Factory for creating Object-to-int maps
 */
public final class ObjectIntMaps {
    public static final ImmutableObjectIntMapFactory immutable;
    public static final MutableObjectIntMapFactory mutable;
}

/**
 * Factory for creating int-to-Object maps
 */
public final class IntObjectMaps {
    public static final ImmutableIntObjectMapFactory immutable;
    public static final MutableIntObjectMapFactory mutable;
}

/**
 * Factory for creating int-to-int maps  
 */
public final class IntIntMaps {
    public static final ImmutableIntIntMapFactory immutable;
    public static final MutableIntIntMapFactory mutable;
}

Primitive Tuples

Tuple types for primitive combinations.

/**
 * Factory for creating primitive tuples
 */
public final class PrimitiveTuples {
    // Object-Primitive pairs
    public static <T> ObjectIntPair<T> pair(T one, int two);
    public static <T> ObjectBooleanPair<T> pair(T one, boolean two);
    public static <T> ObjectBytePair<T> pair(T one, byte two);
    public static <T> ObjectCharPair<T> pair(T one, char two);
    public static <T> ObjectDoublePair<T> pair(T one, double two);
    public static <T> ObjectFloatPair<T> pair(T one, float two);
    public static <T> ObjectLongPair<T> pair(T one, long two);
    public static <T> ObjectShortPair<T> pair(T one, short two);
    
    // Primitive-Object pairs
    public static <T> IntObjectPair<T> pair(int one, T two);
    public static <T> BooleanObjectPair<T> pair(boolean one, T two);
    public static <T> ByteObjectPair<T> pair(byte one, T two);
    public static <T> CharObjectPair<T> pair(char one, T two);
    public static <T> DoubleObjectPair<T> pair(double one, T two);
    public static <T> FloatObjectPair<T> pair(float one, T two);
    public static <T> LongObjectPair<T> pair(long one, T two);
    public static <T> ShortObjectPair<T> pair(short one, T two);
    
    // Primitive-Primitive pairs
    public static IntIntPair pair(int one, int two);
    public static BooleanBooleanPair pair(boolean one, boolean two);
    public static ByteBytePair pair(byte one, byte two);
    public static CharCharPair pair(char one, char two);
    public static DoubleDoublePair pair(double one, double two);
    public static FloatFloatPair pair(float one, float two);
    public static LongLongPair pair(long one, long two);
    public static ShortShortPair pair(short one, short two);
}

/**
 * Pair containing Object and int
 */
interface ObjectIntPair<T> {
    T getOne();
    int getTwo();
}

/**
 * Pair containing int and Object  
 */
interface IntObjectPair<T> {
    int getOne();
    T getTwo();
}

/**
 * Pair containing two ints
 */
interface IntIntPair {
    int getOne();
    int getTwo();
}

Usage Examples

Creating Primitive Collections:

import org.eclipse.collections.impl.factory.primitive.IntLists;
import org.eclipse.collections.impl.factory.primitive.IntSets;
import org.eclipse.collections.impl.factory.primitive.IntBags;

// Create primitive lists
MutableIntList numbers = IntLists.mutable.with(1, 2, 3, 4, 5);
ImmutableIntList immutableNumbers = IntLists.immutable.of(10, 20, 30);

// Create primitive sets
MutableIntSet uniqueNumbers = IntSets.mutable.with(1, 2, 2, 3, 3, 3); // [1, 2, 3]
ImmutableIntSet immutableSet = IntSets.immutable.of(100, 200, 300);

// Create primitive bags  
MutableIntBag numberCounts = IntBags.mutable.with(1, 1, 2, 2, 2, 3);
// 1 appears 2 times, 2 appears 3 times, 3 appears 1 time

Functional Operations:

import org.eclipse.collections.api.block.predicate.primitive.IntPredicate;
import org.eclipse.collections.api.block.function.primitive.IntToObjectFunction;

MutableIntList numbers = IntLists.mutable.with(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

// Filtering with predicates
IntPredicate isEven = i -> i % 2 == 0;
MutableIntList evenNumbers = numbers.select(isEven); // [2, 4, 6, 8, 10]
MutableIntList oddNumbers = numbers.reject(isEven);  // [1, 3, 5, 7, 9]

// Transformation to objects  
IntToObjectFunction<String> intToString = i -> "Number: " + i;
MutableList<String> strings = numbers.collect(intToString);

// Aggregation operations
long sum = numbers.sum();           // 55
int max = numbers.max();            // 10
int min = numbers.min();            // 1
double average = numbers.average(); // 5.5

// Testing operations
boolean hasEven = numbers.anySatisfy(isEven);  // true
boolean allPositive = numbers.allSatisfy(i -> i > 0); // true
int evenCount = numbers.count(isEven); // 5

Primitive Maps:

import org.eclipse.collections.impl.factory.primitive.ObjectIntMaps;
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps;

// Object-to-int maps
MutableObjectIntMap<String> wordCounts = ObjectIntMaps.mutable.empty();
wordCounts.put("hello", 5);
wordCounts.put("world", 3);
wordCounts.addToValue("hello", 2, 0); // Add 2 to existing value: 5 + 2 = 7

int helloCount = wordCounts.get("hello"); // 7
int unknownCount = wordCounts.getIfAbsent("unknown", 0); // 0

// Int-to-Object maps
MutableIntObjectMap<String> idToName = IntObjectMaps.mutable.empty();
idToName.put(1, "Alice");
idToName.put(2, "Bob");
idToName.put(3, "Charlie");

String name = idToName.get(2); // "Bob"
String defaultName = idToName.getIfAbsent(999, "Unknown"); // "Unknown"

// Int-to-int maps
MutableIntIntMap squares = IntIntMaps.mutable.empty();
squares.put(1, 1);
squares.put(2, 4);
squares.put(3, 9);
squares.put(4, 16);

int squareOfThree = squares.get(3); // 9

Performance Benefits

Primitive collections provide significant performance advantages:

  1. Memory Efficiency: No boxing overhead - int uses 4 bytes vs Integer using ~16 bytes
  2. CPU Performance: Direct primitive operations without object allocation
  3. Garbage Collection: Reduced GC pressure from fewer object allocations
  4. Cache Locality: Better CPU cache utilization with primitive arrays

Performance Example:

// Object collection - creates Integer objects
MutableList<Integer> objectList = Lists.mutable.empty();
for (int i = 0; i < 1_000_000; i++) {
    objectList.add(i); // Boxing: int -> Integer
}
int sum1 = objectList.sumOfInt(Integer::intValue); // Unboxing required

// Primitive collection - no boxing
MutableIntList primitiveList = IntLists.mutable.empty();
for (int i = 0; i < 1_000_000; i++) {
    primitiveList.add(i); // Direct primitive storage
}
long sum2 = primitiveList.sum(); // Direct primitive operation

The primitive version uses ~4x less memory and runs significantly faster due to eliminating boxing/unboxing operations.

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-collections--eclipse-collections

docs

advanced-features.md

core-interfaces.md

factory-methods.md

functional-programming.md

index.md

primitive-collections.md

tile.json