Class MaskedLongIterator

  • All Implemented Interfaces:
    LazyLongIterator

    public class MaskedLongIterator
    extends java.lang.Object
    implements LazyLongIterator
    An iterator returning the element of an underlying iterator but filters them using a inclusion-exclusion block list.

    A mask is an array of integers. The sum of the values contained in the mask must not exceed the number of elements returned by the underlying iterator. Moreover, all integers in the mask must be positive, except possibly for the first one, which may be zero.

    Mask values are interpreted as specifying inclusion-exclusion blocks. Suppose that the underlying iterator returns N values, and that the mask is n0, n1, …, nk. Then, the first n0 values returned by the underlying iterator must be kept, the next n1 values must be ignored, the next n2 must be kept and so on. The last N−(n0+…+nk) must be kept if k is odd, and must be ignored otherwise. An instance of this class will returns the kept values only, in increasing order.

    • Constructor Summary

      Constructors 
      Constructor Description
      MaskedLongIterator​(long[] mask, int maskLen, LazyLongIterator underlying)
      Creates a new masked iterator using a given mask, mask length and underlying iterator.
      MaskedLongIterator​(long[] mask, LazyLongIterator underlying)
      Creates a new masked iterator using a given mask and underlying iterator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long nextLong()
      The next long returned by this iterator, or the special marker if this iterator is exhausted.
      long skip​(long n)
      Skips a given number of elements.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MaskedLongIterator

        public MaskedLongIterator​(long[] mask,
                                  LazyLongIterator underlying)
        Creates a new masked iterator using a given mask and underlying iterator.
        Parameters:
        mask - a mask, or null, meaning an empty mask (everything is copied).
        underlying - an underlying iterator.
      • MaskedLongIterator

        public MaskedLongIterator​(long[] mask,
                                  int maskLen,
                                  LazyLongIterator underlying)
        Creates a new masked iterator using a given mask, mask length and underlying iterator.
        Parameters:
        mask - a mask, or null, meaning an empty mask (everything is copied).
        maskLen - an explicit mask length.
        underlying - an underlying iterator.
    • Method Detail

      • nextLong

        public long nextLong()
        Description copied from interface: LazyLongIterator
        The next long returned by this iterator, or the special marker if this iterator is exhausted.
        Specified by:
        nextLong in interface LazyLongIterator
        Returns:
        next long returned by this iterator, or the special marker if this iterator is exhausted.
      • skip

        public long skip​(long n)
        Description copied from interface: LazyLongIterator
        Skips a given number of elements.
        Specified by:
        skip in interface LazyLongIterator
        Parameters:
        n - the number of elements to skip.
        Returns:
        the number of elements actually skipped (which might be less than n if this iterator is exhausted).