code: public static PrimitiveIterator.OfInt iterator(Spliterator.OfInt spliterator) {
          Objects.requireNonNull(spliterator);
          class Adapter implements PrimitiveIterator.OfInt, IntConsumer {
              boolean valueReady = false;
              int nextElement;
  
              @Override
              public void accept(int t) {
                  valueReady = true;
                  nextElement = t;
              }
  
              @Override
              public boolean hasNext() {
                  if (!valueReady)
                      spliterator.tryAdvance(this);
                  return valueReady;
              }
  
              @Override
              public int nextInt() {
                  if (!valueReady && !hasNext())
                      throw new NoSuchElementException();
                  else {
                      valueReady = false;
                      return nextElement;
                  }
              }
          }
  
          return new Adapter();
      }
docs: Creates an {@code PrimitiveIterator.OfInt} from a
  {@code Spliterator.OfInt}.
  
  <p>Traversal of elements should be accomplished through the iterator.
  The behaviour of traversal is undefined if the spliterator is operated
  after the iterator is returned.
  
  @param spliterator The spliterator
  @return An iterator
  @throws NullPointerException if the given spliterator is {@code null}