Check if iterator has next element. If not throw NoSuchElementException

@param iterator
@param message
@return the iterator itself
@throws java.util.NoSuchElementException if iterator.hasNext returns false
502389
public static <T> Iterator<T> checkHasNext(Iterator<T> iterator, String message) throws NoSuchElementException {
        if (!iterator.hasNext()) {
            throw new NoSuchElementException(message);
        }
        return iterator;
    }
1283638
public static boolean hasNull(Iterator<?> iter) {
		if (null == iter) {
			return true;
		}
		while (iter.hasNext()) {
			if (null == iter.next()) {
				return true;
			}
		}

		return false;
	}
285328
@Override
    public boolean hasNext() {
        if (throwable != null)
            throw throwable;

        try {
            if (hasDepleted.get())
                return false;

            if (nextElement != null && nextElement != terminator) {
                return true;
            } else if (nextElement == terminator)
                return false;


            nextElement = buffer.take();

            if (nextElement == terminator) {
                hasDepleted.set(true);
                return false;
            }

            return true;
        } catch (Exception e) {
            log.error("Premature end of loop!");
            throw new RuntimeException(e);
        }
    }
727191
public boolean next()
    {
        if (this.iter == null) {
            this.iter = new ArrayList<>(this.values).iterator();
        }
        final boolean ret = this.iter.hasNext();
        if (ret) {
            this.current = this.iter.next();
        }
        return ret;
    }
512678
public Iterator iterator() {
        return new Iterator() {
            public boolean hasNext() {
                return false;
            }

            public Object next() {
                return null;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
937366
public boolean nextInnerElement(ElementContext parent, String childName) throws XMLException, IOException {
		while (nextInnerElement(parent)) {
			if (event.text.equals(childName))
				return true;
		}
		return false;
	}
462919
@Override
	public Long next() {
		if (!hasNext()) {
			throw new NoSuchElementException(toString() + " ended");
		}

		current = next;
		next = next + increment;

		return current();
	}
120395
@Override
	public boolean hasNext()
	{
		if (this.items != null)
			return i != this.itemsSize;
		else if (this.itemsIterator != null)
			return this.itemsIterator.hasNext();
		else
			return this.itemsEnumerator.hasMoreElements();
	}
874273
public <E extends T> Iterator<E> filter (final Iterator<E> input)
    {
        return new Iterator<E>() {
            // from Iterator
            public boolean hasNext ()
            {
                return _found || findNext();
            }

            // from Iterator
            public E next ()
            {
                if (_found || findNext()) {
                    _found = false;
                    return _last;

                } else {
                    throw new NoSuchElementException();
                }
            }

            // from Iterator
            public void remove ()
            {
                if (_removeable) {
                    _removeable = false;
                    input.remove();

                } else {
                    throw new IllegalStateException();
                }
            }

            private boolean findNext ()
            {
                boolean result = false;
                while (input.hasNext()) {
                    E candidate = input.next();
                    if (isMatch(candidate)) {
                        _last = candidate;
                        result = true;
                        break;
                    }
                }

                _found = result;
                _removeable = result;
                return result;
            }

            private E _last;
            private boolean _found; // because _last == null is a valid element
            private boolean _removeable;
        };
    }
202560
public Iterator<T> iterator() {
        return new Iterator<T>() {
            private int currentPosition = start;
            private boolean hasNext = true;

            public boolean hasNext() {
                return hasNext;
            }

            @SuppressWarnings("unchecked")
            public T next() {
                if (end == -1)
                    hasNext = !sequence.getItem(currentPosition).getClass().equals(SequenceTerminal.class);
                else
                    hasNext = currentPosition < getEnd() - 1;
                return (T) sequence.getItem(currentPosition++);
            }

            public void remove() {
                throw new UnsupportedOperationException(
                    "The remove method is not supported.");
            }
        };
    }
829773
public T next() {
    if (nextToken == null) {
      nextToken = getNext();
    }
    T result = nextToken;
    nextToken = null;
    if (result == null) {
      throw new NoSuchElementException();
    }
    return result;
  }
137629
public static <T> ObjIterator<T> skipNull(final Iterator<T> iter) {
        if (iter == null) {
            return ObjIterator.empty();
        }

        return new ObjIterator<T>() {
            private final Iterator<T> iterator = iter;
            private T next;

            @Override
            public boolean hasNext() {
                if (next == null && iterator.hasNext()) {
                    next = iterator.next();

                    if (next == null) {
                        while (iterator.hasNext()) {
                            next = iterator.next();

                            if (next != null) {
                                break;
                            }
                        }
                    }
                }

                return next != null;
            }

            @Override
            public T next() {
                if (next == null && hasNext() == false) {
                    throw new NoSuchElementException();
                }

                final T result = next;
                next = null;
                return result;
            }
        };
    }
511717
public JsMessage next() throws SIResourceException, SISessionDroppedException 
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "next");
    
    JsMessage msg = null;
    Iterator<BrowseCursor> it = cursors.iterator();
    while(it.hasNext() && msg==null)
      msg = it.next().next();     
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "next");
    
    return msg;
  }
457588
public static <T> ObjIterator<T> limit(final Iterator<T> iter, final long count) {
        N.checkArgNotNegative(count, "count");

        if (iter == null || count == 0) {
            return ObjIterator.empty();
        }

        return new ObjIterator<T>() {
            private long cnt = count;

            @Override
            public boolean hasNext() {
                return cnt > 0 && iter.hasNext();
            }

            @Override
            public T next() {
                if (hasNext() == false) {
                    throw new NoSuchElementException();
                }

                cnt--;
                return iter.next();
            }
        };
    }
1282919
public static <M extends Message> IterableOfProtosSubject<?, M, Iterable<M>> assertThat(
      @NullableDecl Iterable<M> messages) {
    return assertAbout(protos()).that(messages);
  }
691638
public static <T> Iterator<T> reverseIterator(final List<T> list) {
		return new Iterator<T>() {

			private int next = list.size() - 1;

			@Override
			@Pure
			public boolean hasNext() {
				return this.next >= 0;
			}

			@Override
			public T next() {
				final int n = this.next;
				--this.next;
				try {
					return list.get(n);
				} catch (IndexOutOfBoundsException exception) {
					throw new NoSuchElementException();
				}
			}

		};
	}
1018783
public Object nextElement()
    {
        try
        {
            if (!hasCalledCheck)
            {    
                hasMoreElements();
            }    
            hasCalledCheck = false;
            if (hasNext)
            {
                Identity oid = getIdentityFromResultSet();
                Identity[] args = {oid};
                return this.constructor.newInstance(args);
            }
            else
                throw new NoSuchElementException();
        }
        catch (Exception ex)
        {
            LoggerFactory.getDefaultLogger().error(ex);
            throw new NoSuchElementException();
        }
    }