Skip to content
mihxilPublic

About

java.util

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

java.util extensions

Build Status Maven Central codecov javadoc

Functional extensions

Classes related to java.util.Function and extensions like Predicate, Consumer and Supplier.

  • TriFunction, QuadriFunction

  • TriConsumer

  • TriPredicate

  • Morphing methods like

    • TriFunction#ignoreArg[1-4](…​) morphs a TriFunction to a QuadriFunction

    • TriFunction#withArg[1-3](…​) morphs a TriFunction to a BiFunction.

  • Utilities for that in

    • Functions

    • Consumers

    • Predicates,

    • Suppliers

      Things like memoize (to memoize the value of a supplier), closeable (to make a Supplier AutoCloseable) and ignoreArg (to morph a Supplier to a Function that ignores the argument) are provided.

  • Consistent equals and hashCode, for the utility functions that produce functional implementations. E.g. the above mentioned ignoreArg* and withArg* are not simply implemented with lambda’s, but also with equals and hashcode based on the source functional class implementation.

Collections

The mihxil-collections module (since 1.18) contains utilities for java.util.Iterator and java.util.Collection, in package org.meeuw.collections. Most of them originate from vpro-shared-util.

Iterator interfaces

  • CloseableIterator: an Iterator that is also AutoCloseable. CloseableIterator.of(iterator) wraps any iterator (closing it if it is AutoCloseable itself).

  • PeekingIterator: an iterator with a one-element lookahead (peek()), like guava’s, but without the dependency.

  • CountedIterator: an iterator that knows its current position (getCount()), and optionally the size of what it iterates (getSize()) and of some 'total' (getTotalSize()), e.g. when it represents a page of a larger result.

  • Combinations of these: CloseablePeekingIterator, CountedPeekingIterator.

  • CloseableSpliterator: a Spliterator owning a closeable resource.

Iterator implementations

Most of these are wrappers around another iterator, and can be constructed with a (lombok generated) builder.

  • BatchedReceiver: presents an API that only supports batched retrieval (paging with offset/max, or some 'resumption token') as one simple Iterator.

    Iterator<String> i = BatchedReceiver.<String>builder()
        .batchGetter((offset, max) -> apiClient.getPage(offset, max).iterator())
        .batchSize(100)
        .build();
  • MaxOffsetIterator, CountedMaxOffsetIterator: implements 'offset' and 'max' on top of another iterator.

    MaxOffsetIterator<String> i = MaxOffsetIterator.<String>builder()
        .wrapped(iterator)
        .offset(10)
        .max(20)
        .build();
  • FilteringIterator: filters an iterator with a predicate, with optional 'keep alive' callbacks for when many consecutive elements are filtered out.

  • TransformingIterator: maps the elements of an iterator with a function.

  • SkippingIterator: skips elements based on comparison with the previous one (e.g. to remove consecutive duplicates).

  • HeadAdder, TailAdder: add elements at the start or at the end of an iterator (the latter possibly based on the last element).

  • MergedSortedIterator: merges several sorted iterators into one sorted iterator. merge(…​) uses a priority queue, mergeInSameThread(…​) doesn’t (so it is also usable with e.g. Hibernate).

  • LazyIterator: wraps a Supplier<Iterator>, delaying creation of the actual iterator until it is first used.

  • CallbackIterator: calls a callback when iteration is finished.

  • WrappedIterator, BasicWrappedIterator: base classes for iterators wrapping another one.

Collection wrappers

Release history

Version date remarks

2.0

2026-10

Optional<Long> results were replaced by OptionaLong, which is not backwards compatible (only in new collections module)

1.18

2026-08

Having collection module too.

1.17

2026-03

For the 'Throwing-' functional interfaces, there are now also overridden verison of the 'withArgN' and 'ignoreArgN' morphing methods, that remain 'Throwing-' functional interfaces, and throw the same exception as the original functional interface.

1.12

2025-06-26

A.o, introduction of 'CloseableSupplier' and 'UnwrappableSupplier' interfaces,

1.11

2024-05-11

1.10

2023-12

1.0

2020-11-30

About

java.util

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages