Module inet.ipaddr

Interface AddressComponentRangeSpliterator<S extends AddressComponentRange,T>

Type Parameters:
T -
All Superinterfaces:
Spliterator<T>
All Known Subinterfaces:
AddressComponentSpliterator<T>

public interface AddressComponentRangeSpliterator<S extends AddressComponentRange,T> extends Spliterator<T>
AddressComponentSpliterator is a Spliterator for address items.

The implementation of estimateSize() and getExactSizeIfKnown() provide exact sizes if the size is no larger than Long.MAX_VALUE. It also provides a getSize() method returning BigInteger providing the exact size at all times.

An AddressComponentSpliterator instance has the spliterator characteristics of being concurrent, non-null, sorted, ordered, and distinct. When the size is no larger than Long.MAX_VALUE, it is also sized and sub-sized, but practically speaking it is actually always sized and sub-sized since the exact size as a BigInteger is always available from getSize(), which is not a part of the Spliterator interface.

Unlike the default spliterator that you get with any iterator, which has linear-time splitting, all instances of AddressItemRangeSpliterator split in constant-time, therefore allowing for instant parallel iteration over subnets or subnet components.

Splitting can be attempted at any time, including after iteration has started. All spliterators will split the address component range roughly in half. Segment spliterators will split the remaining range exactly in half. Other spliterators will split the original range roughly in half.

An instance of AddressItemRangeSpliterator is not thread-safe. Parallel iteration derives from handing each additional AddressItemRangeSpliterator returned from trySplit() to other threads.

Author:
seancfoley
  • Method Details

    • getSize

      BigInteger getSize()
      Returns an exact count of the number of elements that would be encountered by a Spliterator.forEachRemaining(java.util.function.Consumer<? super T>) traversal.
      Returns:
    • getAddressItem

      S getAddressItem()
      Returns:
      the item corresponding to this spliterator when it was last split or created
    • trySplit

      If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

      The returned Spliterator will cover a strict prefix of the elements, preserving the ordering of the address items.

      Repeated calls to trySplit() will eventually return null. Upon non-null return, the sizes of the new spliterator and this spliterator as given by getSize() will add up to the size of this spliterator before splitting.

      The remaining elements of segment spliterators will be divided exactly in half.

      Other address item spliterators divide the original address item roughly in half, not the remaining elements. Because the original address item is divided instead of dividing the remaining elements, the resulting spliterators will not be roughly equal in size if a disproportionate amount of traversing using Spliterator.tryAdvance(java.util.function.Consumer) occurred before splitting. In fact, the splitting will not happen at all if half the elements have already been traversed.

      Specified by:
      trySplit in interface Spliterator<S extends AddressComponentRange>
      Returns:
      a Spliterator covering some portion of the elements, or null if this spliterator cannot be split
    • getComparator

      default Comparator<? super T> getComparator()
      Specified by:
      getComparator in interface Spliterator<S extends AddressComponentRange>